tailwind-a11y 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -25,6 +25,8 @@ npm install --save-dev tailwind-a11y
25
25
  npx tailwind-a11y # scans **/*.{jsx,tsx}
26
26
  npx tailwind-a11y "src/**/*.tsx" # custom glob
27
27
  npx tailwind-a11y --verbose # also reports what couldn't be checked, and why
28
+ npx tailwind-a11y --version # print the installed version
29
+ npx tailwind-a11y --help # usage and all options
28
30
  ```
29
31
 
30
32
  ```
package/dist/cli.js CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { readFileSync } from "node:fs";
3
3
  import { relative, sep } from "node:path";
4
+ import { createRequire } from "node:module";
4
5
  import fg from "fast-glob";
5
6
  import { extractChecks, extractContrastSkips } from "./parser/extractClasses.js";
6
7
  import { checkContrast, checkContrastValueSkips } from "./rules/checkContrast.js";
@@ -8,6 +9,10 @@ import { extractTouchTargetChecks, extractTouchTargetSkips } from "./parser/extr
8
9
  import { checkTouchTargets } from "./rules/checkTouchTarget.js";
9
10
  import { extractFocusIndicatorChecks } from "./parser/extractFocusIndicators.js";
10
11
  import { checkFocusIndicators } from "./rules/checkFocusIndicator.js";
12
+ import { parseArgs, getHelpText } from "./cliArgs.js";
13
+ // ../package.json resolves correctly from both src/ (dev) and dist/ (published).
14
+ const require = createRequire(import.meta.url);
15
+ const { version: packageVersion } = require("../package.json");
11
16
  function formatViolation(v) {
12
17
  switch (v.type) {
13
18
  case "contrast": {
@@ -34,9 +39,15 @@ function groupByFile(items) {
34
39
  return byFile;
35
40
  }
36
41
  async function main() {
37
- const args = process.argv.slice(2);
38
- const verbose = args.includes("--verbose") || args.includes("-v");
39
- const patterns = args.filter((a) => a !== "--verbose" && a !== "-v");
42
+ const { help, version, verbose, patterns } = parseArgs(process.argv.slice(2));
43
+ if (help) {
44
+ console.log(getHelpText());
45
+ return;
46
+ }
47
+ if (version) {
48
+ console.log(packageVersion);
49
+ return;
50
+ }
40
51
  const globPatterns = patterns.length > 0 ? patterns : ["**/*.{jsx,tsx}"];
41
52
  const files = await fg(globPatterns, {
42
53
  cwd: process.cwd(),
@@ -0,0 +1,8 @@
1
+ export interface ParsedArgs {
2
+ help: boolean;
3
+ version: boolean;
4
+ verbose: boolean;
5
+ patterns: string[];
6
+ }
7
+ export declare function getHelpText(): string;
8
+ export declare function parseArgs(argv: string[]): ParsedArgs;
@@ -0,0 +1,31 @@
1
+ // Split out from cli.ts so it's importable in tests without triggering
2
+ // cli.ts's top-level main() call (which does real file I/O on import).
3
+ const HELP_TEXT = `Usage: tailwind-a11y [options] [<glob>...]
4
+
5
+ Static analysis for Tailwind CSS accessibility violations -- color contrast,
6
+ touch target size, and focus indicator removal.
7
+
8
+ Options:
9
+ -v, --verbose Also report what couldn't be checked, and why
10
+ -V, --version Print the version number
11
+ -h, --help Print this help message
12
+
13
+ Examples:
14
+ tailwind-a11y Scan **/*.{jsx,tsx} from the current directory
15
+ tailwind-a11y "src/**/*.tsx" Scan a custom glob pattern
16
+ tailwind-a11y --verbose Also report skipped/unresolvable cases
17
+ `;
18
+ export function getHelpText() {
19
+ return HELP_TEXT;
20
+ }
21
+ // -v/--verbose already existed before --version was added; -V (uppercase)
22
+ // avoids colliding with it, matching a common CLI convention.
23
+ const FLAGS = new Set(["--verbose", "-v", "--version", "-V", "--help", "-h"]);
24
+ export function parseArgs(argv) {
25
+ return {
26
+ help: argv.includes("--help") || argv.includes("-h"),
27
+ version: argv.includes("--version") || argv.includes("-V"),
28
+ verbose: argv.includes("--verbose") || argv.includes("-v"),
29
+ patterns: argv.filter((a) => !FLAGS.has(a)),
30
+ };
31
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tailwind-a11y",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Static analysis CLI that catches WCAG accessibility violations — color contrast, touch target size, and focus indicator removal — in Tailwind CSS class combinations before they ship.",
5
5
  "type": "module",
6
6
  "bin": {