@pragmatiks/lint 0.8.0 → 0.10.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/dist/index.js CHANGED
@@ -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],
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/eslint-config/options.ts","../src/eslint-config/index.ts"],"names":[],"mappings":";;;;;;;;;;;AAAO,IAAM,eAAA,GAAkB;AAExB,IAAM,2BAAA,GAA8B;AAAA,EACzC,GAAA,EAAK,EAAA;AAAA,EACL,cAAA,EAAgB,IAAA;AAAA,EAChB,YAAA,EAAc;AAChB;AAEO,IAAM,mBAAA,GAAsB;AAE5B,IAAM,cAAA,GAAiB;AAEvB,IAAM,eAAA,GAAkB;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,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AAA,GACtE,CAAA;AACH","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;AAExB,IAAM,2BAAA,GAA8B;AAAA,EACzC,GAAA,EAAK,EAAA;AAAA,EACL,cAAA,EAAgB,IAAA;AAAA,EAChB,YAAA,EAAc;AAChB;AAEO,IAAM,mBAAA,GAAsB;AAE5B,IAAM,cAAA,GAAiB;AAEvB,IAAM,eAAA,GAAkB;AAExB,IAAM,0BAAA,GAA6B;AAAA,EACxC,SAAA,EAAW;AAAA,IACT,EA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E,KACF;AAAA,IACA,cAAc,CAAC,SAAA,EAAW,iBAAA,EAAmB,UAAA,EAAY,WAAW,CAAC;AAAA,GACtE,CAAA;AACH","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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pragmatiks/lint",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "Pragmatiks engineering principles eslint config and bundled semgrep rules.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -18,6 +18,10 @@
18
18
  "./eslint-config/next": {
19
19
  "types": "./dist/eslint-config/next/index.d.ts",
20
20
  "import": "./dist/eslint-config/next/index.js"
21
+ },
22
+ "./eslint-config/css": {
23
+ "types": "./dist/eslint-config/css/index.d.ts",
24
+ "import": "./dist/eslint-config/css/index.js"
21
25
  }
22
26
  },
23
27
  "files": [
@@ -0,0 +1,14 @@
1
+ rules:
2
+ - id: pra-exists-gated-read
3
+ patterns:
4
+ - pattern: $READ if $PATH.exists() else None
5
+ - metavariable-pattern:
6
+ metavariable: $READ
7
+ pattern-either:
8
+ - pattern: <... $FILE.read_text(...) ...>
9
+ - pattern: <... $FILE.read_bytes(...) ...>
10
+ - pattern: <... $FILE.open(...) ...>
11
+ - pattern: <... open(...) ...>
12
+ message: "principle #9 an existence check folded into a read ternary hides the absent case. Return None in a guard clause first, then read."
13
+ severity: WARNING
14
+ languages: [python]
@@ -0,0 +1,14 @@
1
+ rules:
2
+ - id: pra-if-chain-else-continue
3
+ pattern: |
4
+ if $FIRST:
5
+ $NAME = $FIRST_VALUE
6
+ elif $SECOND:
7
+ $NAME = $SECOND_VALUE
8
+ else:
9
+ continue
10
+ message: "principle #9 an if/elif chain that assigns one name in every branch and ends in else: continue hides a value lookup in the loop body. Move the chain into a helper that returns the value or None, and continue on None."
11
+ severity: WARNING
12
+ languages: [python]
13
+ metadata:
14
+ note: "The pattern matches the last two assigning branches, so a chain of any length is reported once at its final elif."
@@ -0,0 +1,6 @@
1
+ rules:
2
+ - id: pra-multi-underscore-unpack
3
+ pattern: "..., _, ..., _, ... = $VALUE[$KEY]"
4
+ message: "principle #9 unpacking a subscript into two or more _ placeholders hides the shape of the record. Read the parts by name: a named record, a dataclass or attribute access."
5
+ severity: WARNING
6
+ languages: [python]
@@ -0,0 +1,23 @@
1
+ rules:
2
+ - id: pra-optional-tuple-index
3
+ pattern-either:
4
+ - pattern: $FIRST, $SECOND = $CALL(...) or ($FIRST_DEFAULT, $SECOND_DEFAULT)
5
+ - patterns:
6
+ - pattern-either:
7
+ - pattern: $TUPLE is None or <... $TUPLE[$INDEX] ...>
8
+ - pattern: $TUPLE is not None and <... $TUPLE[$INDEX] ...>
9
+ - patterns:
10
+ - pattern-inside: |
11
+ def $FUNCTION(...):
12
+ ...
13
+ <... $TUPLE[$FIRST_INDEX] if $TUPLE else $FIRST_DEFAULT ...>
14
+ ...
15
+ <... $TUPLE[$SECOND_INDEX] if $TUPLE else $SECOND_DEFAULT ...>
16
+ ...
17
+ - pattern: $TUPLE[$INDEX] if $TUPLE else $DEFAULT
18
+ - metavariable-regex:
19
+ metavariable: $INDEX
20
+ regex: '^-?\d+$'
21
+ message: "principle #9 indexing an optional tuple under a None test mixes the absent case with positional access. Return on None in a guard clause, then unpack once into named locals."
22
+ severity: WARNING
23
+ languages: [python]
@@ -0,0 +1,15 @@
1
+ rules:
2
+ - id: pra-parsed-result-index
3
+ patterns:
4
+ - pattern-either:
5
+ - pattern: $FUNCTION(...)[$INDEX]
6
+ - pattern: $OBJECT.$FUNCTION(...)[$INDEX]
7
+ - metavariable-regex:
8
+ metavariable: $FUNCTION
9
+ regex: '^(parse|extract)_\w+$'
10
+ - metavariable-regex:
11
+ metavariable: $INDEX
12
+ regex: '^-?\d+$'
13
+ message: "principle #9 a literal index into a parse or extract result hides which part is meant. Unpack the result into named locals, or return a named record."
14
+ severity: WARNING
15
+ languages: [python]
@@ -0,0 +1,16 @@
1
+ rules:
2
+ - id: pra-pure-call-result-dropped
3
+ patterns:
4
+ - pattern-regex: '(?m)^[ \t]*(?:await[ \t]+)?(?:(?:self|cls)\.)?(?:compute|build|derive|format|parse|extract)_\w+\((?![^\n]*\)[ \t]*[.\[])(?:[^\n]*[(),])?[ \t]*$'
5
+ - pattern-not-inside: $CALL(...)
6
+ - pattern-not-inside: "[...]"
7
+ - pattern-not-inside: "{...}"
8
+ - pattern-not-inside: "(...)"
9
+ - pattern-not-inside: '"..."'
10
+ - pattern-not-inside: $TARGET = $VALUE
11
+ - pattern-not-inside: "$TARGET: $TYPE = $VALUE"
12
+ message: "principle #7 a compute, build, derive, format, parse or extract function is pure, so a call whose result is dropped does nothing. Use the result, or call the function that performs the side effect."
13
+ severity: WARNING
14
+ languages: [python]
15
+ metadata:
16
+ note: "Matches a call statement that opens its own line, so a call used as an argument, element, assignment value or chained receiver is not flagged. Principle #7 makes these prefixes pure; a result consumed only to raise on bad input belongs in a validate function that says so."
@@ -1,6 +0,0 @@
1
- rules:
2
- - id: pra-no-block-comments-js
3
- pattern-regex: '/\*(?!\*)[\s\S]*?\*/'
4
- message: "principle #10 Block comments make code harder to trust. Delete the comment; rationale worth keeping goes in the owning docstring."
5
- severity: ERROR
6
- languages: [typescript, javascript]
@@ -1,6 +0,0 @@
1
- rules:
2
- - id: pra-no-todo-comments-js
3
- pattern-regex: '(?i)(//|/\*)\s*(TODO(?!\(PRA-[0-9]+\))|FIXME|XXX)\b'
4
- message: "principle #10 Planning comments decay. Track the work as an issue and delete the comment."
5
- severity: ERROR
6
- languages: [typescript, javascript]