@kutur-kit/oxc 0.1.0-alpha.2 → 0.1.0-alpha.3

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.
Files changed (43) hide show
  1. package/README.md +32 -1
  2. package/dist/anti-slop.d.ts.map +1 -1
  3. package/dist/anti-slop.js +3 -0
  4. package/dist/anti-slop.js.map +1 -1
  5. package/dist/base.d.ts.map +1 -1
  6. package/dist/base.js +7 -1
  7. package/dist/base.js.map +1 -1
  8. package/dist/effect.d.ts.map +1 -1
  9. package/dist/effect.js +19 -0
  10. package/dist/effect.js.map +1 -1
  11. package/dist/plugin.d.ts.map +1 -1
  12. package/dist/plugin.js +7 -1
  13. package/dist/plugin.js.map +1 -1
  14. package/dist/prose/cli.d.ts +3 -0
  15. package/dist/prose/cli.d.ts.map +1 -0
  16. package/dist/prose/cli.js +63 -0
  17. package/dist/prose/cli.js.map +1 -0
  18. package/dist/prose/problems.d.ts +18 -0
  19. package/dist/prose/problems.d.ts.map +1 -0
  20. package/dist/prose/problems.js +49 -0
  21. package/dist/prose/problems.js.map +1 -0
  22. package/dist/rules/comment-prose.d.ts +2 -0
  23. package/dist/rules/comment-prose.d.ts.map +1 -0
  24. package/dist/rules/comment-prose.js +49 -0
  25. package/dist/rules/comment-prose.js.map +1 -0
  26. package/dist/rules/directives.d.ts +4 -0
  27. package/dist/rules/directives.d.ts.map +1 -0
  28. package/dist/rules/directives.js +12 -0
  29. package/dist/rules/directives.js.map +1 -0
  30. package/dist/rules/no-suppression-directives.d.ts +2 -0
  31. package/dist/rules/no-suppression-directives.d.ts.map +1 -0
  32. package/dist/rules/no-suppression-directives.js +93 -0
  33. package/dist/rules/no-suppression-directives.js.map +1 -0
  34. package/package.json +5 -2
  35. package/src/anti-slop.ts +3 -0
  36. package/src/base.ts +7 -1
  37. package/src/effect.ts +19 -0
  38. package/src/plugin.ts +7 -1
  39. package/src/prose/cli.ts +86 -0
  40. package/src/prose/problems.ts +68 -0
  41. package/src/rules/comment-prose.ts +58 -0
  42. package/src/rules/directives.ts +16 -0
  43. package/src/rules/no-suppression-directives.ts +140 -0
package/README.md CHANGED
@@ -35,7 +35,38 @@ Install the required tools in `devDependencies` and include linted files in your
35
35
 
36
36
  `effect-tsgo` runs Oxlint with the Effect rules without patching `node_modules`. Check [supported tool versions](https://github.com/Effect-TS/tsgo#supported-package-versions) when upgrading.
37
37
 
38
- `/anti-slop` is optional and includes the generic and Effect rules from [anti-slop](https://github.com/dmmulroy/anti-slop).
38
+ `/effect` also warns where code uses a runtime global that has an Effect service, such as `console`, `Date` or `process.env`. Its rules warn, so set `maxWarnings: 0` to fail on them. Turn a rule off with `overrides` only for files where the global is the point, such as a script that prints its result.
39
+
40
+ `/anti-slop` is optional and includes the generic and Effect rules from [anti-slop](https://github.com/dmmulroy/anti-slop), and `kit/comment-prose` (see [Prose](#prose)).
41
+
42
+ ### Suppression comments
43
+
44
+ `kit/no-suppression-directives` reports comments that suppress Oxlint rules or Effect diagnostics, reading `oxlint-disable`, `eslint-disable` and `@effect-diagnostics` as Oxlint and tsgo read them. With `{ allowWithReason: true }`, as `/base` sets it, a comment passes when it names each rule and gives a reason after `--`:
45
+
46
+ ```ts
47
+ // oxlint-disable-next-line no-debugger -- the page demonstrates the debugger
48
+ // @effect-diagnostics-next-line floatingEffect:off -- the test asserts the type only
49
+ ```
50
+
51
+ Blanket comments, `*:off`, `skip-file` and comments that disable `unicorn/no-abusive-eslint-disable` or `typescript/ban-ts-comment` still fail. Without the option, every suppression fails. `@ts-*` comments are left to `typescript/ban-ts-comment`.
52
+
53
+ A comment that disables `kit/no-suppression-directives` itself turns the rule off for its file, so the comment suppresses nothing and `reportUnusedDisableDirectives` fails on it. `/base` sets that option to `"error"`. Your own `options` merge with the preset's, so it stays on unless you override it.
54
+
55
+ tsgo also reads `@effect-diagnostics` in string literals, which the rule does not check.
56
+
57
+ ## Prose
58
+
59
+ `kit/comment-prose`, which `/anti-slop` turns on, checks comments. The `kit-prose` command checks Markdown. Both report vague words such as `lands`, `gated` or `leverage`, and dashes used as punctuation: an em dash anywhere, or an en dash, `-` or `--` with a space on each side. Each message names the fix. Put a literal use, such as an identifier, in a code span.
60
+
61
+ Code spans, fenced code, URLs, link targets, autolinks and HTML comments are not checked. In comments, JSDoc margins and a directive's keyword and rules, up to the `--` before its reason, are skipped too; the reason is checked. String literals are never checked, so product copy can use a spaced en dash.
62
+
63
+ `kit-prose` expands quoted glob patterns and skips symlinks and `node_modules`:
64
+
65
+ ```sh
66
+ kit-prose --budget AGENTS.md=7400 '*.md' 'packages/*/README.md'
67
+ ```
68
+
69
+ It prints each problem as `<file>:<line>` and exits with 1 on any failure. `--budget <file>=<characters>` fails when the file has more characters than the limit, counted as Unicode code points. A budget whose file no pattern matches fails, and so does a pattern that matches no file, so a typo cannot switch a check off.
39
70
 
40
71
  ## Formatting
41
72
 
@@ -1 +1 @@
1
- {"version":3,"file":"anti-slop.d.ts","sources":["../src/anti-slop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAM3C,QAAA,MAAM,QAAQ,EAAE,YAuCf,CAAC;AAEF,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"anti-slop.d.ts","sources":["../src/anti-slop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAM3C,QAAA,MAAM,QAAQ,EAAE,YA0Cf,CAAC;AAEF,eAAe,QAAQ,CAAC"}
package/dist/anti-slop.js CHANGED
@@ -2,6 +2,8 @@ import { fileURLToPath } from "node:url";
2
2
  const extension = import.meta.url.endsWith(".ts") ? "ts" : "js";
3
3
  const antiSlop = {
4
4
  jsPlugins: [
5
+ // `/base` registers the same plugin with the same specifier, so Oxlint loads it once.
6
+ { name: "kit", specifier: fileURLToPath(new URL(`./plugin.${extension}`, import.meta.url)) },
5
7
  {
6
8
  name: "anti-slop",
7
9
  specifier: fileURLToPath(new URL(`./vendor/anti-slop/index.${extension}`, import.meta.url)),
@@ -12,6 +14,7 @@ const antiSlop = {
12
14
  },
13
15
  ],
14
16
  rules: {
17
+ "kit/comment-prose": "error",
15
18
  "oxc/no-accumulating-spread": "error",
16
19
  "anti-slop/no-array-filter-map": "error",
17
20
  "anti-slop/no-reduce-accumulator-copy": "error",
@@ -1 +1 @@
1
- {"version":3,"file":"anti-slop.js","sources":["../src/anti-slop.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,SAAS,GAAG,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AAEhE,MAAM,QAAQ,GAAiB;IAC7B,SAAS,EAAE;QACT;YACE,IAAI,EAAE,WAAW;YACjB,SAAS,EAAE,aAAa,CAAC,IAAI,GAAG,CAAC,4BAA4B,SAAS,EAAE,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;SAC5F;QACD;YACE,IAAI,EAAE,kBAAkB;YACxB,SAAS,EAAE,aAAa,CACtB,IAAI,GAAG,CAAC,mCAAmC,SAAS,EAAE,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CACzE;SACF;KACF;IACD,KAAK,EAAE;QACL,4BAA4B,EAAE,OAAO;QACrC,+BAA+B,EAAE,OAAO;QACxC,sCAAsC,EAAE,OAAO;QAC/C,sCAAsC,EAAE,OAAO;QAC/C,8CAA8C,EAAE,OAAO;QACvD,mCAAmC,EAAE,OAAO;QAC5C,6BAA6B,EAAE,OAAO;QACtC,gCAAgC,EAAE,OAAO;QACzC,4BAA4B,EAAE,OAAO;QACrC,0BAA0B,EAAE,OAAO;QACnC,6BAA6B,EAAE,OAAO;QACtC,qCAAqC,EAAE,OAAO;QAC9C,oCAAoC,EAAE,OAAO;QAC7C,iCAAiC,EAAE,OAAO;QAC1C,8BAA8B,EAAE,OAAO;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OAAO;QAC5C,6BAA6B,EAAE,OAAO;QACtC,gCAAgC,EAAE,OAAO;QACzC,4BAA4B,EAAE,OAAO;QACrC,0BAA0B,EAAE,OAAO;QACnC,6BAA6B,EAAE,OAAO;QACtC,qCAAqC,EAAE,OAAO;QAC9C,oCAAoC,EAAE,OAAO;QAC7C,iCAAiC,EAAE,OAAO;QAC1C,8BAA8B,EAAE,OAAO;QACvC,mCAAmC,EAAE,OAAO;QAC5C,gCAAgC,EAAE,OAAO;QACzC,oCAAoC,EAAE,OAAO;QAC7C,qDAAqD,EAAE,OAAO;QAC9D,6CAA6C,EAAE,OAAO;QACtD,2CAA2C,EAAE,OAAO;QACpD,gDAAgD,EAAE,OAAO;QACzD,iDAAiD,EAAE,OAAO;QAC1D,sCAAsC,EAAE,OAAO;KAChD;CACF,CAAC;AAEF,eAAe,QAAQ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"base.d.ts","sources":["../src/base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAM3C,QAAA,MAAM,IAAI,EAAE,YAwCX,CAAC;AAEF,eAAe,IAAI,CAAC"}
1
+ {"version":3,"file":"base.d.ts","sources":["../src/base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAM3C,QAAA,MAAM,IAAI,EAAE,YA8CX,CAAC;AAEF,eAAe,IAAI,CAAC"}
package/dist/base.js CHANGED
@@ -11,7 +11,13 @@ const base = {
11
11
  plugins: ["typescript", "oxc", "unicorn", "import"],
12
12
  categories: { correctness: "error" },
13
13
  rules: {
14
+ "kit/no-suppression-directives": ["error", { allowWithReason: true }],
14
15
  "kit/no-yield-in-if": "error",
16
+ "unicorn/no-abusive-eslint-disable": "error",
17
+ "typescript/ban-ts-comment": [
18
+ "error",
19
+ { "ts-expect-error": "allow-with-description", "ts-ignore": true, "ts-nocheck": true },
20
+ ],
15
21
  "sonarjs/cognitive-complexity": ["error", 15],
16
22
  "max-depth": ["error", 3],
17
23
  "typescript/no-explicit-any": "error",
@@ -39,7 +45,7 @@ const base = {
39
45
  "no-debugger": "error",
40
46
  "prefer-const": "error",
41
47
  },
42
- options: { typeAware: true },
48
+ options: { typeAware: true, reportUnusedDisableDirectives: "error" },
43
49
  };
44
50
  export default base;
45
51
  //# sourceMappingURL=base.js.map
package/dist/base.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","sources":["../src/base.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,SAAS,GAAG,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AAEhE,MAAM,IAAI,GAAiB;IACzB,SAAS,EAAE;QACT;YACE,IAAI,EAAE,KAAK;YACX,SAAS,EAAE,aAAa,CAAC,IAAI,GAAG,CAAC,YAAY,SAAS,EAAE,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;SAC5E;QACD,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAC,EAAE;KAC5F;IACD,OAAO,EAAE,CAAC,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,CAAC;IACnD,UAAU,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE;IACpC,KAAK,EAAE;QACL,oBAAoB,EAAE,OAAO;QAC7B,8BAA8B,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC;QAC7C,WAAW,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;QACzB,4BAA4B,EAAE,OAAO;QACrC,wCAAwC,EAAE,OAAO;QACjD,0BAA0B,EAAE,OAAO;QACnC,iCAAiC,EAAE,OAAO;QAC1C,+BAA+B,EAAE,OAAO;QACxC,2BAA2B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AAO;QACjB,8BAA8B,EAAE,OAAO;QACvC,uBAAuB,EAAE,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,CAAC;QACpF,aAAa,EAAE,OAAO;QACtB,cAAc,EAAE,OAAO;KACxB;IACD,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,6BAA6B,EAAE,OAAO,EAAE;CACrE,CAAC;AAEF,eAAe,IAAI,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"effect.d.ts","sources":["../src/effect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAM3C,QAAA,MAAM,MAAM,EAAE,YAGb,CAAC;AAEF,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"effect.d.ts","sources":["../src/effect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAM3C,QAAA,MAAM,MAAM,EAAE,YAsBb,CAAC;AAEF,eAAe,MAAM,CAAC"}
package/dist/effect.js CHANGED
@@ -2,6 +2,25 @@ import { recommended } from "@effect/tsgo/oxlint-presets";
2
2
  import base from "./base.js";
3
3
  const effect = {
4
4
  extends: [base, recommended],
5
+ rules: {
6
+ // Globals that bypass Effect's services, so layers and tests cannot replace them.
7
+ "effecttsgo/crypto-random-uuid": "warn",
8
+ "effecttsgo/crypto-random-uuid-in-effect": "warn",
9
+ "effecttsgo/global-console": "warn",
10
+ "effecttsgo/global-console-in-effect": "warn",
11
+ "effecttsgo/global-date": "warn",
12
+ "effecttsgo/global-date-in-effect": "warn",
13
+ "effecttsgo/global-fetch": "warn",
14
+ "effecttsgo/global-fetch-in-effect": "warn",
15
+ "effecttsgo/global-random": "warn",
16
+ "effecttsgo/global-random-in-effect": "warn",
17
+ "effecttsgo/global-timers": "warn",
18
+ "effecttsgo/global-timers-in-effect": "warn",
19
+ "effecttsgo/process-env": "warn",
20
+ "effecttsgo/process-env-in-effect": "warn",
21
+ // Effect's documented form for a service is a class that extends `Context.Service`.
22
+ "effecttsgo/service-not-as-class": "warn",
23
+ },
5
24
  options: { typeAware: true },
6
25
  };
7
26
  export default effect;
@@ -1 +1 @@
1
- {"version":3,"file":"effect.js","sources":["../src/effect.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE1D,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,MAAM,GAAiB;IAC3B,OAAO,EAAE,CAAC,IAAI,EAAE,WAAW,CAAC;IAC5B,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE;CAC7B,CAAC;AAEF,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"effect.js","sources":["../src/effect.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE1D,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,MAAM,GAAiB;IAC3B,OAAO,EAAE,CAAC,IAAI,EAAE,WAAW,CAAC;IAC5B,KAAK,EAAE;QACL,kFAAkF;QAClF,+BAA+B,EAAE,MAAM;QACvC,yCAAyC,EAAE,MAAM;QACjD,2BAA2B,EAAE,MAAM;QACnC,qCAAqC,EAAE,MAAM;QAC7C,wBAAwB,EAAE,MAAM;QAChC,kCAAkC,EAAE,MAAM;QAC1C,yBAAyB,EAAE,MAAM;QACjC,mCAAmC,EAAE,MAAM;QAC3C,0BAA0B,EAAE,MAAM;QAClC,oCAAoC,EAAE,MAAM;QAC5C,0BAA0B,EAAE,MAAM;QAClC,oCAAoC,EAAE,MAAM;QAC5C,wBAAwB,EAAE,MAAM;QAChC,kCAAkC,EAAE,MAAM;QAC1C,oFAAoF;QACpF,iCAAiC,EAAE,MAAM;KAC1C;IACD,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE;CAC7B,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sources":["../src/plugin.ts"],"names":[],"mappings":";AAIA,wBAGG"}
1
+ {"version":3,"file":"plugin.d.ts","sources":["../src/plugin.ts"],"names":[],"mappings":";AAMA,wBAOG"}
package/dist/plugin.js CHANGED
@@ -1,7 +1,13 @@
1
1
  import { definePlugin } from "@oxlint/plugins";
2
+ import { commentProse } from "./rules/comment-prose.js";
3
+ import { noSuppressionDirectives } from "./rules/no-suppression-directives.js";
2
4
  import { noYieldInIf } from "./rules/no-yield-in-if.js";
3
5
  export default definePlugin({
4
6
  meta: { name: "@kutur-kit/oxc" },
5
- rules: { "no-yield-in-if": noYieldInIf },
7
+ rules: {
8
+ "comment-prose": commentProse,
9
+ "no-suppression-directives": noSuppressionDirectives,
10
+ "no-yield-in-if": noYieldInIf,
11
+ },
6
12
  });
7
13
  //# sourceMappingURL=plugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,eAAe,YAAY,CAAC;IAC1B,IAAI,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE;IAChC,KAAK,EAAE,EAAE,gBAAgB,EAAE,WAAW,EAAE;CACzC,CAAC,CAAC"}
1
+ {"version":3,"file":"plugin.js","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,eAAe,YAAY,CAAC;IAC1B,IAAI,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE;IAChC,KAAK,EAAE;QACL,eAAe,EAAE,YAAY;QAC7B,2BAA2B,EAAE,uBAAuB;QACpD,gBAAgB,EAAE,WAAW;KAC9B;CACF,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sources":["../../src/prose/cli.ts"],"names":[],"mappings":""}
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env node
2
+ import { globSync, readFileSync } from "node:fs";
3
+ import { join, resolve } from "node:path";
4
+ import { parseArgs } from "node:util";
5
+ import { proseProblems } from "./problems.js";
6
+ const usage = "Usage: kit-prose [--budget <file>=<characters>]... <glob>...";
7
+ const { values, positionals } = parseArgs({
8
+ allowPositionals: true,
9
+ options: { budget: { type: "string", multiple: true, default: [] } },
10
+ });
11
+ if (positionals.length === 0)
12
+ throw new Error(`No glob given. ${usage}`);
13
+ // Keyed by absolute path, so `AGENTS.md` and `./AGENTS.md` name the same file.
14
+ const budgets = new Map(values.budget.map((entry) => {
15
+ const { file, limit } = /^(?<file>.+)=(?<limit>\d+)$/.exec(entry)?.groups ?? {};
16
+ if (file === undefined || limit === undefined) {
17
+ throw new Error(`--budget ${entry} is not <file>=<characters>. ${usage}`);
18
+ }
19
+ return [resolve(file), { file, limit: Number(limit) }];
20
+ }));
21
+ const failures = [];
22
+ const files = new Set();
23
+ for (const pattern of positionals) {
24
+ const matched = [];
25
+ // A symlink such as `CLAUDE.md` is not a file entry, so its target is not reported twice.
26
+ for (const entry of globSync(pattern, { exclude: ["**/node_modules"], withFileTypes: true })) {
27
+ if (entry.isFile())
28
+ matched.push(join(entry.parentPath, entry.name));
29
+ }
30
+ // Counted after filtering, so a pattern that matches only directories or symlinks fails too.
31
+ if (matched.length === 0) {
32
+ failures.push(`${pattern}: matches no file. The pattern checks nothing. Fix: correct the pattern or remove it.`);
33
+ }
34
+ for (const file of matched)
35
+ files.add(file);
36
+ }
37
+ const checked = new Set(Array.from(files, (file) => resolve(file)));
38
+ for (const [path, { file }] of budgets) {
39
+ if (!checked.has(path)) {
40
+ failures.push(`${file}: has a budget, but no pattern matches it. The budget checks nothing. Fix: correct the path or add a pattern that matches it.`);
41
+ }
42
+ }
43
+ for (const file of Array.from(files).sort()) {
44
+ const markdown = readFileSync(file, "utf8");
45
+ for (const { index, text, message } of proseProblems(markdown)) {
46
+ failures.push(`${file}:${markdown.slice(0, index).split("\n").length}: "${text}" ${message}`);
47
+ }
48
+ const budget = budgets.get(resolve(file));
49
+ // Code points, so a character outside the BMP counts once.
50
+ const characters = Array.from(markdown).length;
51
+ if (budget !== undefined && characters > budget.limit) {
52
+ failures.push(`${file}: ${characters} characters, over its budget of ${budget.limit}. Raising the budget needs the user. Fix: shorten it or move a rule into a check.`);
53
+ }
54
+ }
55
+ if (failures.length > 0) {
56
+ console.error(failures.join("\n"));
57
+ // Unlike `process.exit`, `exitCode` lets stderr finish writing to a pipe.
58
+ process.exitCode = 1;
59
+ }
60
+ else {
61
+ console.log(`Checked prose in ${files.size} Markdown ${files.size === 1 ? "file" : "files"}.`);
62
+ }
63
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sources":["../../src/prose/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,KAAK,GAAG,8DAA8D,CAAC;AAE7E,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,SAAS,CAAC;IACxC,gBAAgB,EAAE,IAAI;IACtB,OAAO,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAA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AC;IAE/C,IAAI,MAAM,KAAK,SAAS,IAAI,UAAU,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC;QACtD,QAAQ,CAAC,IAAI,CACX,GAAG,IAAI,KAAK,UAAU,mCAAmC,MAAM,CAAC,KAAK,mFAAmF,CACzJ,CAAC;IACJ,CAAC;AACH,CAAC;AAED,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;IACxB,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACnC,0EAA0E;IAC1E,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC;KAAM,CAAC;IACN,OAAO,CAAC,GAAG,CAAC,oBAAoB,KAAK,CAAC,IAAI,aAAa,KAAK,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC;AACjG,CAAC"}
@@ -0,0 +1,18 @@
1
+ /** A vague word or a dash used as punctuation, at a UTF-16 offset into the checked text. */
2
+ export type ProseProblem = {
3
+ readonly index: number;
4
+ readonly text: string;
5
+ readonly message: string;
6
+ };
7
+ /**
8
+ * Replaces every character but line breaks with a space, so offsets and line numbers still point
9
+ * into the source. Without the `u` flag the pattern matches UTF-16 units, so a character outside
10
+ * the BMP becomes two spaces.
11
+ */
12
+ export declare const blank: (span: string) => string;
13
+ /**
14
+ * Finds vague words and dashes used as punctuation in Markdown or comment text. Fenced code, HTML
15
+ * comments, code spans, link targets, autolinks and URLs are not prose.
16
+ */
17
+ export declare const proseProblems: (text: string) => ReadonlyArray<ProseProblem>;
18
+ //# sourceMappingURL=problems.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"problems.d.ts","sources":["../../src/prose/problems.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,CAAC;AA4BF;;;;GAIG;AACH,eAAO,MAAM,KAAK,SAAU,MAAM,WAAmC,CAAC;AAatE;;;GAGG;AACH,eAAO,MAAM,aAAa,SAAU,MAAM,KAAG,aAAa,CAAC,YAAY,CAYtE,CAAC"}
@@ -0,0 +1,49 @@
1
+ const vague = (pattern, fix) => ({
2
+ pattern,
3
+ message: `is vague. A plain word says what happens. Fix: ${fix}, or put a literal use in a code span.`,
4
+ });
5
+ const rules = [
6
+ vague(/\b(?:stamp|stamps|stamped|stamping)\b/giu, "say who records or approves it"),
7
+ vague(/\b(?:land|lands|landed)\b/giu, "say `merged`, `deployed` or `released`"),
8
+ vague(/\b(?:gate|gates|gated|gating)\b/giu, "say what checks, blocks or requires it"),
9
+ vague(/\b(?:unlock|unlocks|unlocked|unlocking)\b/giu, "say what it allows"),
10
+ vague(/\b(?:supercharge|supercharges|supercharged)\b/giu, "say what changes"),
11
+ vague(/\b(?:seamless|seamlessly)\b/giu, "delete it or say what keeps working"),
12
+ vague(/\bbattle-tested\b/giu, "say where it runs or what tests it"),
13
+ vague(/\b(?:leverage|leverages|leveraged|leveraging)\b/giu, "say `use`"),
14
+ vague(/\b(?:empower|empowers|empowered|empowering)\b/giu, "say `lets` or `supports`"),
15
+ {
16
+ // An em dash (U+2014) anywhere. An en dash (U+2013), `-` or `--` only between spaces, so
17
+ // ranges such as `2–4`, hyphenated words, flags and list items pass.
18
+ pattern: /\u2014|(?<=\S )(?:\u2013|--?)(?= \S)/gu,
19
+ message: "is a dash used as punctuation. A period, comma, colon or parentheses say how the parts relate. Fix: use one of them, or put a literal use in a code span.",
20
+ },
21
+ ];
22
+ /**
23
+ * Replaces every character but line breaks with a space, so offsets and line numbers still point
24
+ * into the source. Without the `u` flag the pattern matches UTF-16 units, so a character outside
25
+ * the BMP becomes two spaces.
26
+ */
27
+ export const blank = (span) => span.replaceAll(/[^\n]/g, " ");
28
+ // Fenced code, indented in a list item or not, and HTML comments.
29
+ const block = /^[ \t]*(?<fence>(?<char>[`~])\k<char>{2,})[^\n]*\n[\s\S]*?^[ \t]*\k<fence>\k<char>*[ \t]*$|<!--[\s\S]*?-->/gmu;
30
+ // Code spans, link targets, autolinks and bare URLs.
31
+ const inline = /(?<ticks>`+)[^\n]*?\k<ticks>|\]\([^)\n]*\)|<https?:[^>\n]*>|https?:\/\/\S+/gu;
32
+ // U+FFFC instead of a space, so a dash next to a code span or link still has a non-space
33
+ // neighbour. None of the inline spans holds a line break.
34
+ const mark = (span) => "\uFFFC".repeat(span.length);
35
+ /**
36
+ * Finds vague words and dashes used as punctuation in Markdown or comment text. Fenced code, HTML
37
+ * comments, code spans, link targets, autolinks and URLs are not prose.
38
+ */
39
+ export const proseProblems = (text) => {
40
+ const prose = text.replaceAll(block, blank).replaceAll(inline, mark);
41
+ return rules
42
+ .flatMap(({ pattern, message }) => Array.from(prose.matchAll(pattern), (match) => ({
43
+ index: match.index,
44
+ text: match[0],
45
+ message,
46
+ })))
47
+ .sort((a, b) => a.index - b.index);
48
+ };
49
+ //# sourceMappingURL=problems.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"problems.js","sources":["../../src/prose/problems.ts"],"names":[],"mappings":"AASA,MAAM,KAAK,GAAG,CAAC,OAAe,EAAE,GAAW,EAAQ,EAAE,CAAC,CAAC;IACrD,OAAO;IACP,OAAO,EAAE,kDAAkD,GAAG,wCAAwC;CACvG,CAAC,CAAC;AAEH,MAAM,KAAK,GAAwB;IACjC,KAAK,CAAC,0CAA0C,EAAE,gCAAgC,CAAC;IACnF,KAAK,CAAC,8BAA8B,EAAE,wCAAwC,CAAC;IAC/E,KAAK,CAAC,oCAAoC,EAAE,wCAAwC,CAAC;IACrF,KAAK,CAAC,8CAA8C,EAAE,oBAAoB,CAAC;IAC3E,KAAK,CAAC,kDAAkD,EAAE,kBAAkB,CAAC;IAC7E,KAAK,CAAC,gC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AAG,CAAC,CAAC,KAAK,CAAC,CAAC;AACvC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const commentProse: import("@oxlint/plugins").Rule;
2
+ //# sourceMappingURL=comment-prose.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comment-prose.d.ts","sources":["../../src/rules/comment-prose.ts"],"names":[],"mappings":"AA2BA,eAAO,MAAM,YAAY,gCA8BvB,CAAC"}
@@ -0,0 +1,49 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { blank, proseProblems } from "../prose/problems.js";
3
+ import { effectDirective, lintDirective, reasonSeparator } from "./directives.js";
4
+ // JSDoc margins are not prose; a list item after one would read as a dash.
5
+ const jsdocMargin = /^[ \t]*\*/gm;
6
+ // TypeScript reads a `@ts-` directive at the start of a comment. The description after it is prose.
7
+ const typeScriptDirective = /^\s*@ts-(?:expect-error|ignore|nocheck)(?:\s--\s)?/;
8
+ // Blanks a directive's keyword and rules up to and including the separator, so ` -- ` is not read
9
+ // as a dash. The reason after it is prose.
10
+ const blankSyntax = (directive) => {
11
+ const separator = reasonSeparator.exec(directive);
12
+ const end = separator === null ? directive.length : separator.index + separator[0].length;
13
+ return blank(directive.slice(0, end)) + directive.slice(end);
14
+ };
15
+ const proseOf = (comment) => comment
16
+ .replaceAll(jsdocMargin, blank)
17
+ .replace(lintDirective, blankSyntax)
18
+ .replace(typeScriptDirective, blank)
19
+ .replaceAll(effectDirective, blankSyntax);
20
+ export const commentProse = defineRule({
21
+ meta: {
22
+ type: "suggestion",
23
+ docs: { description: "Disallow vague words and dashes used as punctuation in comments." },
24
+ schema: [],
25
+ messages: { prose: '"{{text}}" {{message}}' },
26
+ },
27
+ createOnce(context) {
28
+ return {
29
+ Program() {
30
+ const { sourceCode } = context;
31
+ for (const comment of sourceCode.getAllComments()) {
32
+ // The value starts after the comment's opening `//` or `/*`.
33
+ const start = comment.range[0] + 2;
34
+ for (const { index, text, message } of proseProblems(proseOf(comment.value))) {
35
+ context.report({
36
+ loc: {
37
+ start: sourceCode.getLocFromIndex(start + index),
38
+ end: sourceCode.getLocFromIndex(start + index + text.length),
39
+ },
40
+ messageId: "prose",
41
+ data: { text, message },
42
+ });
43
+ }
44
+ }
45
+ },
46
+ };
47
+ },
48
+ });
49
+ //# sourceMappingURL=comment-prose.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comment-prose.js","sources":["../../src/rules/comment-prose.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElF,2EAA2E;AAC3E,MAAM,WAAW,GAAG,aAAa,CAAC;AAElC,oGAAoG;AACpG,MAAM,mBAAmB,GAAG,oDAAoD,CAAC;AAEjF,kGAAkG;AAClG,2CAA2C;AAC3C,MAAM,WAAW,GAAG,CAAC,SAAiB,EAAE,EAAE;IACxC,MAAM,SAAS,GAAG,eAAe,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAClD,MAAM,GAAG,GAAG,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAE1F,OAAO,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AAC/D,CAAC,CAAC;AAEF,MAAM,OAAO,GAAG,CAAC,OAAe,EAAE,EAAE,CAClC,OAAO;KACJ,UAAU,CAAC,WAAW,EAAE,KAAK,CAAC;KAC9B,OAAO,CAAC,aAAa,EAAE,WAAW,CAAC;KACnC,OAAO,CAAC,mBAAmB,EAAE,KAAK,CAAC;KACnC,UAAU,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC;AAE9C,MAAM,CAAC,MAAM,YAAY,GAAG,UAAU,CAAC;IACrC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,EAAE,WAAW,EAAE,kEAAkE,EAAE;QACzF,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE,EAAE,KAAK,EAAE,wBAAwB,EAAE;KAC9C;IACD,UAAU,CAAC,OAAO;QAChB,OAAO;YACL,OAAO;gBACL,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;gBAE/B,KAAK,MAAM,OAAO,IAAI,UAAU,CAAC,cAAc,EAAE,EAAE,CAAC;oBAClD,6DAA6D;oBAC7D,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;oBAEnC,KAAK,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;wBAC7E,OAAO,CAAC,MAAM,CAAC;4BACb,GAAG,EAAE;gCACH,KAAK,EAAE,UAAU,CAAC,eAAe,CAAC,KAAK,GAAG,KAAK,CAAC;gCAChD,GAAG,EAAE,UAAU,CAAC,eAAe,CAAC,KAAK,GAAG,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC;6BAC7D;4BACD,SAAS,EAAE,OAAO;4BAClB,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;yBACxB,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare const lintDirective: RegExp;
2
+ export declare const effectDirective: RegExp;
3
+ export declare const reasonSeparator: RegExp;
4
+ //# sourceMappingURL=directives.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directives.d.ts","sources":["../../src/rules/directives.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,aAAa,QAC2E,CAAC;AAMtG,eAAO,MAAM,eAAe,QAC6D,CAAC;AAG1F,eAAO,MAAM,eAAe,QAAW,CAAC"}
@@ -0,0 +1,12 @@
1
+ // Comment directives as Oxlint, ESLint and tsgo read them.
2
+ // Oxlint honours a directive only at the start of a comment. A JSDoc comment starts with `*`, so
3
+ // Oxlint ignores a directive there. `text` holds the rule list and the reason.
4
+ export const lintDirective = /^\s*(?:oxlint|eslint)-(?:(?<disable>disable(?:-next-line|-line)?)|enable)(?=\s|$)(?<text>[\s\S]*)/;
5
+ // tsgo honours `@effect-diagnostics` anywhere in a comment, JSDoc included. It also reads string
6
+ // literals, which kit's rules do not check. A directive runs to the end of its line or to the next
7
+ // `@effect-diagnostics`, so a second directive on the same line cannot hide in the first one's
8
+ // reason.
9
+ export const effectDirective = /@effect-diagnostics(?:-next-line)?(?=\s|$)(?<text>(?:(?!@effect-diagnostics)[^\n])*)/g;
10
+ // The reason follows ` -- `; neither tool reads it as a rule.
11
+ export const reasonSeparator = /\s--\s/;
12
+ //# sourceMappingURL=directives.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directives.js","sources":["../../src/rules/directives.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAE3D,iGAAiG;AACjG,+EAA+E;AAC/E,MAAM,CAAC,MAAM,aAAa,GACxB,mGAAmG,CAAC;AAEtG,iGAAiG;AACjG,mGAAmG;AACnG,+FAA+F;AAC/F,UAAU;AACV,MAAM,CAAC,MAAM,eAAe,GAC1B,uFAAuF,CAAC;AAE1F,8DAA8D;AAC9D,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const noSuppressionDirectives: import("@oxlint/plugins").Rule;
2
+ //# sourceMappingURL=no-suppression-directives.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-suppression-directives.d.ts","sources":["../../src/rules/no-suppression-directives.ts"],"names":[],"mappings":"AAiFA,eAAO,MAAM,uBAAuB,gCA0DlC,CAAC"}
@@ -0,0 +1,93 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import { effectDirective, lintDirective, reasonSeparator } from "./directives.js";
3
+ const thisRule = "no-suppression-directives";
4
+ // Rules that keep the remaining suppressions visible. Suppressing them reopens what this rule closes.
5
+ const fenceRules = ["no-abusive-eslint-disable", "ban-ts-comment"];
6
+ // An Effect entry that sets one diagnostic to a level, such as `floatingEffect:off`. `*:off` and
7
+ // `skip-file` do not match.
8
+ const effectRuleLevel = /^[\w-]+:(?:off|warning|error|message|suggestion)$/;
9
+ // Oxlint splits a rule list on whitespace and commas, tsgo on whitespace.
10
+ const lintRuleSeparator = /[\s,]+/;
11
+ const effectEntrySeparator = /\s+/;
12
+ const splitReason = (text) => {
13
+ const separator = reasonSeparator.exec(text);
14
+ return separator === null
15
+ ? { list: text, reason: "" }
16
+ : {
17
+ list: text.slice(0, separator.index),
18
+ reason: text.slice(separator.index + separator[0].length).trim(),
19
+ };
20
+ };
21
+ const words = (list, separator) => list.split(separator).filter((word) => word !== "");
22
+ const directivesIn = (comment) => {
23
+ const effect = Array.from(comment.matchAll(effectDirective), (match) => {
24
+ const { list, reason } = splitReason(match.groups?.text ?? "");
25
+ return { kind: "effect-diagnostics", entries: words(list, effectEntrySeparator), reason };
26
+ });
27
+ const lint = lintDirective.exec(comment);
28
+ if (lint?.groups?.disable === undefined)
29
+ return effect;
30
+ const { list, reason } = splitReason(lint.groups.text ?? "");
31
+ return [{ kind: "lint-disable", rules: words(list, lintRuleSeparator), reason }, ...effect];
32
+ };
33
+ // A rule id may carry any plugin prefix, such as `kit/` or an alias the consumer chose.
34
+ const includesRule = (rules, rule) => rules.some((id) => id === rule || id.endsWith(`/${rule}`));
35
+ const namesEachRule = (directive) => directive.kind === "lint-disable"
36
+ ? directive.rules.length > 0
37
+ : directive.entries.length > 0 &&
38
+ directive.entries.every((entry) => effectRuleLevel.test(entry));
39
+ const violation = (directive, allowWithReason) => {
40
+ if (!allowWithReason)
41
+ return "suppression";
42
+ if (directive.kind === "lint-disable" &&
43
+ fenceRules.some((fence) => includesRule(directive.rules, fence))) {
44
+ return "fence";
45
+ }
46
+ return namesEachRule(directive) && directive.reason !== "" ? undefined : "unexplained";
47
+ };
48
+ export const noSuppressionDirectives = defineRule({
49
+ meta: {
50
+ type: "problem",
51
+ docs: {
52
+ description: "Disallow comments that suppress lint rules or Effect diagnostics, or allow only those that name their rules and give a reason.",
53
+ },
54
+ schema: [
55
+ {
56
+ type: "object",
57
+ properties: { allowWithReason: { type: "boolean" } },
58
+ additionalProperties: false,
59
+ },
60
+ ],
61
+ defaultOptions: [{ allowWithReason: false }],
62
+ messages: {
63
+ suppression: "Suppression comment. It hides a finding instead of fixing its cause. Fix: delete the comment and fix the finding.",
64
+ unexplained: "Suppression comment without named rules and a reason. A blanket or unexplained suppression also hides later findings. Fix: name each rule (`rule:level` for `@effect-diagnostics`) and append ` -- <reason>`, or delete the comment and fix the finding.",
65
+ fence: "Suppression of `no-abusive-eslint-disable` or `ban-ts-comment`. These rules keep the other suppressions visible. Fix: delete the comment and fix what the rule reports.",
66
+ },
67
+ },
68
+ createOnce(context) {
69
+ return {
70
+ Program() {
71
+ // SAFETY: Oxlint validates the options against `meta.schema` and merges them over
72
+ // `meta.defaultOptions`, so the first one is a complete `Options`.
73
+ const { allowWithReason } = context.options[0];
74
+ const comments = context.sourceCode
75
+ .getAllComments()
76
+ .map((comment) => ({ comment, directives: directivesIn(comment.value) }));
77
+ // A disable directive naming this rule would hide its reports. Reporting nothing leaves
78
+ // that directive unused, and `reportUnusedDisableDirectives` fails on it instead.
79
+ if (comments.some(({ directives }) => directives.some((directive) => directive.kind === "lint-disable" && includesRule(directive.rules, thisRule)))) {
80
+ return;
81
+ }
82
+ for (const { comment, directives } of comments) {
83
+ const messageId = directives
84
+ .map((directive) => violation(directive, allowWithReason))
85
+ .find((id) => id !== undefined);
86
+ if (messageId !== undefined)
87
+ context.report({ node: comment, messageId });
88
+ }
89
+ },
90
+ };
91
+ },
92
+ });
93
+ //# sourceMappingURL=no-suppression-directives.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-suppression-directives.js","sources":["../../src/rules/no-suppression-directives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElF,MAAM,QAAQ,GAAG,2BAA2B,CAAC;AAE7C,sGAAsG;AACtG,MAAM,UAAU,GAAG,CAAC,2BAA2B,EAAE,gBAAgB,CAAC,CAAC;AAEnE,iGAAiG;AACjG,4BAA4B;AAC5B,MAAM,eAAe,GAAG,mDAAmD,CAAC;AAE5E,0EAA0E;AAC1E,MAAM,iBAAiB,GAAG,QAAQ,CAAC;AAEnC,MAAM,oBAAoB,GAAG,KAAK,CAAC;AAYnC,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,EAAE;IACnC,MAAM,SAAS,GAAG,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE7C,OAAO,SAAS,KAAK,IAAI;QACvB,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE;QAC5B,CAAC,CAAC;YACE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,KAAK,CAAC;YACpC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE;SACjE,CAAC;AACR,CAAC,CAAC;AAEF,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,SAAiB,EAAE,EAAE,CAChD,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,CA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AO,CAAC,CAAC,CAAY,CAAC;gBAE1D,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU;qBAChC,cAAc,EAAE;qBAChB,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;gBAE5E,wFAAwF;gBACxF,kFAAkF;gBAClF,IACE,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAC/B,UAAU,CAAC,IAAI,CACb,CAAC,SAAS,EAAE,EAAE,CACZ,SAAS,CAAC,IAAI,KAAK,cAAc,IAAI,YAAY,CAAC,SAAS,CAAC,KAAK,EAAE,QAAQ,CAAC,CAC/E,CACF,EACD,CAAC;oBACD,OAAO;gBACT,CAAC;gBAED,KAAK,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,QAAQ,EAAE,CAAC;oBAC/C,MAAM,SAAS,GAAG,UAAU;yBACzB,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;yBACzD,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC;oBAElC,IAAI,SAAS,KAAK,SAAS;wBAAE,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;gBAC5E,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,13 +1,16 @@
1
1
  {
2
2
  "name": "@kutur-kit/oxc",
3
- "version": "0.1.0-alpha.2",
4
- "description": "Oxlint and Oxfmt presets for TypeScript, with optional Effect rules.",
3
+ "version": "0.1.0-alpha.3",
4
+ "description": "Oxlint and Oxfmt presets for TypeScript, with optional Effect rules and a prose check for Markdown.",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/kutur-labs/kit.git",
9
9
  "directory": "packages/oxc"
10
10
  },
11
+ "bin": {
12
+ "kit-prose": "./dist/prose/cli.js"
13
+ },
11
14
  "files": [
12
15
  "src",
13
16
  "dist"
package/src/anti-slop.ts CHANGED
@@ -6,6 +6,8 @@ const extension = import.meta.url.endsWith(".ts") ? "ts" : "js";
6
6
 
7
7
  const antiSlop: OxlintConfig = {
8
8
  jsPlugins: [
9
+ // `/base` registers the same plugin with the same specifier, so Oxlint loads it once.
10
+ { name: "kit", specifier: fileURLToPath(new URL(`./plugin.${extension}`, import.meta.url)) },
9
11
  {
10
12
  name: "anti-slop",
11
13
  specifier: fileURLToPath(new URL(`./vendor/anti-slop/index.${extension}`, import.meta.url)),
@@ -18,6 +20,7 @@ const antiSlop: OxlintConfig = {
18
20
  },
19
21
  ],
20
22
  rules: {
23
+ "kit/comment-prose": "error",
21
24
  "oxc/no-accumulating-spread": "error",
22
25
  "anti-slop/no-array-filter-map": "error",
23
26
  "anti-slop/no-reduce-accumulator-copy": "error",
package/src/base.ts CHANGED
@@ -15,7 +15,13 @@ const base: OxlintConfig = {
15
15
  plugins: ["typescript", "oxc", "unicorn", "import"],
16
16
  categories: { correctness: "error" },
17
17
  rules: {
18
+ "kit/no-suppression-directives": ["error", { allowWithReason: true }],
18
19
  "kit/no-yield-in-if": "error",
20
+ "unicorn/no-abusive-eslint-disable": "error",
21
+ "typescript/ban-ts-comment": [
22
+ "error",
23
+ { "ts-expect-error": "allow-with-description", "ts-ignore": true, "ts-nocheck": true },
24
+ ],
19
25
  "sonarjs/cognitive-complexity": ["error", 15],
20
26
  "max-depth": ["error", 3],
21
27
  "typescript/no-explicit-any": "error",
@@ -43,7 +49,7 @@ const base: OxlintConfig = {
43
49
  "no-debugger": "error",
44
50
  "prefer-const": "error",
45
51
  },
46
- options: { typeAware: true },
52
+ options: { typeAware: true, reportUnusedDisableDirectives: "error" },
47
53
  };
48
54
 
49
55
  export default base;
package/src/effect.ts CHANGED
@@ -6,6 +6,25 @@ import base from "./base.ts";
6
6
 
7
7
  const effect: OxlintConfig = {
8
8
  extends: [base, recommended],
9
+ rules: {
10
+ // Globals that bypass Effect's services, so layers and tests cannot replace them.
11
+ "effecttsgo/crypto-random-uuid": "warn",
12
+ "effecttsgo/crypto-random-uuid-in-effect": "warn",
13
+ "effecttsgo/global-console": "warn",
14
+ "effecttsgo/global-console-in-effect": "warn",
15
+ "effecttsgo/global-date": "warn",
16
+ "effecttsgo/global-date-in-effect": "warn",
17
+ "effecttsgo/global-fetch": "warn",
18
+ "effecttsgo/global-fetch-in-effect": "warn",
19
+ "effecttsgo/global-random": "warn",
20
+ "effecttsgo/global-random-in-effect": "warn",
21
+ "effecttsgo/global-timers": "warn",
22
+ "effecttsgo/global-timers-in-effect": "warn",
23
+ "effecttsgo/process-env": "warn",
24
+ "effecttsgo/process-env-in-effect": "warn",
25
+ // Effect's documented form for a service is a class that extends `Context.Service`.
26
+ "effecttsgo/service-not-as-class": "warn",
27
+ },
9
28
  options: { typeAware: true },
10
29
  };
11
30
 
package/src/plugin.ts CHANGED
@@ -1,8 +1,14 @@
1
1
  import { definePlugin } from "@oxlint/plugins";
2
2
 
3
+ import { commentProse } from "./rules/comment-prose.ts";
4
+ import { noSuppressionDirectives } from "./rules/no-suppression-directives.ts";
3
5
  import { noYieldInIf } from "./rules/no-yield-in-if.ts";
4
6
 
5
7
  export default definePlugin({
6
8
  meta: { name: "@kutur-kit/oxc" },
7
- rules: { "no-yield-in-if": noYieldInIf },
9
+ rules: {
10
+ "comment-prose": commentProse,
11
+ "no-suppression-directives": noSuppressionDirectives,
12
+ "no-yield-in-if": noYieldInIf,
13
+ },
8
14
  });
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env node
2
+ import { globSync, readFileSync } from "node:fs";
3
+ import { join, resolve } from "node:path";
4
+ import { parseArgs } from "node:util";
5
+
6
+ import { proseProblems } from "./problems.ts";
7
+
8
+ const usage = "Usage: kit-prose [--budget <file>=<characters>]... <glob>...";
9
+
10
+ const { values, positionals } = parseArgs({
11
+ allowPositionals: true,
12
+ options: { budget: { type: "string", multiple: true, default: [] } },
13
+ });
14
+
15
+ if (positionals.length === 0) throw new Error(`No glob given. ${usage}`);
16
+
17
+ // Keyed by absolute path, so `AGENTS.md` and `./AGENTS.md` name the same file.
18
+ const budgets = new Map(
19
+ values.budget.map((entry) => {
20
+ const { file, limit } = /^(?<file>.+)=(?<limit>\d+)$/.exec(entry)?.groups ?? {};
21
+
22
+ if (file === undefined || limit === undefined) {
23
+ throw new Error(`--budget ${entry} is not <file>=<characters>. ${usage}`);
24
+ }
25
+
26
+ return [resolve(file), { file, limit: Number(limit) }] as const;
27
+ }),
28
+ );
29
+
30
+ const failures: string[] = [];
31
+
32
+ const files = new Set<string>();
33
+
34
+ for (const pattern of positionals) {
35
+ const matched: string[] = [];
36
+
37
+ // A symlink such as `CLAUDE.md` is not a file entry, so its target is not reported twice.
38
+ for (const entry of globSync(pattern, { exclude: ["**/node_modules"], withFileTypes: true })) {
39
+ if (entry.isFile()) matched.push(join(entry.parentPath, entry.name));
40
+ }
41
+
42
+ // Counted after filtering, so a pattern that matches only directories or symlinks fails too.
43
+ if (matched.length === 0) {
44
+ failures.push(
45
+ `${pattern}: matches no file. The pattern checks nothing. Fix: correct the pattern or remove it.`,
46
+ );
47
+ }
48
+
49
+ for (const file of matched) files.add(file);
50
+ }
51
+
52
+ const checked = new Set(Array.from(files, (file) => resolve(file)));
53
+
54
+ for (const [path, { file }] of budgets) {
55
+ if (!checked.has(path)) {
56
+ failures.push(
57
+ `${file}: has a budget, but no pattern matches it. The budget checks nothing. Fix: correct the path or add a pattern that matches it.`,
58
+ );
59
+ }
60
+ }
61
+
62
+ for (const file of Array.from(files).sort()) {
63
+ const markdown = readFileSync(file, "utf8");
64
+
65
+ for (const { index, text, message } of proseProblems(markdown)) {
66
+ failures.push(`${file}:${markdown.slice(0, index).split("\n").length}: "${text}" ${message}`);
67
+ }
68
+
69
+ const budget = budgets.get(resolve(file));
70
+ // Code points, so a character outside the BMP counts once.
71
+ const characters = Array.from(markdown).length;
72
+
73
+ if (budget !== undefined && characters > budget.limit) {
74
+ failures.push(
75
+ `${file}: ${characters} characters, over its budget of ${budget.limit}. Raising the budget needs the user. Fix: shorten it or move a rule into a check.`,
76
+ );
77
+ }
78
+ }
79
+
80
+ if (failures.length > 0) {
81
+ console.error(failures.join("\n"));
82
+ // Unlike `process.exit`, `exitCode` lets stderr finish writing to a pipe.
83
+ process.exitCode = 1;
84
+ } else {
85
+ console.log(`Checked prose in ${files.size} Markdown ${files.size === 1 ? "file" : "files"}.`);
86
+ }
@@ -0,0 +1,68 @@
1
+ /** A vague word or a dash used as punctuation, at a UTF-16 offset into the checked text. */
2
+ export type ProseProblem = {
3
+ readonly index: number;
4
+ readonly text: string;
5
+ readonly message: string;
6
+ };
7
+
8
+ type Rule = { readonly pattern: RegExp; readonly message: string };
9
+
10
+ const vague = (pattern: RegExp, fix: string): Rule => ({
11
+ pattern,
12
+ message: `is vague. A plain word says what happens. Fix: ${fix}, or put a literal use in a code span.`,
13
+ });
14
+
15
+ const rules: ReadonlyArray<Rule> = [
16
+ vague(/\b(?:stamp|stamps|stamped|stamping)\b/giu, "say who records or approves it"),
17
+ vague(/\b(?:land|lands|landed)\b/giu, "say `merged`, `deployed` or `released`"),
18
+ vague(/\b(?:gate|gates|gated|gating)\b/giu, "say what checks, blocks or requires it"),
19
+ vague(/\b(?:unlock|unlocks|unlocked|unlocking)\b/giu, "say what it allows"),
20
+ vague(/\b(?:supercharge|supercharges|supercharged)\b/giu, "say what changes"),
21
+ vague(/\b(?:seamless|seamlessly)\b/giu, "delete it or say what keeps working"),
22
+ vague(/\bbattle-tested\b/giu, "say where it runs or what tests it"),
23
+ vague(/\b(?:leverage|leverages|leveraged|leveraging)\b/giu, "say `use`"),
24
+ vague(/\b(?:empower|empowers|empowered|empowering)\b/giu, "say `lets` or `supports`"),
25
+ {
26
+ // An em dash (U+2014) anywhere. An en dash (U+2013), `-` or `--` only between spaces, so
27
+ // ranges such as `2–4`, hyphenated words, flags and list items pass.
28
+ pattern: /\u2014|(?<=\S )(?:\u2013|--?)(?= \S)/gu,
29
+ message:
30
+ "is a dash used as punctuation. A period, comma, colon or parentheses say how the parts relate. Fix: use one of them, or put a literal use in a code span.",
31
+ },
32
+ ];
33
+
34
+ /**
35
+ * Replaces every character but line breaks with a space, so offsets and line numbers still point
36
+ * into the source. Without the `u` flag the pattern matches UTF-16 units, so a character outside
37
+ * the BMP becomes two spaces.
38
+ */
39
+ export const blank = (span: string) => span.replaceAll(/[^\n]/g, " ");
40
+
41
+ // Fenced code, indented in a list item or not, and HTML comments.
42
+ const block =
43
+ /^[ \t]*(?<fence>(?<char>[`~])\k<char>{2,})[^\n]*\n[\s\S]*?^[ \t]*\k<fence>\k<char>*[ \t]*$|<!--[\s\S]*?-->/gmu;
44
+
45
+ // Code spans, link targets, autolinks and bare URLs.
46
+ const inline = /(?<ticks>`+)[^\n]*?\k<ticks>|\]\([^)\n]*\)|<https?:[^>\n]*>|https?:\/\/\S+/gu;
47
+
48
+ // U+FFFC instead of a space, so a dash next to a code span or link still has a non-space
49
+ // neighbour. None of the inline spans holds a line break.
50
+ const mark = (span: string) => "\uFFFC".repeat(span.length);
51
+
52
+ /**
53
+ * Finds vague words and dashes used as punctuation in Markdown or comment text. Fenced code, HTML
54
+ * comments, code spans, link targets, autolinks and URLs are not prose.
55
+ */
56
+ export const proseProblems = (text: string): ReadonlyArray<ProseProblem> => {
57
+ const prose = text.replaceAll(block, blank).replaceAll(inline, mark);
58
+
59
+ return rules
60
+ .flatMap(({ pattern, message }) =>
61
+ Array.from(prose.matchAll(pattern), (match) => ({
62
+ index: match.index,
63
+ text: match[0],
64
+ message,
65
+ })),
66
+ )
67
+ .sort((a, b) => a.index - b.index);
68
+ };
@@ -0,0 +1,58 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+
3
+ import { blank, proseProblems } from "../prose/problems.ts";
4
+ import { effectDirective, lintDirective, reasonSeparator } from "./directives.ts";
5
+
6
+ // JSDoc margins are not prose; a list item after one would read as a dash.
7
+ const jsdocMargin = /^[ \t]*\*/gm;
8
+
9
+ // TypeScript reads a `@ts-` directive at the start of a comment. The description after it is prose.
10
+ const typeScriptDirective = /^\s*@ts-(?:expect-error|ignore|nocheck)(?:\s--\s)?/;
11
+
12
+ // Blanks a directive's keyword and rules up to and including the separator, so ` -- ` is not read
13
+ // as a dash. The reason after it is prose.
14
+ const blankSyntax = (directive: string) => {
15
+ const separator = reasonSeparator.exec(directive);
16
+ const end = separator === null ? directive.length : separator.index + separator[0].length;
17
+
18
+ return blank(directive.slice(0, end)) + directive.slice(end);
19
+ };
20
+
21
+ const proseOf = (comment: string) =>
22
+ comment
23
+ .replaceAll(jsdocMargin, blank)
24
+ .replace(lintDirective, blankSyntax)
25
+ .replace(typeScriptDirective, blank)
26
+ .replaceAll(effectDirective, blankSyntax);
27
+
28
+ export const commentProse = defineRule({
29
+ meta: {
30
+ type: "suggestion",
31
+ docs: { description: "Disallow vague words and dashes used as punctuation in comments." },
32
+ schema: [],
33
+ messages: { prose: '"{{text}}" {{message}}' },
34
+ },
35
+ createOnce(context) {
36
+ return {
37
+ Program() {
38
+ const { sourceCode } = context;
39
+
40
+ for (const comment of sourceCode.getAllComments()) {
41
+ // The value starts after the comment's opening `//` or `/*`.
42
+ const start = comment.range[0] + 2;
43
+
44
+ for (const { index, text, message } of proseProblems(proseOf(comment.value))) {
45
+ context.report({
46
+ loc: {
47
+ start: sourceCode.getLocFromIndex(start + index),
48
+ end: sourceCode.getLocFromIndex(start + index + text.length),
49
+ },
50
+ messageId: "prose",
51
+ data: { text, message },
52
+ });
53
+ }
54
+ }
55
+ },
56
+ };
57
+ },
58
+ });
@@ -0,0 +1,16 @@
1
+ // Comment directives as Oxlint, ESLint and tsgo read them.
2
+
3
+ // Oxlint honours a directive only at the start of a comment. A JSDoc comment starts with `*`, so
4
+ // Oxlint ignores a directive there. `text` holds the rule list and the reason.
5
+ export const lintDirective =
6
+ /^\s*(?:oxlint|eslint)-(?:(?<disable>disable(?:-next-line|-line)?)|enable)(?=\s|$)(?<text>[\s\S]*)/;
7
+
8
+ // tsgo honours `@effect-diagnostics` anywhere in a comment, JSDoc included. It also reads string
9
+ // literals, which kit's rules do not check. A directive runs to the end of its line or to the next
10
+ // `@effect-diagnostics`, so a second directive on the same line cannot hide in the first one's
11
+ // reason.
12
+ export const effectDirective =
13
+ /@effect-diagnostics(?:-next-line)?(?=\s|$)(?<text>(?:(?!@effect-diagnostics)[^\n])*)/g;
14
+
15
+ // The reason follows ` -- `; neither tool reads it as a rule.
16
+ export const reasonSeparator = /\s--\s/;
@@ -0,0 +1,140 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+
3
+ import { effectDirective, lintDirective, reasonSeparator } from "./directives.ts";
4
+
5
+ const thisRule = "no-suppression-directives";
6
+
7
+ // Rules that keep the remaining suppressions visible. Suppressing them reopens what this rule closes.
8
+ const fenceRules = ["no-abusive-eslint-disable", "ban-ts-comment"];
9
+
10
+ // An Effect entry that sets one diagnostic to a level, such as `floatingEffect:off`. `*:off` and
11
+ // `skip-file` do not match.
12
+ const effectRuleLevel = /^[\w-]+:(?:off|warning|error|message|suggestion)$/;
13
+
14
+ // Oxlint splits a rule list on whitespace and commas, tsgo on whitespace.
15
+ const lintRuleSeparator = /[\s,]+/;
16
+
17
+ const effectEntrySeparator = /\s+/;
18
+
19
+ type Directive =
20
+ | { readonly kind: "lint-disable"; readonly rules: string[]; readonly reason: string }
21
+ | { readonly kind: "effect-diagnostics"; readonly entries: string[]; readonly reason: string };
22
+
23
+ // A type alias, unlike an interface, is assignable to `JsonObject`, so `context.options` can be
24
+ // asserted to it.
25
+ type Options = { readonly allowWithReason: boolean };
26
+
27
+ type MessageId = "suppression" | "unexplained" | "fence";
28
+
29
+ const splitReason = (text: string) => {
30
+ const separator = reasonSeparator.exec(text);
31
+
32
+ return separator === null
33
+ ? { list: text, reason: "" }
34
+ : {
35
+ list: text.slice(0, separator.index),
36
+ reason: text.slice(separator.index + separator[0].length).trim(),
37
+ };
38
+ };
39
+
40
+ const words = (list: string, separator: RegExp) =>
41
+ list.split(separator).filter((word) => word !== "");
42
+
43
+ const directivesIn = (comment: string): Directive[] => {
44
+ const effect = Array.from(comment.matchAll(effectDirective), (match): Directive => {
45
+ const { list, reason } = splitReason(match.groups?.text ?? "");
46
+
47
+ return { kind: "effect-diagnostics", entries: words(list, effectEntrySeparator), reason };
48
+ });
49
+
50
+ const lint = lintDirective.exec(comment);
51
+
52
+ if (lint?.groups?.disable === undefined) return effect;
53
+
54
+ const { list, reason } = splitReason(lint.groups.text ?? "");
55
+
56
+ return [{ kind: "lint-disable", rules: words(list, lintRuleSeparator), reason }, ...effect];
57
+ };
58
+
59
+ // A rule id may carry any plugin prefix, such as `kit/` or an alias the consumer chose.
60
+ const includesRule = (rules: string[], rule: string) =>
61
+ rules.some((id) => id === rule || id.endsWith(`/${rule}`));
62
+
63
+ const namesEachRule = (directive: Directive) =>
64
+ directive.kind === "lint-disable"
65
+ ? directive.rules.length > 0
66
+ : directive.entries.length > 0 &&
67
+ directive.entries.every((entry) => effectRuleLevel.test(entry));
68
+
69
+ const violation = (directive: Directive, allowWithReason: boolean): MessageId | undefined => {
70
+ if (!allowWithReason) return "suppression";
71
+
72
+ if (
73
+ directive.kind === "lint-disable" &&
74
+ fenceRules.some((fence) => includesRule(directive.rules, fence))
75
+ ) {
76
+ return "fence";
77
+ }
78
+
79
+ return namesEachRule(directive) && directive.reason !== "" ? undefined : "unexplained";
80
+ };
81
+
82
+ export const noSuppressionDirectives = defineRule({
83
+ meta: {
84
+ type: "problem",
85
+ docs: {
86
+ description:
87
+ "Disallow comments that suppress lint rules or Effect diagnostics, or allow only those that name their rules and give a reason.",
88
+ },
89
+ schema: [
90
+ {
91
+ type: "object",
92
+ properties: { allowWithReason: { type: "boolean" } },
93
+ additionalProperties: false,
94
+ },
95
+ ],
96
+ defaultOptions: [{ allowWithReason: false }],
97
+ messages: {
98
+ suppression:
99
+ "Suppression comment. It hides a finding instead of fixing its cause. Fix: delete the comment and fix the finding.",
100
+ unexplained:
101
+ "Suppression comment without named rules and a reason. A blanket or unexplained suppression also hides later findings. Fix: name each rule (`rule:level` for `@effect-diagnostics`) and append ` -- <reason>`, or delete the comment and fix the finding.",
102
+ fence:
103
+ "Suppression of `no-abusive-eslint-disable` or `ban-ts-comment`. These rules keep the other suppressions visible. Fix: delete the comment and fix what the rule reports.",
104
+ },
105
+ },
106
+ createOnce(context) {
107
+ return {
108
+ Program() {
109
+ // SAFETY: Oxlint validates the options against `meta.schema` and merges them over
110
+ // `meta.defaultOptions`, so the first one is a complete `Options`.
111
+ const { allowWithReason } = context.options[0] as Options;
112
+
113
+ const comments = context.sourceCode
114
+ .getAllComments()
115
+ .map((comment) => ({ comment, directives: directivesIn(comment.value) }));
116
+
117
+ // A disable directive naming this rule would hide its reports. Reporting nothing leaves
118
+ // that directive unused, and `reportUnusedDisableDirectives` fails on it instead.
119
+ if (
120
+ comments.some(({ directives }) =>
121
+ directives.some(
122
+ (directive) =>
123
+ directive.kind === "lint-disable" && includesRule(directive.rules, thisRule),
124
+ ),
125
+ )
126
+ ) {
127
+ return;
128
+ }
129
+
130
+ for (const { comment, directives } of comments) {
131
+ const messageId = directives
132
+ .map((directive) => violation(directive, allowWithReason))
133
+ .find((id) => id !== undefined);
134
+
135
+ if (messageId !== undefined) context.report({ node: comment, messageId });
136
+ }
137
+ },
138
+ };
139
+ },
140
+ });