eslint-plugin-no-mistakes 0.54.1 → 0.55.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/README.md +3 -1
- package/package.json +2 -2
- package/src/index.js +2 -0
- package/src/rules/ts-no-const-aliases.js +47 -0
package/README.md
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
# eslint-plugin-no-mistakes
|
|
2
2
|
|
|
3
3
|
ESLint and Oxlint rules that keep TS/JS, React, Next.js, and Playwright code
|
|
4
|
-
static enough for `no-mistakes` analyzers
|
|
4
|
+
static enough for `no-mistakes` analyzers. They exist so agents cannot hide
|
|
5
|
+
callers, fetches, or selectors behind aliases and dynamic values. See
|
|
6
|
+
[why no-mistakes exists](../../docs/why.md).
|
|
5
7
|
|
|
6
8
|
```sh
|
|
7
9
|
npm install --save-dev eslint-plugin-no-mistakes
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-no-mistakes",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "ESLint and Oxlint rules for
|
|
3
|
+
"version": "0.55.0",
|
|
4
|
+
"description": "ESLint and Oxlint rules that keep code static enough for no-mistakes analyzers and coding agents",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
package/src/index.js
CHANGED
|
@@ -39,6 +39,7 @@ const rules = {
|
|
|
39
39
|
"server-require-nullable-fetch-wrapper": require("./rules/server-require-nullable-fetch-wrapper"),
|
|
40
40
|
"test-no-error-message-matching": require("./rules/test-no-error-message-matching"),
|
|
41
41
|
"test-no-shared-state": require("./rules/test-no-shared-state"),
|
|
42
|
+
"ts-no-const-aliases": require("./rules/ts-no-const-aliases"),
|
|
42
43
|
"ts-no-export-renaming": require("./rules/ts-no-export-renaming"),
|
|
43
44
|
"ts-no-function-aliases": require("./rules/ts-no-function-aliases"),
|
|
44
45
|
"ts-preserve-null-option-defaults": require("./rules/ts-preserve-null-option-defaults"),
|
|
@@ -68,6 +69,7 @@ plugin.configs.recommended = {
|
|
|
68
69
|
"no-mistakes/playwright-no-empty": "error",
|
|
69
70
|
"no-mistakes/playwright-unique": "error",
|
|
70
71
|
"no-mistakes/react-no-nullish-react-node": "error",
|
|
72
|
+
"no-mistakes/ts-no-const-aliases": "error",
|
|
71
73
|
"no-mistakes/ts-no-export-renaming": "error",
|
|
72
74
|
"no-mistakes/ts-no-function-aliases": "error",
|
|
73
75
|
},
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { rule } = require("../helpers");
|
|
4
|
+
|
|
5
|
+
const TRANSPARENT_EXPRESSION_TYPES = new Set([
|
|
6
|
+
"ChainExpression",
|
|
7
|
+
"TSAsExpression",
|
|
8
|
+
"TSInstantiationExpression",
|
|
9
|
+
"TSNonNullExpression",
|
|
10
|
+
"TSSatisfiesExpression",
|
|
11
|
+
"TSTypeAssertion",
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
function unwrapExpression(expression) {
|
|
15
|
+
let current = expression;
|
|
16
|
+
while (TRANSPARENT_EXPRESSION_TYPES.has(current.type)) {
|
|
17
|
+
current = current.expression;
|
|
18
|
+
}
|
|
19
|
+
return current;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = rule(
|
|
23
|
+
{
|
|
24
|
+
type: "problem",
|
|
25
|
+
docs: {
|
|
26
|
+
description: "disallow const aliases for differently named values",
|
|
27
|
+
recommended: true,
|
|
28
|
+
},
|
|
29
|
+
schema: [],
|
|
30
|
+
messages: {
|
|
31
|
+
alias:
|
|
32
|
+
"Do not create a differently named const alias. Use the original name directly so readers and tooling can trace symbols without indirection.",
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
(context) => ({
|
|
36
|
+
VariableDeclaration(node) {
|
|
37
|
+
if (node.kind !== "const") return;
|
|
38
|
+
for (const declarator of node.declarations) {
|
|
39
|
+
if (declarator.id.type !== "Identifier" || !declarator.init) continue;
|
|
40
|
+
const initializer = unwrapExpression(declarator.init);
|
|
41
|
+
if (initializer.type === "Identifier" && declarator.id.name !== initializer.name) {
|
|
42
|
+
context.report({ node: declarator, messageId: "alias" });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
}),
|
|
47
|
+
);
|