eslint-plugin-no-mistakes 0.6.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/LICENSE +21 -0
- package/README.md +10 -0
- package/package.json +36 -0
- package/src/defaulted-props.js +209 -0
- package/src/helpers.js +180 -0
- package/src/index.js +58 -0
- package/src/react-node-types.js +146 -0
- package/src/rules/nextjs-static-fetch-method.js +38 -0
- package/src/rules/nextjs-static-fetch-url.js +27 -0
- package/src/rules/playwright-consistent-attribute.js +33 -0
- package/src/rules/playwright-defaults.js +32 -0
- package/src/rules/playwright-literals.js +64 -0
- package/src/rules/playwright-naming-convention.js +32 -0
- package/src/rules/playwright-no-empty.js +25 -0
- package/src/rules/playwright-prefer-get-by-test-id.js +48 -0
- package/src/rules/playwright-require-interactive-test-id.js +69 -0
- package/src/rules/playwright-unique.js +38 -0
- package/src/rules/react-no-nullish-react-node.js +193 -0
- package/src/rules/ts-no-export-renaming.js +42 -0
- package/src/rules/ts-no-function-aliases.js +102 -0
- package/src/selector-visitor.js +19 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { rule } = require("../helpers");
|
|
4
|
+
|
|
5
|
+
function unwrapExpression(expression) {
|
|
6
|
+
let current = expression;
|
|
7
|
+
while (
|
|
8
|
+
current &&
|
|
9
|
+
(current.type === "AwaitExpression" ||
|
|
10
|
+
current.type === "ChainExpression" ||
|
|
11
|
+
current.type === "TSNonNullExpression")
|
|
12
|
+
) {
|
|
13
|
+
current = current.type === "AwaitExpression" ? current.argument : current.expression;
|
|
14
|
+
}
|
|
15
|
+
return current;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function expressionStatementCall(statement) {
|
|
19
|
+
if (statement.type !== "ExpressionStatement") return null;
|
|
20
|
+
return unwrapExpression(statement.expression);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function returnStatementCall(statement) {
|
|
24
|
+
if (statement.type !== "ReturnStatement") return null;
|
|
25
|
+
return unwrapExpression(statement.argument);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function onlyCallExpression(body) {
|
|
29
|
+
if (!body) return null;
|
|
30
|
+
if (body.type !== "BlockStatement") {
|
|
31
|
+
return unwrapExpression(body);
|
|
32
|
+
}
|
|
33
|
+
if (body.body.length !== 1) return null;
|
|
34
|
+
const statement = body.body[0];
|
|
35
|
+
return returnStatementCall(statement) || expressionStatementCall(statement);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function identifierName(node) {
|
|
39
|
+
return node && node.type === "Identifier" ? node.name : null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function isSameArgumentList(params, args) {
|
|
43
|
+
if (params.length !== args.length) return false;
|
|
44
|
+
return params.every((param, index) => {
|
|
45
|
+
if (param.type === "RestElement") {
|
|
46
|
+
return (
|
|
47
|
+
args[index].type === "SpreadElement" &&
|
|
48
|
+
identifierName(param.argument) === identifierName(args[index].argument)
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
if (param.type === "AssignmentPattern") return false;
|
|
52
|
+
const name = identifierName(param);
|
|
53
|
+
return name && args[index].type === "Identifier" && args[index].name === name;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function isSelfCall(node, call) {
|
|
58
|
+
if (call.callee.type !== "Identifier") return false;
|
|
59
|
+
if (node.id && node.id.name === call.callee.name) return true;
|
|
60
|
+
const parent = node.parent;
|
|
61
|
+
return (
|
|
62
|
+
parent &&
|
|
63
|
+
parent.type === "VariableDeclarator" &&
|
|
64
|
+
parent.id.type === "Identifier" &&
|
|
65
|
+
parent.id.name === call.callee.name
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function reportIfAlias(node, context) {
|
|
70
|
+
const call = onlyCallExpression(node.body);
|
|
71
|
+
if (!call || call.type !== "CallExpression") return;
|
|
72
|
+
if (isSelfCall(node, call)) return;
|
|
73
|
+
if (isSameArgumentList(node.params || [], call.arguments)) {
|
|
74
|
+
context.report({ node, messageId: "alias" });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
module.exports = rule(
|
|
79
|
+
{
|
|
80
|
+
type: "problem",
|
|
81
|
+
docs: {
|
|
82
|
+
description: "disallow function wrappers that only alias another function",
|
|
83
|
+
recommended: true,
|
|
84
|
+
},
|
|
85
|
+
schema: [],
|
|
86
|
+
messages: {
|
|
87
|
+
alias:
|
|
88
|
+
"Do not create a function that only aliases another function call. Export or call the original function name directly so agents can trace behavior.",
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
(context) => ({
|
|
92
|
+
ArrowFunctionExpression(node) {
|
|
93
|
+
reportIfAlias(node, context);
|
|
94
|
+
},
|
|
95
|
+
FunctionDeclaration(node) {
|
|
96
|
+
reportIfAlias(node, context);
|
|
97
|
+
},
|
|
98
|
+
FunctionExpression(node) {
|
|
99
|
+
reportIfAlias(node, context);
|
|
100
|
+
},
|
|
101
|
+
}),
|
|
102
|
+
);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { attributeName, isSelectorAttribute, options, selectorAttributes } = require("./helpers");
|
|
4
|
+
|
|
5
|
+
function selectorAttributeVisitors(context, callback) {
|
|
6
|
+
const attrs = selectorAttributes(options(context));
|
|
7
|
+
return {
|
|
8
|
+
JSXAttribute(node) {
|
|
9
|
+
const name = attributeName(node);
|
|
10
|
+
if (name && isSelectorAttribute(name, attrs)) {
|
|
11
|
+
callback(node, name);
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = {
|
|
18
|
+
selectorAttributeVisitors,
|
|
19
|
+
};
|