@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 +13 -0
- package/README.md +27 -5
- package/dist/eslint-config/css/index.d.ts +16 -0
- package/dist/eslint-config/css/index.js +122 -0
- package/dist/eslint-config/css/index.js.map +1 -0
- package/dist/eslint-config/index.d.ts +5 -1
- package/dist/eslint-config/index.js +107 -0
- package/dist/eslint-config/index.js.map +1 -1
- package/dist/eslint-config/next/index.d.ts +2 -1
- package/dist/eslint-config/next/index.js +130 -6
- package/dist/eslint-config/next/index.js.map +1 -1
- package/dist/index.js +107 -0
- package/dist/index.js.map +1 -1
- package/package.json +5 -1
- package/src/semgrep-rules/pra_io_prefix_mismatch.yml +12 -2
- package/src/semgrep-rules/pra_pure_prefix_mismatch.yml +78 -0
- package/src/semgrep-rules/pra_no_block_comments_js.yml +0 -6
- package/src/semgrep-rules/pra_no_todo_comments_js.yml +0 -6
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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AS,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","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,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,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","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.
|
|
3
|
+
"version": "0.9.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": [
|
|
@@ -103,6 +103,16 @@ rules:
|
|
|
103
103
|
...
|
|
104
104
|
$PATH.rmdir(...)
|
|
105
105
|
...
|
|
106
|
+
- pattern-not: |
|
|
107
|
+
def $NAME(...):
|
|
108
|
+
...
|
|
109
|
+
$PATH.resolve(...)
|
|
110
|
+
...
|
|
111
|
+
- pattern-not: |
|
|
112
|
+
def $NAME(...):
|
|
113
|
+
...
|
|
114
|
+
importlib.import_module(...)
|
|
115
|
+
...
|
|
106
116
|
- pattern-not: |
|
|
107
117
|
def $NAME(...):
|
|
108
118
|
...
|
|
@@ -113,10 +123,10 @@ rules:
|
|
|
113
123
|
...
|
|
114
124
|
subprocess.$METHOD(...)
|
|
115
125
|
...
|
|
116
|
-
- pattern-not-regex: '(?s)\bos\.(mkdir|makedirs|rmdir|removedirs|remove|unlink|rename|replace|kill|chdir|chmod|chown|symlink|link|stat|lstat|listdir|scandir|access|system|popen|path\.(exists|isfile|isdir|islink|getsize))\('
|
|
126
|
+
- pattern-not-regex: '(?s)\bos\.(mkdir|makedirs|rmdir|removedirs|remove|unlink|rename|replace|kill|chdir|chmod|chown|symlink|link|stat|lstat|listdir|scandir|access|system|popen|path\.(exists|isfile|isdir|islink|getsize|realpath))\('
|
|
117
127
|
- pattern-not-regex: '(?s)(database|session|connection|cursor|client)\.(execute|fetch|get|post|put|delete|query|read|write|save)\('
|
|
118
128
|
message: "principle #7 I/O-prefixed function appears pure. Rename it with compute, build, derive, format, or parse."
|
|
119
129
|
severity: WARNING
|
|
120
130
|
languages: [python]
|
|
121
131
|
metadata:
|
|
122
|
-
note: "Heuristic rule; false positives are expected for hidden I/O wrappers."
|
|
132
|
+
note: "Heuristic rule; false positives are expected for hidden I/O wrappers. The I/O vocabulary mirrors pra-pure-prefix-mismatch in opposite polarity; keep both rules in step."
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
rules:
|
|
2
|
+
- id: pra-pure-prefix-mismatch
|
|
3
|
+
patterns:
|
|
4
|
+
- pattern-either:
|
|
5
|
+
- pattern: |
|
|
6
|
+
def $NAME(...):
|
|
7
|
+
...
|
|
8
|
+
- pattern: |
|
|
9
|
+
async def $NAME(...):
|
|
10
|
+
...
|
|
11
|
+
- metavariable-regex:
|
|
12
|
+
metavariable: $NAME
|
|
13
|
+
regex: '^(compute|build|derive|format|parse|extract)_.*'
|
|
14
|
+
- pattern-either:
|
|
15
|
+
- pattern-inside: |
|
|
16
|
+
def $NAME(...):
|
|
17
|
+
...
|
|
18
|
+
$IO
|
|
19
|
+
...
|
|
20
|
+
- pattern-inside: |
|
|
21
|
+
async def $NAME(...):
|
|
22
|
+
...
|
|
23
|
+
$IO
|
|
24
|
+
...
|
|
25
|
+
- metavariable-pattern:
|
|
26
|
+
metavariable: $IO
|
|
27
|
+
pattern-either:
|
|
28
|
+
- pattern: open(...)
|
|
29
|
+
- pattern: $PATH.open(...)
|
|
30
|
+
- patterns:
|
|
31
|
+
- pattern-either:
|
|
32
|
+
- pattern: httpx.$METHOD(...)
|
|
33
|
+
- pattern: requests.$METHOD(...)
|
|
34
|
+
- metavariable-regex:
|
|
35
|
+
metavariable: $METHOD
|
|
36
|
+
regex: '^(get|post|put|patch|delete|head|options|request|stream)$'
|
|
37
|
+
- pattern: $PATH.read_text(...)
|
|
38
|
+
- pattern: $PATH.read_bytes(...)
|
|
39
|
+
- pattern: $PATH.write_text(...)
|
|
40
|
+
- pattern: $PATH.write_bytes(...)
|
|
41
|
+
- pattern: $PATH.unlink(...)
|
|
42
|
+
- pattern: $PATH.mkdir(...)
|
|
43
|
+
- pattern: $PATH.exists(...)
|
|
44
|
+
- pattern: $PATH.iterdir(...)
|
|
45
|
+
- pattern: $PATH.glob(...)
|
|
46
|
+
- pattern: $PATH.rmdir(...)
|
|
47
|
+
- pattern: $PATH.resolve(...)
|
|
48
|
+
- pattern: shutil.$METHOD(...)
|
|
49
|
+
- pattern: subprocess.$METHOD(...)
|
|
50
|
+
- pattern: importlib.import_module(...)
|
|
51
|
+
- patterns:
|
|
52
|
+
- pattern: os.$METHOD(...)
|
|
53
|
+
- metavariable-regex:
|
|
54
|
+
metavariable: $METHOD
|
|
55
|
+
regex: '^(mkdir|makedirs|rmdir|removedirs|remove|unlink|rename|replace|kill|chdir|chmod|chown|symlink|link|stat|lstat|listdir|scandir|access|system|popen)$'
|
|
56
|
+
- patterns:
|
|
57
|
+
- pattern: os.path.$METHOD(...)
|
|
58
|
+
- metavariable-regex:
|
|
59
|
+
metavariable: $METHOD
|
|
60
|
+
regex: '^(exists|isfile|isdir|islink|getsize|realpath)$'
|
|
61
|
+
- patterns:
|
|
62
|
+
- pattern: $CLIENT.$METHOD(...)
|
|
63
|
+
- metavariable-regex:
|
|
64
|
+
metavariable: $CLIENT
|
|
65
|
+
regex: '(database|session|connection|cursor|client)$'
|
|
66
|
+
- metavariable-regex:
|
|
67
|
+
metavariable: $METHOD
|
|
68
|
+
regex: '^(execute|fetch|get|post|put|delete|query|read|write|save)$'
|
|
69
|
+
- patterns:
|
|
70
|
+
- pattern: $CALLEE(...)
|
|
71
|
+
- metavariable-regex:
|
|
72
|
+
metavariable: $CALLEE
|
|
73
|
+
regex: '^(fetch|retrieve|load|save|read|write|query)_\w+$'
|
|
74
|
+
message: "principle #7 pure-prefixed function appears to perform I/O. Rename it with get, fetch, retrieve, load, save, read, write, or query, or move the I/O to the caller."
|
|
75
|
+
severity: WARNING
|
|
76
|
+
languages: [python]
|
|
77
|
+
metadata:
|
|
78
|
+
note: "Heuristic rule; detects I/O written in the body, or a call to a bare function named with an I/O prefix other than get. I/O hidden behind other helpers is not seen. The I/O vocabulary mirrors pra-io-prefix-mismatch in opposite polarity; keep both rules in step."
|
|
@@ -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]
|