@pragmatiks/lint 0.7.0 → 0.9.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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## js-v0.9.0 (2026-11-08)
4
+
5
+ ### Features
6
+
7
+ - **rules**: drop the TS/JS comment semgrep rules the ESLint rules replace (PRA-680)
8
+ - **js**: add the no-comments and css-no-comments ESLint rules (PRA-680)
9
+
10
+ ## js-v0.8.0 (2026-11-07)
11
+
12
+ ### Features
13
+
14
+ - **rules**: flag pure-prefixed functions that perform I/O (PRA-453, PRA-750)
15
+
3
16
  ## js-v0.7.0 (2026-10-07)
4
17
 
5
18
  ### Bug Fixes
package/README.md CHANGED
@@ -17,7 +17,7 @@ This package has no `bin` entry. Command-line integration belongs in `pragma-cli
17
17
  | `eslint-plugin-sonarjs` | `^4.0.0` |
18
18
  | `eslint-plugin-unicorn` | `^64.0.0` |
19
19
 
20
- **`/eslint-config/next` only** (optional peers; install them when you use `@pragmatiks/lint/eslint-config/next`):
20
+ **`/eslint-config/next` only** (optional peers; install them when you use `@pragmatiks/lint/eslint-config/next`; `/eslint-config/css` needs `@eslint/css` alone):
21
21
 
22
22
  | Package | Range | Why |
23
23
  | ----------------------- | --------- | -------------------------------------------------------------------- |
@@ -41,6 +41,28 @@ export default pragmatiksConfig();
41
41
 
42
42
  Every object except the global ignores, the sonarjs and unicorn recommended presets included, applies only to `PRAGMATIKS_LINT_FILES` (`**/*.{js,jsx,mjs,cjs,ts,tsx,mts,cts}`), so the config composes with configs for other languages such as CSS.
43
43
 
44
+ ### Comment ban (principle 10)
45
+
46
+ `pragmatiks-comments/no-comments` flags every JavaScript and TypeScript comment except:
47
+
48
+ - a JSDoc block (`/** ... */`, in JSX `{/** ... */}` too) and a line-1 shebang;
49
+ - a bare tool directive, matched against the whole comment: `eslint-disable`, `eslint-disable-line`, `eslint-disable-next-line` and `eslint-enable` with an optional rule list (`@scope/rule` names, comma separated), `eslint <config>`, `global` / `globals`, `exported`, `@ts-expect-error` and `/// <reference ... />`.
50
+
51
+ A directive with a `-- description` or other prose is flagged, matching the Python `pragmatiks_lint.comments` check; the rationale belongs in the owning JSDoc. `TODO(PRA-n)` gets no exception. `@typescript-eslint/ban-ts-comment` is set to allow a bare `@ts-expect-error`; `@ts-ignore` and `@ts-nocheck` stay flagged. The rules live in the `pragmatiks-comments` plugin, a name distinct from the `/next` frontend plugin, and the base config registers the `typescript-eslint` plugin instance `eslint-config-next` also registers.
52
+
53
+ ## `@pragmatiks/lint/eslint-config/css`
54
+
55
+ The stylesheet config, one object for `**/*.css` that parses with `@eslint/css` (optional peer `^2.0.0`) tolerantly and turns on `pragmatiks-comments/css-no-comments`, which flags every CSS comment except a bare ESLint directive:
56
+
57
+ ```ts
58
+ import { pragmatiksConfig } from "@pragmatiks/lint";
59
+ import { pragmatiksCssConfig } from "@pragmatiks/lint/eslint-config/css";
60
+
61
+ export default [...pragmatiksConfig(), pragmatiksCssConfig()];
62
+ ```
63
+
64
+ `pragmatiksNextConfig` already includes it.
65
+
44
66
  ## `@pragmatiks/lint/eslint-config/next`
45
67
 
46
68
  In the app's `eslint.config.mjs`:
@@ -142,7 +164,7 @@ Fix these by rewriting the code:
142
164
 
143
165
  ## Development
144
166
 
145
- | Command | Purpose |
146
- | -------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
147
- | `task js:check` / `task js:test` / `task js:build` | Lint and type check / tests (Node `>=22.15` for `module.registerHooks`; `mise.toml` pins Node 26) / build |
148
- | `task js:pack` | Install, build and `npm pack` the committed HEAD with CI's toolchain (Node 26, pnpm 12.6.0, latest npm) in a throwaway worktree, printing all three versions; the tarball lands in `js/` |
167
+ | Command | Purpose |
168
+ | -------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
169
+ | `mise run js:check` / `mise run js:test` / `mise run js:build` | Lint and type check / tests (Node `>=22.15` for `module.registerHooks`; `mise.toml` pins Node 26) / build |
170
+ | `mise run js:pack` | Install, build and `npm pack` the committed HEAD as CI publishes it, with the mise-locked node, pnpm and npm, in a throwaway worktree, printing all three versions; the tarball lands in `js/` |
@@ -0,0 +1,16 @@
1
+ import { Linter } from 'eslint';
2
+
3
+ /**
4
+ * The files the stylesheet config applies to.
5
+ */
6
+ declare const PRAGMATIKS_CSS_FILES: string[];
7
+ /**
8
+ * Builds the Pragmatiks flat config object for CSS files.
9
+ *
10
+ * Note: requires the optional peer `@eslint/css`.
11
+ *
12
+ * @returns The config object: `@eslint/css` parsing tolerantly, with `css-no-comments` on.
13
+ */
14
+ declare function pragmatiksCssConfig(): Linter.Config;
15
+
16
+ export { PRAGMATIKS_CSS_FILES, pragmatiksCssConfig as default, pragmatiksCssConfig };
@@ -0,0 +1,122 @@
1
+ import css from '@eslint/css';
2
+
3
+ // src/eslint-config/css/index.ts
4
+
5
+ // src/eslint-config/rules/directives.ts
6
+ var RULE_LIST = String.raw`[\w@/.-]+(?:\s*,\s*[\w@/.-]+)*`;
7
+ var NAME_LIST = String.raw`[\w$:-]+(?:[\s,]+[\w$:-]+)*`;
8
+ var TRIPLE_SLASH_PREFIX = "/ <reference ";
9
+ var TRIPLE_SLASH_SUFFIX = "/>";
10
+ var DESCRIPTION_SEPARATOR = "--";
11
+ var TS_EXPECT_ERROR = "@ts-expect-error";
12
+ var ESLINT_DIRECTIVES = [
13
+ new RegExp(
14
+ String.raw`^eslint-(?:disable(?:-next-line|-line)?|enable)(?:\s+${RULE_LIST})?$`
15
+ ),
16
+ new RegExp(String.raw`^(?:globals?|exported)\s+${NAME_LIST}$`),
17
+ /^eslint\s+\S[\s\S]*$/
18
+ ];
19
+ function isBareEslintDirective(text) {
20
+ const trimmed = text.trim();
21
+ if (trimmed.includes(DESCRIPTION_SEPARATOR)) {
22
+ return false;
23
+ }
24
+ return ESLINT_DIRECTIVES.some((pattern) => pattern.test(trimmed));
25
+ }
26
+ function isTripleSlashReference(trimmed) {
27
+ return trimmed.startsWith(TRIPLE_SLASH_PREFIX) && trimmed.endsWith(TRIPLE_SLASH_SUFFIX) && trimmed.indexOf(">") === trimmed.length - 1;
28
+ }
29
+ function isBareScriptDirective(text, isLine) {
30
+ const trimmed = text.trim();
31
+ if (isLine && isTripleSlashReference(trimmed)) {
32
+ return true;
33
+ }
34
+ return trimmed === TS_EXPECT_ERROR || isBareEslintDirective(trimmed);
35
+ }
36
+
37
+ // src/eslint-config/rules/css-no-comments.ts
38
+ var cssNoCommentsRule = {
39
+ meta: {
40
+ type: "problem",
41
+ docs: {
42
+ description: "Disallow stylesheet comments other than bare ESLint directives (principle 10)."
43
+ },
44
+ messages: {
45
+ comment: "Principle 10: delete this comment, or move its rationale into the JSDoc of the component that sets the selector."
46
+ },
47
+ schema: []
48
+ },
49
+ create(context) {
50
+ return {
51
+ StyleSheet() {
52
+ for (const comment of context.sourceCode.comments ?? []) {
53
+ if (comment.loc && !isBareEslintDirective(comment.value)) {
54
+ context.report({ loc: comment.loc, messageId: "comment" });
55
+ }
56
+ }
57
+ }
58
+ };
59
+ }
60
+ };
61
+
62
+ // src/eslint-config/rules/no-comments.ts
63
+ function isPermittedComment(comment, sourceCode) {
64
+ const isJsdoc = comment.type === "Block" && comment.value.startsWith("*");
65
+ const isShebang = comment.range?.[0] === 0 && sourceCode.text.startsWith("#!");
66
+ return isJsdoc || isShebang || isBareScriptDirective(comment.value, comment.type === "Line");
67
+ }
68
+ var noCommentsRule = {
69
+ meta: {
70
+ type: "problem",
71
+ docs: {
72
+ description: "Disallow comments other than JSDoc and bare tool directives (principle 10)."
73
+ },
74
+ messages: {
75
+ comment: "Principle 10: delete this comment, or move its rationale into the owning JSDoc. Tool directives stay bare, with no `-- description`."
76
+ },
77
+ schema: []
78
+ },
79
+ create(context) {
80
+ const { sourceCode } = context;
81
+ return {
82
+ Program() {
83
+ for (const comment of sourceCode.getAllComments()) {
84
+ if (comment.loc && !isPermittedComment(comment, sourceCode)) {
85
+ context.report({ loc: comment.loc, messageId: "comment" });
86
+ }
87
+ }
88
+ }
89
+ };
90
+ }
91
+ };
92
+
93
+ // src/eslint-config/rules/plugin.ts
94
+ var COMMENTS_PLUGIN_NAME = "pragmatiks-comments";
95
+ var commentsPlugin = {
96
+ meta: { name: "@pragmatiks/lint/comments" },
97
+ rules: {
98
+ "no-comments": noCommentsRule,
99
+ "css-no-comments": cssNoCommentsRule
100
+ }
101
+ };
102
+
103
+ // src/eslint-config/css/index.ts
104
+ var PRAGMATIKS_CSS_FILES = ["**/*.css"];
105
+ function pragmatiksCssConfig() {
106
+ return {
107
+ name: "pragmatiks/css",
108
+ files: PRAGMATIKS_CSS_FILES,
109
+ plugins: {
110
+ css,
111
+ [COMMENTS_PLUGIN_NAME]: commentsPlugin
112
+ },
113
+ language: "css/css",
114
+ languageOptions: { tolerant: true },
115
+ rules: { [`${COMMENTS_PLUGIN_NAME}/css-no-comments`]: "error" }
116
+ };
117
+ }
118
+ var css_default = pragmatiksCssConfig;
119
+
120
+ export { PRAGMATIKS_CSS_FILES, css_default as default, pragmatiksCssConfig };
121
+ //# sourceMappingURL=index.js.map
122
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/eslint-config/rules/directives.ts","../../../src/eslint-config/rules/css-no-comments.ts","../../../src/eslint-config/rules/no-comments.ts","../../../src/eslint-config/rules/plugin.ts","../../../src/eslint-config/css/index.ts"],"names":[],"mappings":";;;;;AASA,IAAM,YAAY,MAAA,CAAO,GAAA,CAAA,8BAAA,CAAA;AAKzB,IAAM,YAAY,MAAA,CAAO,GAAA,CAAA,2BAAA,CAAA;AAKzB,IAAM,mBAAA,GAAsB,eAAA;AAK5B,IAAM,mBAAA,GAAsB,IAAA;AAK5B,IAAM,qBAAA,GAAwB,IAAA;AAK9B,IAAM,eAAA,GAAkB,kBAAA;AAKxB,IAAM,iBAAA,GAAuC;AAAA,EAC3C,IAAI,MAAA;AAAA,IACF,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AE,GAAA,EAAK,QAAQ,GAAA,EAAK,SAAA,EAAW,WAAW,CAAA;AAAA,UAC3D;AAAA,QACF;AAAA,MACF;AAAA,KACF;AAAA,EACF;AACF,CAAA;;;AC7CO,IAAM,oBAAA,GAAuB,qBAAA;AAK7B,IAAM,cAAA,GAAgC;AAAA,EAC3C,IAAA,EAAM,EAAE,IAAA,EAAM,2BAAA,EAA4B;AAAA,EAC1C,KAAA,EAAO;AAAA,IACL,aAAA,EAAe,cAAA;AAAA,IACf,iBAAA,EAAmB;AAAA;AAEvB,CAAA;;;ACdO,IAAM,oBAAA,GAAuB,CAAC,UAAU;AASxC,SAAS,mBAAA,GAAqC;AACnD,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,gBAAA;AAAA,IACN,KAAA,EAAO,oBAAA;AAAA,IACP,OAAA,EAAS;AAAA,MACP,GAAA;AAAA,MACA,CAAC,oBAAoB,GAAG;AAAA,KAC1B;AAAA,IACA,QAAA,EAAU,SAAA;AAAA,IACV,eAAA,EAAiB,EAAE,QAAA,EAAU,IAAA,EAAK;AAAA,IAClC,OAAO,EAAE,CAAC,GAAG,oBAAoB,CAAA,gBAAA,CAAkB,GAAG,OAAA;AAAQ,GAChE;AACF;AAEA,IAAO,WAAA,GAAQ","file":"index.js","sourcesContent":["/**\n * Recognizes bare tool directives, the only comments principle 10 keeps.\n *\n * @packageDocumentation\n */\n\n/**\n * A comma-separated list of rule names an ESLint directive may carry.\n */\nconst RULE_LIST = String.raw`[\\w@/.-]+(?:\\s*,\\s*[\\w@/.-]+)*`;\n\n/**\n * A list of global or exported names a `global(s)` or `exported` directive may carry.\n */\nconst NAME_LIST = String.raw`[\\w$:-]+(?:[\\s,]+[\\w$:-]+)*`;\n\n/**\n * The opening of a triple-slash reference after its `//`.\n */\nconst TRIPLE_SLASH_PREFIX = \"/ <reference \";\n\n/**\n * The closing of a triple-slash reference.\n */\nconst TRIPLE_SLASH_SUFFIX = \"/>\";\n\n/**\n * The separator that starts a directive's description.\n */\nconst DESCRIPTION_SEPARATOR = \"--\";\n\n/**\n * The TypeScript directive kept in a JavaScript or TypeScript comment.\n */\nconst TS_EXPECT_ERROR = \"@ts-expect-error\";\n\n/**\n * Directives ESLint reads from any comment, each matched against the whole trimmed comment text.\n */\nconst ESLINT_DIRECTIVES: readonly RegExp[] = [\n new RegExp(\n String.raw`^eslint-(?:disable(?:-next-line|-line)?|enable)(?:\\s+${RULE_LIST})?$`,\n ),\n new RegExp(String.raw`^(?:globals?|exported)\\s+${NAME_LIST}$`),\n /^eslint\\s+\\S[\\s\\S]*$/,\n];\n\n/**\n * Tells whether a comment's text is a bare ESLint directive.\n *\n * Note: a directive carrying a `-- description` is not bare; its rationale belongs in the owning\n * docstring.\n *\n * @param text - The comment text without its delimiters.\n * @returns `true` when the text is an ESLint directive with no description.\n */\nexport function isBareEslintDirective(text: string): boolean {\n const trimmed = text.trim();\n if (trimmed.includes(DESCRIPTION_SEPARATOR)) {\n return false;\n }\n return ESLINT_DIRECTIVES.some((pattern) => pattern.test(trimmed));\n}\n\n/**\n * Tells whether a line comment's trimmed text is a triple-slash reference.\n *\n * @param trimmed - The trimmed text after `//`.\n * @returns `true` for `/ <reference ... />` holding no other `>`.\n */\nfunction isTripleSlashReference(trimmed: string): boolean {\n return (\n trimmed.startsWith(TRIPLE_SLASH_PREFIX) &&\n trimmed.endsWith(TRIPLE_SLASH_SUFFIX) &&\n trimmed.indexOf(\">\") === trimmed.length - 1\n );\n}\n\n/**\n * Tells whether a JavaScript or TypeScript comment's text is a bare tool directive.\n *\n * @param text - The comment text without its delimiters.\n * @param isLine - Whether the comment is a `//` line comment, the only form a triple-slash\n * reference takes.\n * @returns `true` when the text is a bare ESLint, TypeScript or triple-slash directive.\n */\nexport function isBareScriptDirective(text: string, isLine: boolean): boolean {\n const trimmed = text.trim();\n if (isLine && isTripleSlashReference(trimmed)) {\n return true;\n }\n return (\n trimmed === TS_EXPECT_ERROR ||\n isBareEslintDirective(trimmed)\n );\n}\n","/**\n * The `css-no-comments` rule: stylesheets carry no comments but bare ESLint directives.\n *\n * @packageDocumentation\n */\nimport type { CSSRuleDefinition } from \"@eslint/css\";\n\nimport { isBareEslintDirective } from \"./directives.js\";\n\n/**\n * The `css-no-comments` rule type.\n */\nexport type CssNoCommentsRule = CSSRuleDefinition<{\n RuleOptions: [];\n MessageIds: \"comment\";\n}>;\n\n/**\n * `css-no-comments`: flags every stylesheet comment except a bare ESLint directive.\n */\nexport const cssNoCommentsRule: CssNoCommentsRule = {\n meta: {\n type: \"problem\",\n docs: {\n description:\n \"Disallow stylesheet comments other than bare ESLint directives (principle 10).\",\n },\n messages: {\n comment:\n \"Principle 10: delete this comment, or move its rationale into the JSDoc of the component that sets the selector.\",\n },\n schema: [],\n },\n create(context) {\n return {\n StyleSheet() {\n for (const comment of context.sourceCode.comments ?? []) {\n if (comment.loc && !isBareEslintDirective(comment.value)) {\n context.report({ loc: comment.loc, messageId: \"comment\" });\n }\n }\n },\n };\n },\n};\n","/**\n * The `no-comments` rule: JavaScript and TypeScript files carry no comments but JSDoc and bare\n * tool directives.\n *\n * @packageDocumentation\n */\nimport type { AST, Rule, SourceCode } from \"eslint\";\n\nimport { isBareScriptDirective } from \"./directives.js\";\n\n/**\n * Tells whether a comment is one principle 10 keeps.\n *\n * @param comment - The comment to classify.\n * @param sourceCode - The source the comment belongs to.\n * @returns `true` for a JSDoc block, a line-1 shebang or a bare tool directive.\n */\nfunction isPermittedComment(\n comment: AST.Program[\"comments\"][number],\n sourceCode: SourceCode,\n): boolean {\n const isJsdoc = comment.type === \"Block\" && comment.value.startsWith(\"*\");\n const isShebang =\n comment.range?.[0] === 0 && sourceCode.text.startsWith(\"#!\");\n return (\n isJsdoc ||\n isShebang ||\n isBareScriptDirective(comment.value, comment.type === \"Line\")\n );\n}\n\n/**\n * `no-comments`: flags every comment except a JSDoc block (`/** ... *\\/`), a line-1 shebang and a\n * bare tool directive (`eslint-disable`, `eslint-enable`, `eslint`, `global`,\n * `globals`, `exported`, `@ts-expect-error`, `/// <reference ... />`).\n */\nexport const noCommentsRule: Rule.RuleModule = {\n meta: {\n type: \"problem\",\n docs: {\n description:\n \"Disallow comments other than JSDoc and bare tool directives (principle 10).\",\n },\n messages: {\n comment:\n \"Principle 10: delete this comment, or move its rationale into the owning JSDoc. Tool directives stay bare, with no `-- description`.\",\n },\n schema: [],\n },\n create(context) {\n const { sourceCode } = context;\n return {\n Program() {\n for (const comment of sourceCode.getAllComments()) {\n if (comment.loc && !isPermittedComment(comment, sourceCode)) {\n context.report({ loc: comment.loc, messageId: \"comment\" });\n }\n }\n },\n };\n },\n};\n","/**\n * The `pragmatiks-comments` ESLint plugin, shared by the base and CSS configs.\n *\n * Note: flat config refuses two different objects under one plugin name, so every config\n * registers this one object, under a name distinct from the `/next` frontend plugin.\n *\n * @packageDocumentation\n */\nimport type { ESLint, Rule } from \"eslint\";\n\nimport { cssNoCommentsRule } from \"./css-no-comments.js\";\nimport { noCommentsRule } from \"./no-comments.js\";\n\n/**\n * The plugin name the comment rules are registered under.\n */\nexport const COMMENTS_PLUGIN_NAME = \"pragmatiks-comments\";\n\n/**\n * The plugin holding `no-comments` and `css-no-comments`.\n */\nexport const commentsPlugin: ESLint.Plugin = {\n meta: { name: \"@pragmatiks/lint/comments\" },\n rules: {\n \"no-comments\": noCommentsRule,\n \"css-no-comments\": cssNoCommentsRule as unknown as Rule.RuleModule,\n },\n};\n","/**\n * The `@pragmatiks/lint/eslint-config/css` entry: the flat config for stylesheets.\n *\n * @packageDocumentation\n */\nimport css from \"@eslint/css\";\nimport type { ESLint, Linter } from \"eslint\";\n\nimport { COMMENTS_PLUGIN_NAME, commentsPlugin } from \"../rules/plugin.js\";\n\n/**\n * The files the stylesheet config applies to.\n */\nexport const PRAGMATIKS_CSS_FILES = [\"**/*.css\"];\n\n/**\n * Builds the Pragmatiks flat config object for CSS files.\n *\n * Note: requires the optional peer `@eslint/css`.\n *\n * @returns The config object: `@eslint/css` parsing tolerantly, with `css-no-comments` on.\n */\nexport function pragmatiksCssConfig(): Linter.Config {\n return {\n name: \"pragmatiks/css\",\n files: PRAGMATIKS_CSS_FILES,\n plugins: {\n css: css as unknown as ESLint.Plugin,\n [COMMENTS_PLUGIN_NAME]: commentsPlugin,\n },\n language: \"css/css\",\n languageOptions: { tolerant: true },\n rules: { [`${COMMENTS_PLUGIN_NAME}/css-no-comments`]: \"error\" },\n };\n}\n\nexport default pragmatiksCssConfig;\n"]}
@@ -26,8 +26,12 @@ declare function semgrepRulesDirectory(): string;
26
26
  * applies only to `PRAGMATIKS_LINT_FILES`, so the config composes with configs for other
27
27
  * languages such as CSS.
28
28
  *
29
+ * Note: `@typescript-eslint/ban-ts-comment` allows a bare `@ts-expect-error`, since
30
+ * `no-comments` refuses a directive with a description; the plugin is the `typescript-eslint`
31
+ * instance `eslint-config-next` registers, so the two compose.
32
+ *
29
33
  * @returns The flat config: the typescript-eslint parser, the sonarjs and unicorn recommended
30
- * presets, the Pragmatiks size and naming rules, and global ignores for build output.
34
+ * presets, the Pragmatiks size, naming and comment rules, and global ignores for build output.
31
35
  * @throws Error when the package root cannot be found, or when sonarjs or unicorn has no
32
36
  * recommended flat config.
33
37
  */
@@ -48,6 +48,104 @@ var PREVENT_ABBREVIATIONS_OPTS = {
48
48
  }
49
49
  };
50
50
 
51
+ // src/eslint-config/rules/directives.ts
52
+ var RULE_LIST = String.raw`[\w@/.-]+(?:\s*,\s*[\w@/.-]+)*`;
53
+ var NAME_LIST = String.raw`[\w$:-]+(?:[\s,]+[\w$:-]+)*`;
54
+ var TRIPLE_SLASH_PREFIX = "/ <reference ";
55
+ var TRIPLE_SLASH_SUFFIX = "/>";
56
+ var DESCRIPTION_SEPARATOR = "--";
57
+ var TS_EXPECT_ERROR = "@ts-expect-error";
58
+ var ESLINT_DIRECTIVES = [
59
+ new RegExp(
60
+ String.raw`^eslint-(?:disable(?:-next-line|-line)?|enable)(?:\s+${RULE_LIST})?$`
61
+ ),
62
+ new RegExp(String.raw`^(?:globals?|exported)\s+${NAME_LIST}$`),
63
+ /^eslint\s+\S[\s\S]*$/
64
+ ];
65
+ function isBareEslintDirective(text) {
66
+ const trimmed = text.trim();
67
+ if (trimmed.includes(DESCRIPTION_SEPARATOR)) {
68
+ return false;
69
+ }
70
+ return ESLINT_DIRECTIVES.some((pattern) => pattern.test(trimmed));
71
+ }
72
+ function isTripleSlashReference(trimmed) {
73
+ return trimmed.startsWith(TRIPLE_SLASH_PREFIX) && trimmed.endsWith(TRIPLE_SLASH_SUFFIX) && trimmed.indexOf(">") === trimmed.length - 1;
74
+ }
75
+ function isBareScriptDirective(text, isLine) {
76
+ const trimmed = text.trim();
77
+ if (isLine && isTripleSlashReference(trimmed)) {
78
+ return true;
79
+ }
80
+ return trimmed === TS_EXPECT_ERROR || isBareEslintDirective(trimmed);
81
+ }
82
+
83
+ // src/eslint-config/rules/css-no-comments.ts
84
+ var cssNoCommentsRule = {
85
+ meta: {
86
+ type: "problem",
87
+ docs: {
88
+ description: "Disallow stylesheet comments other than bare ESLint directives (principle 10)."
89
+ },
90
+ messages: {
91
+ comment: "Principle 10: delete this comment, or move its rationale into the JSDoc of the component that sets the selector."
92
+ },
93
+ schema: []
94
+ },
95
+ create(context) {
96
+ return {
97
+ StyleSheet() {
98
+ for (const comment of context.sourceCode.comments ?? []) {
99
+ if (comment.loc && !isBareEslintDirective(comment.value)) {
100
+ context.report({ loc: comment.loc, messageId: "comment" });
101
+ }
102
+ }
103
+ }
104
+ };
105
+ }
106
+ };
107
+
108
+ // src/eslint-config/rules/no-comments.ts
109
+ function isPermittedComment(comment, sourceCode) {
110
+ const isJsdoc = comment.type === "Block" && comment.value.startsWith("*");
111
+ const isShebang = comment.range?.[0] === 0 && sourceCode.text.startsWith("#!");
112
+ return isJsdoc || isShebang || isBareScriptDirective(comment.value, comment.type === "Line");
113
+ }
114
+ var noCommentsRule = {
115
+ meta: {
116
+ type: "problem",
117
+ docs: {
118
+ description: "Disallow comments other than JSDoc and bare tool directives (principle 10)."
119
+ },
120
+ messages: {
121
+ comment: "Principle 10: delete this comment, or move its rationale into the owning JSDoc. Tool directives stay bare, with no `-- description`."
122
+ },
123
+ schema: []
124
+ },
125
+ create(context) {
126
+ const { sourceCode } = context;
127
+ return {
128
+ Program() {
129
+ for (const comment of sourceCode.getAllComments()) {
130
+ if (comment.loc && !isPermittedComment(comment, sourceCode)) {
131
+ context.report({ loc: comment.loc, messageId: "comment" });
132
+ }
133
+ }
134
+ }
135
+ };
136
+ }
137
+ };
138
+
139
+ // src/eslint-config/rules/plugin.ts
140
+ var COMMENTS_PLUGIN_NAME = "pragmatiks-comments";
141
+ var commentsPlugin = {
142
+ meta: { name: "@pragmatiks/lint/comments" },
143
+ rules: {
144
+ "no-comments": noCommentsRule,
145
+ "css-no-comments": cssNoCommentsRule
146
+ }
147
+ };
148
+
51
149
  // src/eslint-config/index.ts
52
150
  var PRAGMATIKS_LINT_FILES = ["**/*.{js,jsx,mjs,cjs,ts,tsx,mts,cts}"];
53
151
  function findPackageRoot(start) {
@@ -103,7 +201,16 @@ function pragmatiksConfig() {
103
201
  }),
104
202
  {
105
203
  files: PRAGMATIKS_LINT_FILES,
204
+ plugins: {
205
+ "@typescript-eslint": tseslint.plugin,
206
+ [COMMENTS_PLUGIN_NAME]: commentsPlugin
207
+ },
106
208
  rules: {
209
+ [`${COMMENTS_PLUGIN_NAME}/no-comments`]: "error",
210
+ "@typescript-eslint/ban-ts-comment": [
211
+ "error",
212
+ { "ts-expect-error": false }
213
+ ],
107
214
  complexity: ["error", COMPLEXITY_OPTS],
108
215
  "max-lines-per-function": ["error", MAX_LINES_PER_FUNCTION_OPTS],
109
216
  "max-statements": ["error", MAX_STATEMENTS_OPTS],
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/eslint-config/options.ts","../../src/eslint-config/index.ts"],"names":[],"mappings":";;;;;;;;;;;AAAO,IAAM,eAAA,GAAkB,EAAA;AAExB,IAAM,2BAAA,GAA8B;AAAA,EACzC,GAAA,EAAK,EAAA;AAAA,EAC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AAO;AAAA,KACR,CAAA;AAAA,IACD,mBAAmB,OAAA,EAAS;AAAA,MAC1B,IAAA,EAAM,uBAAA;AAAA,MACN,KAAA,EAAO;AAAA,KACR,CAAA;AAAA,IACD;AAAA,MACE,KAAA,EAAO,qBAAA;AAAA,MACP,KAAA,EAAO;AAAA,QACL,UAAA,EAAY,CAAC,OAAA,EAAS,eAAe,CAAA;AAAA,QACrC,wBAAA,EAA0B,CAAC,OAAA,EAAS,2BAA2B,CAAA;AAAA,QAC/D,gBAAA,EAAkB,CAAC,OAAA,EAAS,mBAAmB,CAAA;AAAA,QAC/C,WAAA,EAAa,CAAC,OAAA,EAAS,cAAc,CAAA;AAAA,QACrC,YAAA,EAAc,CAAC,OAAA,EAAS,eAAe,CAAA;AAAA,QACvC,+BAAA,EAAiC,CAAC,OAAA,EAAS,0BAA0B;AAAA;AACvE,KACF;AAAA,IACA,cAAc,CAAC,SAAA,EAAW,iBAAA,EAAmB,UAAA,EAAY,WAAW,CAAC;AAAA,GACtE,CAAA;AACH;AAEA,IAAO,qBAAA,GAAQ","file":"index.js","sourcesContent":["export const COMPLEXITY_OPTS = 10;\n\nexport const MAX_LINES_PER_FUNCTION_OPTS = {\n max: 50,\n skipBlankLines: true,\n skipComments: true,\n};\n\nexport const MAX_STATEMENTS_OPTS = 15;\n\nexport const MAX_DEPTH_OPTS = 4;\n\nexport const MAX_PARAMS_OPTS = 4;\n\nexport const PREVENT_ABBREVIATIONS_OPTS = {\n allowList: {\n id: true,\n url: true,\n uri: true,\n api: true,\n cli: true,\n sdk: true,\n os: true,\n io: true,\n ip: true,\n tls: true,\n ssl: true,\n jwt: true,\n json: true,\n yaml: true,\n html: true,\n css: true,\n dom: true,\n ast: true,\n gpu: true,\n cpu: true,\n ram: true,\n vm: true,\n props: true,\n ref: true,\n e: true,\n },\n};\n\n/**\n * `unicorn/filename-case` options for Next apps: kebab-case modules, PascalCase components and\n * camelCase hooks and utilities are all allowed.\n */\nexport const FILENAME_CASE_OPTIONS = {\n cases: {\n kebabCase: true,\n pascalCase: true,\n camelCase: true,\n },\n};\n\n/**\n * `unicorn/no-useless-undefined` options for React: explicit resets such as\n * `setState(undefined)` are meaningful arguments, so arguments are not checked.\n */\nexport const NO_USELESS_UNDEFINED_OPTIONS = { checkArguments: false };\n","import { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nimport { type Config, defineConfig, globalIgnores } from \"eslint/config\";\nimport sonarjs from \"eslint-plugin-sonarjs\";\nimport unicorn from \"eslint-plugin-unicorn\";\nimport tseslint from \"typescript-eslint\";\n\nimport {\n COMPLEXITY_OPTS,\n MAX_DEPTH_OPTS,\n MAX_LINES_PER_FUNCTION_OPTS,\n MAX_PARAMS_OPTS,\n MAX_STATEMENTS_OPTS,\n PREVENT_ABBREVIATIONS_OPTS,\n} from \"./options.js\";\n\n/**\n * The files every Pragmatiks config object applies to: JavaScript and TypeScript, JSX included.\n */\nexport const PRAGMATIKS_LINT_FILES = [\"**/*.{js,jsx,mjs,cjs,ts,tsx,mts,cts}\"];\n\n/**\n * Finds the nearest directory at or above `start` that contains a `package.json`.\n *\n * @param start - The directory to start from.\n * @returns The first directory, walking up, that contains a `package.json`.\n * @throws Error when no directory up to the filesystem root contains one.\n */\nexport function findPackageRoot(start: string): string {\n let current = start;\n for (;;) {\n if (existsSync(path.join(current, \"package.json\"))) {\n return current;\n }\n const parent = path.dirname(current);\n if (parent === current) {\n throw new Error(`package.json not found above ${start}`);\n }\n current = parent;\n }\n}\n\n/**\n * Locates the Semgrep rules shipped with this package.\n *\n * @returns The absolute path of the package's `src/semgrep-rules` directory.\n * @throws Error when the package root cannot be found above this module.\n */\nexport function semgrepRulesDirectory(): string {\n const here = path.dirname(fileURLToPath(import.meta.url));\n return path.join(findPackageRoot(here), \"src\", \"semgrep-rules\");\n}\n\n/**\n * Reads a plugin's recommended flat config and scopes it to `PRAGMATIKS_LINT_FILES`.\n *\n * @param plugin - An ESLint plugin that ships flat configs.\n * @param peer - The plugin's package name and the peer range this package supports, used in the\n * error message.\n * @returns The recommended config with its `files` replaced by `PRAGMATIKS_LINT_FILES`, so it never\n * applies to CSS or other languages composed alongside it.\n * @throws Error when the plugin has no `recommended` flat config, which means an unsupported major.\n */\nfunction recommendedOrThrow(\n plugin: { configs?: Record<string, unknown> },\n peer: { name: string; range: string },\n): Config {\n const recommended = plugin.configs?.recommended;\n if (!recommended) {\n throw new Error(\n `@pragmatiks/lint: ${peer.name} has no recommended flat-config preset (peer dependency major mismatch). To fix it, install ${peer.name} ${peer.range}.`,\n );\n }\n return { ...(recommended as Config), files: PRAGMATIKS_LINT_FILES };\n}\n\n/**\n * Builds the Pragmatiks base flat config for JavaScript and TypeScript files.\n *\n * Every object except the global ignores, the sonarjs and unicorn recommended presets included,\n * applies only to `PRAGMATIKS_LINT_FILES`, so the config composes with configs for other\n * languages such as CSS.\n *\n * @returns The flat config: the typescript-eslint parser, the sonarjs and unicorn recommended\n * presets, the Pragmatiks size and naming rules, and global ignores for build output.\n * @throws Error when the package root cannot be found, or when sonarjs or unicorn has no\n * recommended flat config.\n */\nexport function pragmatiksConfig() {\n return defineConfig([\n {\n files: PRAGMATIKS_LINT_FILES,\n languageOptions: {\n parser: tseslint.parser,\n parserOptions: {\n ecmaVersion: \"latest\",\n sourceType: \"module\",\n },\n },\n settings: {\n pragmatiksLint: {\n semgrepRulesDirectory: semgrepRulesDirectory(),\n },\n },\n },\n recommendedOrThrow(sonarjs, {\n name: \"eslint-plugin-sonarjs\",\n range: \"^4.0.0\",\n }),\n recommendedOrThrow(unicorn, {\n name: \"eslint-plugin-unicorn\",\n range: \"^64.0.0\",\n }),\n {\n files: PRAGMATIKS_LINT_FILES,\n rules: {\n complexity: [\"error\", COMPLEXITY_OPTS],\n \"max-lines-per-function\": [\"error\", MAX_LINES_PER_FUNCTION_OPTS],\n \"max-statements\": [\"error\", MAX_STATEMENTS_OPTS],\n \"max-depth\": [\"error\", MAX_DEPTH_OPTS],\n \"max-params\": [\"error\", MAX_PARAMS_OPTS],\n \"unicorn/prevent-abbreviations\": [\"error\", PREVENT_ABBREVIATIONS_OPTS],\n },\n },\n globalIgnores([\"dist/**\", \"node_modules/**\", \".next/**\", \".turbo/**\"]),\n ]);\n}\n\nexport default pragmatiksConfig;\n"]}
1
+ {"version":3,"sources":["../../src/eslint-config/options.ts","../../src/eslint-config/rules/directives.ts","../../src/eslint-config/rules/css-no-comments.ts","../../src/eslint-config/rules/no-comments.ts","../../src/eslint-config/rules/plugin.ts","../../src/eslint-config/index.ts"],"names":[],"mappings":";;;;;;;;;;;AAAO,IAAM,eAAA,GAAkB,EAAA;AAExB,IAAM,2BAAA,GAA8B;AAAA,EACzC,GAAA,EAAK,EAAA;AAAA,EACL,cAAA,EAAgB,IAAA;AAAA,EAChB,YAAA,EAAc;AAChB,CAAA;AAEO,IAAM,mBAAA,GAAsB,EAAA;AAE5B,IAAM,cAAA,GAAiB,CAAA;AAEvB,IAAM,eAAA,GAAkB,CAAA;AAExB,IAAM,0BAAA,GAA6B;AAAA,EACxC,SAAA,EAAW;AAAA,IACT,EAAA,EAAI,IAAA;AAAA,IACJ,GAAA,EAAK,IAAA;AAAA,IACL,GAAA,EAAK,IAAA;AAAA,IACL,GAAA,EAAK,IAAA;AAAA,IACL,GAAA,EAAK,IAAA;AAAA,IACL,GAAA,EAAK,IAAA;AAAA,IACL,EAAA,EAAI,IAAA;AAAA,IACJ,EAAA,EAAI,IAAA;AAAA,IACJ,EAAA,EAAI,IAAA;AAAA,IACJ,GAAA,EAAK,IAAA;AAAA,IACL,GAAA,EAAK,IAAA;AAAA,IACL,GAAA,EAAK,IAAA;AAAA,IACL,IAAA,EAAM,IAAA;AAAA,IACN,IAAA,EAAM,IAAA;AAAA,IACN,IAAA,EAAM,IAAA;AAAA,IACN,GAAA,EAAK,IAAA;AAAA,IACL,GAAA,EAAK,IAAA;AAAA,IACL,GAAA,EAAK,IAAA;AAAA,IACL,GAAA,EAAK,IAAA;AAAA,IACL,GA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A,KACR,CAAA;AAAA,IACD;AAAA,MACE,KAAA,EAAO,qBAAA;AAAA,MACP,OAAA,EAAS;AAAA,QACP,sBAAsB,QAAA,CAAS,MAAA;AAAA,QAC/B,CAAC,oBAAoB,GAAG;AAAA,OAC1B;AAAA,MACA,KAAA,EAAO;AAAA,QACL,CAAC,CAAA,EAAG,oBAAoB,CAAA,YAAA,CAAc,GAAG,OAAA;AAAA,QACzC,mCAAA,EAAqC;AAAA,UACnC,OAAA;AAAA,UACA,EAAE,mBAAmB,KAAA;AAAM,SAC7B;AAAA,QACA,UAAA,EAAY,CAAC,OAAA,EAAS,eAAe,CAAA;AAAA,QACrC,wBAAA,EAA0B,CAAC,OAAA,EAAS,2BAA2B,CAAA;AAAA,QAC/D,gBAAA,EAAkB,CAAC,OAAA,EAAS,mBAAmB,CAAA;AAAA,QAC/C,WAAA,EAAa,CAAC,OAAA,EAAS,cAAc,CAAA;AAAA,QACrC,YAAA,EAAc,CAAC,OAAA,EAAS,eAAe,CAAA;AAAA,QACvC,+BAAA,EAAiC,CAAC,OAAA,EAAS,0BAA0B;AAAA;AACvE,KACF;AAAA,IACA,cAAc,CAAC,SAAA,EAAW,iBAAA,EAAmB,UAAA,EAAY,WAAW,CAAC;AAAA,GACtE,CAAA;AACH;AAEA,IAAO,qBAAA,GAAQ","file":"index.js","sourcesContent":["export const COMPLEXITY_OPTS = 10;\n\nexport const MAX_LINES_PER_FUNCTION_OPTS = {\n max: 50,\n skipBlankLines: true,\n skipComments: true,\n};\n\nexport const MAX_STATEMENTS_OPTS = 15;\n\nexport const MAX_DEPTH_OPTS = 4;\n\nexport const MAX_PARAMS_OPTS = 4;\n\nexport const PREVENT_ABBREVIATIONS_OPTS = {\n allowList: {\n id: true,\n url: true,\n uri: true,\n api: true,\n cli: true,\n sdk: true,\n os: true,\n io: true,\n ip: true,\n tls: true,\n ssl: true,\n jwt: true,\n json: true,\n yaml: true,\n html: true,\n css: true,\n dom: true,\n ast: true,\n gpu: true,\n cpu: true,\n ram: true,\n vm: true,\n props: true,\n ref: true,\n e: true,\n },\n};\n\n/**\n * `unicorn/filename-case` options for Next apps: kebab-case modules, PascalCase components and\n * camelCase hooks and utilities are all allowed.\n */\nexport const FILENAME_CASE_OPTIONS = {\n cases: {\n kebabCase: true,\n pascalCase: true,\n camelCase: true,\n },\n};\n\n/**\n * `unicorn/no-useless-undefined` options for React: explicit resets such as\n * `setState(undefined)` are meaningful arguments, so arguments are not checked.\n */\nexport const NO_USELESS_UNDEFINED_OPTIONS = { checkArguments: false };\n","/**\n * Recognizes bare tool directives, the only comments principle 10 keeps.\n *\n * @packageDocumentation\n */\n\n/**\n * A comma-separated list of rule names an ESLint directive may carry.\n */\nconst RULE_LIST = String.raw`[\\w@/.-]+(?:\\s*,\\s*[\\w@/.-]+)*`;\n\n/**\n * A list of global or exported names a `global(s)` or `exported` directive may carry.\n */\nconst NAME_LIST = String.raw`[\\w$:-]+(?:[\\s,]+[\\w$:-]+)*`;\n\n/**\n * The opening of a triple-slash reference after its `//`.\n */\nconst TRIPLE_SLASH_PREFIX = \"/ <reference \";\n\n/**\n * The closing of a triple-slash reference.\n */\nconst TRIPLE_SLASH_SUFFIX = \"/>\";\n\n/**\n * The separator that starts a directive's description.\n */\nconst DESCRIPTION_SEPARATOR = \"--\";\n\n/**\n * The TypeScript directive kept in a JavaScript or TypeScript comment.\n */\nconst TS_EXPECT_ERROR = \"@ts-expect-error\";\n\n/**\n * Directives ESLint reads from any comment, each matched against the whole trimmed comment text.\n */\nconst ESLINT_DIRECTIVES: readonly RegExp[] = [\n new RegExp(\n String.raw`^eslint-(?:disable(?:-next-line|-line)?|enable)(?:\\s+${RULE_LIST})?$`,\n ),\n new RegExp(String.raw`^(?:globals?|exported)\\s+${NAME_LIST}$`),\n /^eslint\\s+\\S[\\s\\S]*$/,\n];\n\n/**\n * Tells whether a comment's text is a bare ESLint directive.\n *\n * Note: a directive carrying a `-- description` is not bare; its rationale belongs in the owning\n * docstring.\n *\n * @param text - The comment text without its delimiters.\n * @returns `true` when the text is an ESLint directive with no description.\n */\nexport function isBareEslintDirective(text: string): boolean {\n const trimmed = text.trim();\n if (trimmed.includes(DESCRIPTION_SEPARATOR)) {\n return false;\n }\n return ESLINT_DIRECTIVES.some((pattern) => pattern.test(trimmed));\n}\n\n/**\n * Tells whether a line comment's trimmed text is a triple-slash reference.\n *\n * @param trimmed - The trimmed text after `//`.\n * @returns `true` for `/ <reference ... />` holding no other `>`.\n */\nfunction isTripleSlashReference(trimmed: string): boolean {\n return (\n trimmed.startsWith(TRIPLE_SLASH_PREFIX) &&\n trimmed.endsWith(TRIPLE_SLASH_SUFFIX) &&\n trimmed.indexOf(\">\") === trimmed.length - 1\n );\n}\n\n/**\n * Tells whether a JavaScript or TypeScript comment's text is a bare tool directive.\n *\n * @param text - The comment text without its delimiters.\n * @param isLine - Whether the comment is a `//` line comment, the only form a triple-slash\n * reference takes.\n * @returns `true` when the text is a bare ESLint, TypeScript or triple-slash directive.\n */\nexport function isBareScriptDirective(text: string, isLine: boolean): boolean {\n const trimmed = text.trim();\n if (isLine && isTripleSlashReference(trimmed)) {\n return true;\n }\n return (\n trimmed === TS_EXPECT_ERROR ||\n isBareEslintDirective(trimmed)\n );\n}\n","/**\n * The `css-no-comments` rule: stylesheets carry no comments but bare ESLint directives.\n *\n * @packageDocumentation\n */\nimport type { CSSRuleDefinition } from \"@eslint/css\";\n\nimport { isBareEslintDirective } from \"./directives.js\";\n\n/**\n * The `css-no-comments` rule type.\n */\nexport type CssNoCommentsRule = CSSRuleDefinition<{\n RuleOptions: [];\n MessageIds: \"comment\";\n}>;\n\n/**\n * `css-no-comments`: flags every stylesheet comment except a bare ESLint directive.\n */\nexport const cssNoCommentsRule: CssNoCommentsRule = {\n meta: {\n type: \"problem\",\n docs: {\n description:\n \"Disallow stylesheet comments other than bare ESLint directives (principle 10).\",\n },\n messages: {\n comment:\n \"Principle 10: delete this comment, or move its rationale into the JSDoc of the component that sets the selector.\",\n },\n schema: [],\n },\n create(context) {\n return {\n StyleSheet() {\n for (const comment of context.sourceCode.comments ?? []) {\n if (comment.loc && !isBareEslintDirective(comment.value)) {\n context.report({ loc: comment.loc, messageId: \"comment\" });\n }\n }\n },\n };\n },\n};\n","/**\n * The `no-comments` rule: JavaScript and TypeScript files carry no comments but JSDoc and bare\n * tool directives.\n *\n * @packageDocumentation\n */\nimport type { AST, Rule, SourceCode } from \"eslint\";\n\nimport { isBareScriptDirective } from \"./directives.js\";\n\n/**\n * Tells whether a comment is one principle 10 keeps.\n *\n * @param comment - The comment to classify.\n * @param sourceCode - The source the comment belongs to.\n * @returns `true` for a JSDoc block, a line-1 shebang or a bare tool directive.\n */\nfunction isPermittedComment(\n comment: AST.Program[\"comments\"][number],\n sourceCode: SourceCode,\n): boolean {\n const isJsdoc = comment.type === \"Block\" && comment.value.startsWith(\"*\");\n const isShebang =\n comment.range?.[0] === 0 && sourceCode.text.startsWith(\"#!\");\n return (\n isJsdoc ||\n isShebang ||\n isBareScriptDirective(comment.value, comment.type === \"Line\")\n );\n}\n\n/**\n * `no-comments`: flags every comment except a JSDoc block (`/** ... *\\/`), a line-1 shebang and a\n * bare tool directive (`eslint-disable`, `eslint-enable`, `eslint`, `global`,\n * `globals`, `exported`, `@ts-expect-error`, `/// <reference ... />`).\n */\nexport const noCommentsRule: Rule.RuleModule = {\n meta: {\n type: \"problem\",\n docs: {\n description:\n \"Disallow comments other than JSDoc and bare tool directives (principle 10).\",\n },\n messages: {\n comment:\n \"Principle 10: delete this comment, or move its rationale into the owning JSDoc. Tool directives stay bare, with no `-- description`.\",\n },\n schema: [],\n },\n create(context) {\n const { sourceCode } = context;\n return {\n Program() {\n for (const comment of sourceCode.getAllComments()) {\n if (comment.loc && !isPermittedComment(comment, sourceCode)) {\n context.report({ loc: comment.loc, messageId: \"comment\" });\n }\n }\n },\n };\n },\n};\n","/**\n * The `pragmatiks-comments` ESLint plugin, shared by the base and CSS configs.\n *\n * Note: flat config refuses two different objects under one plugin name, so every config\n * registers this one object, under a name distinct from the `/next` frontend plugin.\n *\n * @packageDocumentation\n */\nimport type { ESLint, Rule } from \"eslint\";\n\nimport { cssNoCommentsRule } from \"./css-no-comments.js\";\nimport { noCommentsRule } from \"./no-comments.js\";\n\n/**\n * The plugin name the comment rules are registered under.\n */\nexport const COMMENTS_PLUGIN_NAME = \"pragmatiks-comments\";\n\n/**\n * The plugin holding `no-comments` and `css-no-comments`.\n */\nexport const commentsPlugin: ESLint.Plugin = {\n meta: { name: \"@pragmatiks/lint/comments\" },\n rules: {\n \"no-comments\": noCommentsRule,\n \"css-no-comments\": cssNoCommentsRule as unknown as Rule.RuleModule,\n },\n};\n","import { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nimport { type Config, defineConfig, globalIgnores } from \"eslint/config\";\nimport sonarjs from \"eslint-plugin-sonarjs\";\nimport unicorn from \"eslint-plugin-unicorn\";\nimport tseslint from \"typescript-eslint\";\n\nimport {\n COMPLEXITY_OPTS,\n MAX_DEPTH_OPTS,\n MAX_LINES_PER_FUNCTION_OPTS,\n MAX_PARAMS_OPTS,\n MAX_STATEMENTS_OPTS,\n PREVENT_ABBREVIATIONS_OPTS,\n} from \"./options.js\";\nimport { COMMENTS_PLUGIN_NAME, commentsPlugin } from \"./rules/plugin.js\";\n\n/**\n * The files every Pragmatiks config object applies to: JavaScript and TypeScript, JSX included.\n */\nexport const PRAGMATIKS_LINT_FILES = [\"**/*.{js,jsx,mjs,cjs,ts,tsx,mts,cts}\"];\n\n/**\n * Finds the nearest directory at or above `start` that contains a `package.json`.\n *\n * @param start - The directory to start from.\n * @returns The first directory, walking up, that contains a `package.json`.\n * @throws Error when no directory up to the filesystem root contains one.\n */\nexport function findPackageRoot(start: string): string {\n let current = start;\n for (;;) {\n if (existsSync(path.join(current, \"package.json\"))) {\n return current;\n }\n const parent = path.dirname(current);\n if (parent === current) {\n throw new Error(`package.json not found above ${start}`);\n }\n current = parent;\n }\n}\n\n/**\n * Locates the Semgrep rules shipped with this package.\n *\n * @returns The absolute path of the package's `src/semgrep-rules` directory.\n * @throws Error when the package root cannot be found above this module.\n */\nexport function semgrepRulesDirectory(): string {\n const here = path.dirname(fileURLToPath(import.meta.url));\n return path.join(findPackageRoot(here), \"src\", \"semgrep-rules\");\n}\n\n/**\n * Reads a plugin's recommended flat config and scopes it to `PRAGMATIKS_LINT_FILES`.\n *\n * @param plugin - An ESLint plugin that ships flat configs.\n * @param peer - The plugin's package name and the peer range this package supports, used in the\n * error message.\n * @returns The recommended config with its `files` replaced by `PRAGMATIKS_LINT_FILES`, so it never\n * applies to CSS or other languages composed alongside it.\n * @throws Error when the plugin has no `recommended` flat config, which means an unsupported major.\n */\nfunction recommendedOrThrow(\n plugin: { configs?: Record<string, unknown> },\n peer: { name: string; range: string },\n): Config {\n const recommended = plugin.configs?.recommended;\n if (!recommended) {\n throw new Error(\n `@pragmatiks/lint: ${peer.name} has no recommended flat-config preset (peer dependency major mismatch). To fix it, install ${peer.name} ${peer.range}.`,\n );\n }\n return { ...(recommended as Config), files: PRAGMATIKS_LINT_FILES };\n}\n\n/**\n * Builds the Pragmatiks base flat config for JavaScript and TypeScript files.\n *\n * Every object except the global ignores, the sonarjs and unicorn recommended presets included,\n * applies only to `PRAGMATIKS_LINT_FILES`, so the config composes with configs for other\n * languages such as CSS.\n *\n * Note: `@typescript-eslint/ban-ts-comment` allows a bare `@ts-expect-error`, since\n * `no-comments` refuses a directive with a description; the plugin is the `typescript-eslint`\n * instance `eslint-config-next` registers, so the two compose.\n *\n * @returns The flat config: the typescript-eslint parser, the sonarjs and unicorn recommended\n * presets, the Pragmatiks size, naming and comment rules, and global ignores for build output.\n * @throws Error when the package root cannot be found, or when sonarjs or unicorn has no\n * recommended flat config.\n */\nexport function pragmatiksConfig() {\n return defineConfig([\n {\n files: PRAGMATIKS_LINT_FILES,\n languageOptions: {\n parser: tseslint.parser,\n parserOptions: {\n ecmaVersion: \"latest\",\n sourceType: \"module\",\n },\n },\n settings: {\n pragmatiksLint: {\n semgrepRulesDirectory: semgrepRulesDirectory(),\n },\n },\n },\n recommendedOrThrow(sonarjs, {\n name: \"eslint-plugin-sonarjs\",\n range: \"^4.0.0\",\n }),\n recommendedOrThrow(unicorn, {\n name: \"eslint-plugin-unicorn\",\n range: \"^64.0.0\",\n }),\n {\n files: PRAGMATIKS_LINT_FILES,\n plugins: {\n \"@typescript-eslint\": tseslint.plugin,\n [COMMENTS_PLUGIN_NAME]: commentsPlugin,\n },\n rules: {\n [`${COMMENTS_PLUGIN_NAME}/no-comments`]: \"error\",\n \"@typescript-eslint/ban-ts-comment\": [\n \"error\",\n { \"ts-expect-error\": false },\n ],\n complexity: [\"error\", COMPLEXITY_OPTS],\n \"max-lines-per-function\": [\"error\", MAX_LINES_PER_FUNCTION_OPTS],\n \"max-statements\": [\"error\", MAX_STATEMENTS_OPTS],\n \"max-depth\": [\"error\", MAX_DEPTH_OPTS],\n \"max-params\": [\"error\", MAX_PARAMS_OPTS],\n \"unicorn/prevent-abbreviations\": [\"error\", PREVENT_ABBREVIATIONS_OPTS],\n },\n },\n globalIgnores([\"dist/**\", \"node_modules/**\", \".next/**\", \".turbo/**\"]),\n ]);\n}\n\nexport default pragmatiksConfig;\n"]}
@@ -21,7 +21,8 @@ interface PragmatiksNextOptions extends DesignSystemSource {
21
21
  }
22
22
  /**
23
23
  * Builds the flat config for a Next app: the Next presets, the Pragmatiks base config, the
24
- * frontend rules for JavaScript and TypeScript, a typed leaked-render check, and the CSS rules.
24
+ * frontend rules for JavaScript and TypeScript, a typed leaked-render check, the CSS rules and the
25
+ * stylesheet comment ban.
25
26
  *
26
27
  * Next config objects without `files` are scoped to the glob of the one object that registers
27
28
  * `jsx-a11y`; ignore-only objects are kept as they are. The base config's typescript-eslint parser
@@ -12,6 +12,120 @@ import { lexer, property, generate, toPlainObject, parse } from '@eslint/css-tre
12
12
 
13
13
  // src/eslint-config/next/index.ts
14
14
 
15
+ // src/eslint-config/rules/directives.ts
16
+ var RULE_LIST = String.raw`[\w@/.-]+(?:\s*,\s*[\w@/.-]+)*`;
17
+ var NAME_LIST = String.raw`[\w$:-]+(?:[\s,]+[\w$:-]+)*`;
18
+ var TRIPLE_SLASH_PREFIX = "/ <reference ";
19
+ var TRIPLE_SLASH_SUFFIX = "/>";
20
+ var DESCRIPTION_SEPARATOR = "--";
21
+ var TS_EXPECT_ERROR = "@ts-expect-error";
22
+ var ESLINT_DIRECTIVES = [
23
+ new RegExp(
24
+ String.raw`^eslint-(?:disable(?:-next-line|-line)?|enable)(?:\s+${RULE_LIST})?$`
25
+ ),
26
+ new RegExp(String.raw`^(?:globals?|exported)\s+${NAME_LIST}$`),
27
+ /^eslint\s+\S[\s\S]*$/
28
+ ];
29
+ function isBareEslintDirective(text) {
30
+ const trimmed = text.trim();
31
+ if (trimmed.includes(DESCRIPTION_SEPARATOR)) {
32
+ return false;
33
+ }
34
+ return ESLINT_DIRECTIVES.some((pattern) => pattern.test(trimmed));
35
+ }
36
+ function isTripleSlashReference(trimmed) {
37
+ return trimmed.startsWith(TRIPLE_SLASH_PREFIX) && trimmed.endsWith(TRIPLE_SLASH_SUFFIX) && trimmed.indexOf(">") === trimmed.length - 1;
38
+ }
39
+ function isBareScriptDirective(text, isLine) {
40
+ const trimmed = text.trim();
41
+ if (isLine && isTripleSlashReference(trimmed)) {
42
+ return true;
43
+ }
44
+ return trimmed === TS_EXPECT_ERROR || isBareEslintDirective(trimmed);
45
+ }
46
+
47
+ // src/eslint-config/rules/css-no-comments.ts
48
+ var cssNoCommentsRule = {
49
+ meta: {
50
+ type: "problem",
51
+ docs: {
52
+ description: "Disallow stylesheet comments other than bare ESLint directives (principle 10)."
53
+ },
54
+ messages: {
55
+ comment: "Principle 10: delete this comment, or move its rationale into the JSDoc of the component that sets the selector."
56
+ },
57
+ schema: []
58
+ },
59
+ create(context) {
60
+ return {
61
+ StyleSheet() {
62
+ for (const comment of context.sourceCode.comments ?? []) {
63
+ if (comment.loc && !isBareEslintDirective(comment.value)) {
64
+ context.report({ loc: comment.loc, messageId: "comment" });
65
+ }
66
+ }
67
+ }
68
+ };
69
+ }
70
+ };
71
+
72
+ // src/eslint-config/rules/no-comments.ts
73
+ function isPermittedComment(comment, sourceCode) {
74
+ const isJsdoc = comment.type === "Block" && comment.value.startsWith("*");
75
+ const isShebang = comment.range?.[0] === 0 && sourceCode.text.startsWith("#!");
76
+ return isJsdoc || isShebang || isBareScriptDirective(comment.value, comment.type === "Line");
77
+ }
78
+ var noCommentsRule = {
79
+ meta: {
80
+ type: "problem",
81
+ docs: {
82
+ description: "Disallow comments other than JSDoc and bare tool directives (principle 10)."
83
+ },
84
+ messages: {
85
+ comment: "Principle 10: delete this comment, or move its rationale into the owning JSDoc. Tool directives stay bare, with no `-- description`."
86
+ },
87
+ schema: []
88
+ },
89
+ create(context) {
90
+ const { sourceCode } = context;
91
+ return {
92
+ Program() {
93
+ for (const comment of sourceCode.getAllComments()) {
94
+ if (comment.loc && !isPermittedComment(comment, sourceCode)) {
95
+ context.report({ loc: comment.loc, messageId: "comment" });
96
+ }
97
+ }
98
+ }
99
+ };
100
+ }
101
+ };
102
+
103
+ // src/eslint-config/rules/plugin.ts
104
+ var COMMENTS_PLUGIN_NAME = "pragmatiks-comments";
105
+ var commentsPlugin = {
106
+ meta: { name: "@pragmatiks/lint/comments" },
107
+ rules: {
108
+ "no-comments": noCommentsRule,
109
+ "css-no-comments": cssNoCommentsRule
110
+ }
111
+ };
112
+
113
+ // src/eslint-config/css/index.ts
114
+ var PRAGMATIKS_CSS_FILES = ["**/*.css"];
115
+ function pragmatiksCssConfig() {
116
+ return {
117
+ name: "pragmatiks/css",
118
+ files: PRAGMATIKS_CSS_FILES,
119
+ plugins: {
120
+ css,
121
+ [COMMENTS_PLUGIN_NAME]: commentsPlugin
122
+ },
123
+ language: "css/css",
124
+ languageOptions: { tolerant: true },
125
+ rules: { [`${COMMENTS_PLUGIN_NAME}/css-no-comments`]: "error" }
126
+ };
127
+ }
128
+
15
129
  // src/eslint-config/options.ts
16
130
  var COMPLEXITY_OPTS = 10;
17
131
  var MAX_LINES_PER_FUNCTION_OPTS = {
@@ -115,7 +229,16 @@ function pragmatiksConfig() {
115
229
  }),
116
230
  {
117
231
  files: PRAGMATIKS_LINT_FILES,
232
+ plugins: {
233
+ "@typescript-eslint": tseslint.plugin,
234
+ [COMMENTS_PLUGIN_NAME]: commentsPlugin
235
+ },
118
236
  rules: {
237
+ [`${COMMENTS_PLUGIN_NAME}/no-comments`]: "error",
238
+ "@typescript-eslint/ban-ts-comment": [
239
+ "error",
240
+ { "ts-expect-error": false }
241
+ ],
119
242
  complexity: ["error", COMPLEXITY_OPTS],
120
243
  "max-lines-per-function": ["error", MAX_LINES_PER_FUNCTION_OPTS],
121
244
  "max-statements": ["error", MAX_STATEMENTS_OPTS],
@@ -243,9 +366,9 @@ function collectStylesheetDeclarations(stylesheet) {
243
366
  stylesheetDeclarations.set(stylesheet, declarations);
244
367
  return declarations;
245
368
  }
246
- function parseStylesheetDeclarations(css2) {
369
+ function parseStylesheetDeclarations(css3) {
247
370
  const stylesheet = toPlainObject(
248
- parse(css2, { parseCustomProperty: true })
371
+ parse(css3, { parseCustomProperty: true })
249
372
  );
250
373
  return collectStylesheetDeclarations(stylesheet);
251
374
  }
@@ -423,8 +546,8 @@ function createDesignSystemView(tailwind) {
423
546
  }
424
547
  return {
425
548
  declarationsOf: memoize((token) => {
426
- const css2 = tailwind.candidatesToCss([token])[0];
427
- return css2 ? parseStylesheetDeclarations(css2) : void 0;
549
+ const css3 = tailwind.candidatesToCss([token])[0];
550
+ return css3 ? parseStylesheetDeclarations(css3) : void 0;
428
551
  }),
429
552
  candidatesOf: memoize(
430
553
  (token) => tailwind.parseCandidate(token).map((candidate) => buildClassCandidate(tailwind, candidate))
@@ -2585,7 +2708,7 @@ function buildCssConfig(plugin, rules) {
2585
2708
  return {
2586
2709
  name: "pragmatiks/next/css",
2587
2710
  files: ["**/*.css"],
2588
- plugins: { css, pragmatiks: plugin },
2711
+ plugins: { css: css, pragmatiks: plugin },
2589
2712
  language: "css/css",
2590
2713
  languageOptions: { tolerant: true },
2591
2714
  rules: buildRuleEntries(Object.keys(rules.css))
@@ -2601,7 +2724,8 @@ async function pragmatiksNextConfig(nextConfigs, options) {
2601
2724
  ...pragmatiksConfig(),
2602
2725
  buildFrontendConfig(accessibilityConfig, plugin, rules),
2603
2726
  buildTypedConfig(options.rootDir),
2604
- buildCssConfig(plugin, rules)
2727
+ buildCssConfig(plugin, rules),
2728
+ pragmatiksCssConfig()
2605
2729
  ];
2606
2730
  }
2607
2731