@aria-a11y/cli 0.1.1 → 0.1.2

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.
@@ -43,15 +43,33 @@ function toDiagnostics(messages) {
43
43
  formatTier: m.fix !== void 0
44
44
  }));
45
45
  }
46
+ var UNKNOWN_RULE_RE = /^Definition for rule '(.+)' was not found\.?$/;
47
+ function isForeignUnknownRule(m) {
48
+ return !m.fatal && UNKNOWN_RULE_RE.test(m.message) && m.ruleId !== null && !m.ruleId.startsWith("aria-a11y/");
49
+ }
50
+ function lintTextDetailed(code, filename) {
51
+ const messages = linter.verify(code, baseConfig, resolve(filename));
52
+ const foreign = messages.filter(isForeignUnknownRule).length;
53
+ return {
54
+ diagnostics: toDiagnostics(messages.filter((m) => !isForeignUnknownRule(m))),
55
+ foreignRuleReferences: foreign
56
+ };
57
+ }
46
58
  function lintText(code, filename) {
47
- return toDiagnostics(linter.verify(code, baseConfig, resolve(filename)));
59
+ return lintTextDetailed(code, filename).diagnostics;
48
60
  }
49
61
  function fixText(code, filename) {
50
62
  const result = linter.verifyAndFix(code, baseConfig, resolve(filename));
51
- return { output: result.output, remaining: toDiagnostics(result.messages) };
63
+ const foreign = result.messages.filter(isForeignUnknownRule).length;
64
+ return {
65
+ output: result.output,
66
+ remaining: toDiagnostics(result.messages.filter((m) => !isForeignUnknownRule(m))),
67
+ foreignRuleReferences: foreign
68
+ };
52
69
  }
53
70
 
54
71
  export {
72
+ lintTextDetailed,
55
73
  lintText,
56
74
  fixText
57
75
  };
package/dist/cli.js CHANGED
@@ -1,46 +1,101 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  fixText,
4
- lintText
5
- } from "./chunk-AX3Y6N3T.js";
4
+ lintTextDetailed
5
+ } from "./chunk-MDTKH5T7.js";
6
6
 
7
7
  // src/cli.ts
8
- import { readdirSync, readFileSync, statSync, writeFileSync } from "fs";
9
- import { join, relative } from "path";
8
+ import { readFileSync as readFileSync2, writeFileSync } from "fs";
9
+ import { relative as relative2 } from "path";
10
+
11
+ // src/walk.ts
12
+ import { existsSync, readdirSync, readFileSync, statSync } from "fs";
13
+ import { join, relative, sep } from "path";
14
+ import ignore from "ignore";
15
+ var DEFAULT_SKIP = /* @__PURE__ */ new Set([
16
+ "node_modules",
17
+ ".git",
18
+ ".next",
19
+ "out",
20
+ "build",
21
+ "dist",
22
+ "coverage",
23
+ ".turbo",
24
+ ".vercel"
25
+ ]);
10
26
  var SOURCE_EXT = /\.(?:js|jsx|ts|tsx|mjs|cjs|mts|cts)$/;
11
- var SKIP_DIR = /* @__PURE__ */ new Set(["node_modules", "dist", ".git", "coverage", ".turbo"]);
12
- var useColor = process.stdout.isTTY && process.env["NO_COLOR"] === void 0;
13
- var paint = (code, s) => useColor ? `\x1B[${code}m${s}\x1B[0m` : s;
14
- var red = (s) => paint("31", s);
15
- var yellow = (s) => paint("33", s);
16
- var dim = (s) => paint("2", s);
17
- var bold = (s) => paint("1", s);
27
+ function gitignoreFor(root) {
28
+ const file = join(root, ".gitignore");
29
+ if (!existsSync(file)) return null;
30
+ try {
31
+ return ignore().add(readFileSync(file, "utf8"));
32
+ } catch {
33
+ return null;
34
+ }
35
+ }
18
36
  function collectFiles(paths) {
19
- const out = [];
20
- const walk = (p) => {
37
+ const files = [];
38
+ const missing = [];
39
+ const walkDir = (dir, root, ig) => {
40
+ for (const entry of readdirSync(dir)) {
41
+ if (DEFAULT_SKIP.has(entry)) continue;
42
+ const full = join(dir, entry);
43
+ let st;
44
+ try {
45
+ st = statSync(full);
46
+ } catch {
47
+ continue;
48
+ }
49
+ if (ig !== null) {
50
+ const rel = relative(root, full).split(sep).join("/");
51
+ if (ig.ignores(rel) || st.isDirectory() && ig.ignores(`${rel}/`)) continue;
52
+ }
53
+ if (st.isDirectory()) walkDir(full, root, ig);
54
+ else if (SOURCE_EXT.test(entry)) files.push(full);
55
+ }
56
+ };
57
+ for (const p of paths) {
21
58
  let st;
22
59
  try {
23
60
  st = statSync(p);
24
61
  } catch {
25
- process.stderr.write(red(`aria: no such path: ${p}
26
- `));
27
- return;
62
+ missing.push(p);
63
+ continue;
28
64
  }
29
65
  if (st.isDirectory()) {
30
- for (const entry of readdirSync(p)) {
31
- if (SKIP_DIR.has(entry)) continue;
32
- walk(join(p, entry));
33
- }
34
- } else if (SOURCE_EXT.test(p)) {
35
- out.push(p);
66
+ walkDir(p, p, gitignoreFor(p));
67
+ } else {
68
+ files.push(p);
36
69
  }
37
- };
38
- for (const p of paths) walk(p);
39
- return out;
70
+ }
71
+ return { files, missing };
72
+ }
73
+
74
+ // src/cli.ts
75
+ var useColor = process.stdout.isTTY && process.env["NO_COLOR"] === void 0;
76
+ var paint = (code, s) => useColor ? `\x1B[${code}m${s}\x1B[0m` : s;
77
+ var red = (s) => paint("31", s);
78
+ var yellow = (s) => paint("33", s);
79
+ var dim = (s) => paint("2", s);
80
+ var bold = (s) => paint("1", s);
81
+ function gather(paths) {
82
+ const { files, missing } = collectFiles(paths);
83
+ for (const p of missing) process.stderr.write(red(`aria: no such path: ${p}
84
+ `));
85
+ return files;
86
+ }
87
+ function reportForeign(count) {
88
+ if (count === 0) return;
89
+ process.stdout.write(
90
+ dim(
91
+ `note: ${count} eslint-disable comment(s) reference rules unknown to this standalone runner \u2014 ignored (they belong to your project's own ESLint setup, not Aria).
92
+ `
93
+ )
94
+ );
40
95
  }
41
96
  function printDiagnostics(file, diags) {
42
97
  if (diags.length === 0) return;
43
- process.stdout.write(bold(relative(process.cwd(), file)) + "\n");
98
+ process.stdout.write(bold(relative2(process.cwd(), file)) + "\n");
44
99
  for (const d of diags) {
45
100
  const sev = d.severity === "error" ? red("error") : yellow("warn ");
46
101
  const loc = dim(`${d.line}:${d.column}`);
@@ -62,35 +117,41 @@ function summarize(files, diags) {
62
117
  );
63
118
  }
64
119
  function runCheck(paths) {
65
- const files = collectFiles(paths);
120
+ const files = gather(paths);
66
121
  const all = [];
122
+ let foreign = 0;
67
123
  for (const file of files) {
68
- const diags = lintText(readFileSync(file, "utf8"), file);
69
- printDiagnostics(file, diags);
70
- all.push(...diags);
124
+ const detail = lintTextDetailed(readFileSync2(file, "utf8"), file);
125
+ printDiagnostics(file, detail.diagnostics);
126
+ all.push(...detail.diagnostics);
127
+ foreign += detail.foreignRuleReferences;
71
128
  }
129
+ reportForeign(foreign);
72
130
  summarize(files.length, all);
73
131
  return all.some((d) => d.formatTier) ? 1 : 0;
74
132
  }
75
133
  function runFix(paths) {
76
- const files = collectFiles(paths);
134
+ const files = gather(paths);
77
135
  let fixedCount = 0;
136
+ let foreign = 0;
78
137
  const remaining = [];
79
138
  for (const file of files) {
80
- const before = readFileSync(file, "utf8");
81
- const { output, remaining: left } = fixText(before, file);
139
+ const before = readFileSync2(file, "utf8");
140
+ const { output, remaining: left, foreignRuleReferences } = fixText(before, file);
82
141
  if (output !== before) {
83
142
  writeFileSync(file, output);
84
143
  fixedCount += 1;
85
- process.stdout.write(dim(`fixed ${relative(process.cwd(), file)}
144
+ process.stdout.write(dim(`fixed ${relative2(process.cwd(), file)}
86
145
  `));
87
146
  }
88
147
  printDiagnostics(file, left);
89
148
  remaining.push(...left);
149
+ foreign += foreignRuleReferences;
90
150
  }
91
151
  process.stdout.write(dim(`
92
152
  ${fixedCount} file(s) fixed.
93
153
  `));
154
+ reportForeign(foreign);
94
155
  summarize(files.length, remaining);
95
156
  return remaining.some((d) => d.formatTier) ? 1 : 0;
96
157
  }
package/dist/runner.d.ts CHANGED
@@ -17,7 +17,13 @@ interface AriaDiagnostic {
17
17
  */
18
18
  formatTier: boolean;
19
19
  }
20
+ interface LintDetail {
21
+ diagnostics: AriaDiagnostic[];
22
+ /** Count of suppressed foreign eslint-disable rule references (summary, not findings). */
23
+ foreignRuleReferences: number;
24
+ }
20
25
  /** Lint one source string. `filename` drives TS/TSX detection and config discovery. */
26
+ declare function lintTextDetailed(code: string, filename: string): LintDetail;
21
27
  declare function lintText(code: string, filename: string): AriaDiagnostic[];
22
28
  /**
23
29
  * Fix one source string. Applies ONLY ESLint-native `fix` edits — which, by the
@@ -28,6 +34,7 @@ declare function lintText(code: string, filename: string): AriaDiagnostic[];
28
34
  declare function fixText(code: string, filename: string): {
29
35
  output: string;
30
36
  remaining: AriaDiagnostic[];
37
+ foreignRuleReferences: number;
31
38
  };
32
39
 
33
- export { type AriaDiagnostic, fixText, lintText };
40
+ export { type AriaDiagnostic, type LintDetail, fixText, lintText, lintTextDetailed };
package/dist/runner.js CHANGED
@@ -1,9 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  fixText,
4
- lintText
5
- } from "./chunk-AX3Y6N3T.js";
4
+ lintText,
5
+ lintTextDetailed
6
+ } from "./chunk-MDTKH5T7.js";
6
7
  export {
7
8
  fixText,
8
- lintText
9
+ lintText,
10
+ lintTextDetailed
9
11
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aria-a11y/cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Zero-config standalone CLI for Aria's accessibility rules — aria check / aria fix, no ESLint config required.",
5
5
  "keywords": [
6
6
  "accessibility",
@@ -43,6 +43,7 @@
43
43
  "@babel/preset-react": "^7.27.0",
44
44
  "@babel/preset-typescript": "^7.27.0",
45
45
  "eslint": "^9.13.0",
46
+ "ignore": "^7.0.6",
46
47
  "eslint-plugin-aria-a11y": "^0.1.1"
47
48
  },
48
49
  "devDependencies": {