@checkdigit/eslint-plugin 7.14.0-PR.117-1980 → 7.14.0-PR.57-987f
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-mjs/index.mjs +6 -9
- package/dist-mjs/no-side-effects.mjs +87 -31
- package/dist-mjs/no-util.mjs +47 -0
- package/dist-types/no-util.d.ts +5 -0
- package/package.json +1 -1
- package/src/file-path-comment.ts +1 -1
- package/src/index.ts +5 -8
- package/src/no-side-effects.ts +161 -70
- package/src/no-util.ts +53 -0
- package/dist-mjs/no-type-assertion-as.mjs +0 -45
- package/dist-types/no-type-assertion-as.d.ts +0 -5
- package/src/no-type-assertion-as.ts +0 -60
package/dist-mjs/index.mjs
CHANGED
|
@@ -23,7 +23,7 @@ import noEnum from "./no-enum.mjs";
|
|
|
23
23
|
import noSideEffects from "./no-side-effects.mjs";
|
|
24
24
|
import noRandomV4UUID from "./no-random-v4-uuid.mjs";
|
|
25
25
|
import noTestImport from "./no-test-import.mjs";
|
|
26
|
-
import
|
|
26
|
+
import noUtil from "./no-util.mjs";
|
|
27
27
|
import noUuid from "./no-uuid.mjs";
|
|
28
28
|
import noWallabyComment from "./no-wallaby-comment.mjs";
|
|
29
29
|
import objectLiteralResponse from "./object-literal-response.mjs";
|
|
@@ -38,6 +38,7 @@ var rules = {
|
|
|
38
38
|
"no-enum": noEnum,
|
|
39
39
|
"no-random-v4-uuid": noRandomV4UUID,
|
|
40
40
|
"no-status-code-assert": noStatusCodeAssert,
|
|
41
|
+
"no-util": noUtil,
|
|
41
42
|
"no-uuid": noUuid,
|
|
42
43
|
"require-assert-message": requireAssertMessage,
|
|
43
44
|
"require-strict-assert": requireStrictAssert,
|
|
@@ -45,7 +46,6 @@ var rules = {
|
|
|
45
46
|
"no-test-import": noTestImport,
|
|
46
47
|
"no-wallaby-comment": noWallabyComment,
|
|
47
48
|
"no-side-effects": noSideEffects,
|
|
48
|
-
"no-type-assertion-as": noTypeAssertionAs,
|
|
49
49
|
"regular-expression-comment": regexComment,
|
|
50
50
|
"require-assert-predicate-rejects-throws": requireAssertPredicateRejectsThrows,
|
|
51
51
|
"object-literal-response": objectLiteralResponse,
|
|
@@ -75,16 +75,13 @@ var configs = {
|
|
|
75
75
|
"@checkdigit/file-path-comment": "error",
|
|
76
76
|
"@checkdigit/no-random-v4-uuid": "error",
|
|
77
77
|
"@checkdigit/no-status-code-assert": "error",
|
|
78
|
+
"@checkdigit/no-util": "error",
|
|
78
79
|
"@checkdigit/no-uuid": "error",
|
|
79
80
|
"@checkdigit/require-assert-message": "error",
|
|
80
81
|
"@checkdigit/require-strict-assert": "error",
|
|
81
82
|
"@checkdigit/require-ts-extension-imports-exports": "error",
|
|
82
83
|
"@checkdigit/no-wallaby-comment": "error",
|
|
83
|
-
"@checkdigit/no-side-effects":
|
|
84
|
-
"error",
|
|
85
|
-
{ excludedIdentifiers: ["assert", "debug", "log", "promisify", "Symbol.for"] }
|
|
86
|
-
],
|
|
87
|
-
"@checkdigit/no-type-assertion-as": "error",
|
|
84
|
+
"@checkdigit/no-side-effects": "error",
|
|
88
85
|
"@checkdigit/regular-expression-comment": "error",
|
|
89
86
|
"@checkdigit/require-assert-predicate-rejects-throws": "error",
|
|
90
87
|
"@checkdigit/object-literal-response": "error",
|
|
@@ -113,13 +110,13 @@ var configs = {
|
|
|
113
110
|
"@checkdigit/file-path-comment": "off",
|
|
114
111
|
"@checkdigit/no-random-v4-uuid": "error",
|
|
115
112
|
"@checkdigit/no-status-code-assert": "error",
|
|
113
|
+
"@checkdigit/no-util": "error",
|
|
116
114
|
"@checkdigit/no-uuid": "error",
|
|
117
115
|
"@checkdigit/require-assert-message": "error",
|
|
118
116
|
"@checkdigit/require-strict-assert": "error",
|
|
119
117
|
"@checkdigit/require-ts-extension-imports-exports": "error",
|
|
120
118
|
"@checkdigit/no-wallaby-comment": "off",
|
|
121
119
|
"@checkdigit/no-side-effects": "error",
|
|
122
|
-
"@checkdigit/no-type-assertion-as": "error",
|
|
123
120
|
"@checkdigit/regular-expression-comment": "error",
|
|
124
121
|
"@checkdigit/require-assert-predicate-rejects-throws": "error",
|
|
125
122
|
"@checkdigit/object-literal-response": "error",
|
|
@@ -145,4 +142,4 @@ var src_default = defaultToExport;
|
|
|
145
142
|
export {
|
|
146
143
|
src_default as default
|
|
147
144
|
};
|
|
148
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
145
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL2luZGV4LnRzIl0sCiAgIm1hcHBpbmdzIjogIjtBQVVBLE9BQU8sd0JBQXdCLFVBQVUsa0NBQWtDO0FBQzNFLE9BQU8sdUJBQXVCLFVBQVUsaUNBQWlDO0FBQ3pFLE9BQU8seUJBQXlCLFVBQVUsbUNBQW1DO0FBQzdFLE9BQU8sMkJBQTJCLFVBQVUscUNBQXFDO0FBQ2pGLE9BQU8sd0JBQXdCO0FBQy9CLE9BQU87QUFBQSxFQUNMLFVBQVU7QUFBQSxPQUNMO0FBQ1AsT0FBTztBQUFBLEVBQ0wsVUFBVTtBQUFBLE9BQ0w7QUFDUCxPQUFPO0FBQUEsRUFDTCxVQUFVO0FBQUEsT0FDTDtBQUNQLE9BQU8sa0JBQWtCLFVBQVUsNEJBQTRCO0FBQy9ELE9BQU87QUFBQSxFQUNMLFVBQVU7QUFBQSxPQUNMO0FBQ1AsT0FBTyxxQkFBcUI7QUFDNUIsT0FBTyxtQkFBbUI7QUFDMUIsT0FBTyxZQUFZO0FBQ25CLE9BQU8sbUJBQW1CO0FBQzFCLE9BQU8sb0JBQW9CO0FBQzNCLE9BQU8sa0JBQWtCO0FBQ3pCLE9BQU8sWUFBWTtBQUNuQixPQUFPLFlBQVk7QUFDbkIsT0FBTyxzQkFBc0I7QUFDN0IsT0FBTywyQkFBMkI7QUFDbEMsT0FBTyxrQkFBa0I7QUFDekIsT0FBTyx5Q0FBeUM7QUFDaEQsT0FBT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@typescript-eslint/utils";
|
|
3
3
|
import { TSESTree } from "@typescript-eslint/typescript-estree";
|
|
4
|
+
import getDocumentationUrl from "./get-documentation-url.mjs";
|
|
4
5
|
var ruleId = "no-side-effects";
|
|
5
6
|
var NO_SIDE_EFFECTS = "NO_SIDE_EFFECTS";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
function isVariableDeclarationCallExpression(node, excludedIdentifiers) {
|
|
7
|
+
var isExpressionStatement = (node) => node.type === TSESTree.AST_NODE_TYPES.ExpressionStatement;
|
|
8
|
+
var isAwaitExpression = (statement) => isExpressionStatement(statement) && statement.expression.type === TSESTree.AST_NODE_TYPES.AwaitExpression;
|
|
9
|
+
var isVariableDeclarationAwaitExpression = (node) => node.type === TSESTree.AST_NODE_TYPES.VariableDeclaration && node.declarations.length > 0 && node.declarations[0]?.init?.type === TSESTree.AST_NODE_TYPES.AwaitExpression;
|
|
10
|
+
var isNotValidVariableDeclaration = (node) => node.type === TSESTree.AST_NODE_TYPES.VariableDeclaration && node.kind !== "const" && node.kind !== "using";
|
|
11
|
+
var isControlFlowStatement = (node) => [
|
|
12
|
+
TSESTree.AST_NODE_TYPES.TryStatement,
|
|
13
|
+
TSESTree.AST_NODE_TYPES.IfStatement,
|
|
14
|
+
TSESTree.AST_NODE_TYPES.SwitchStatement,
|
|
15
|
+
TSESTree.AST_NODE_TYPES.ForStatement,
|
|
16
|
+
TSESTree.AST_NODE_TYPES.WhileStatement,
|
|
17
|
+
TSESTree.AST_NODE_TYPES.DoWhileStatement
|
|
18
|
+
].includes(node.type);
|
|
19
|
+
var isAssignmentExpression = (node) => node.type === TSESTree.AST_NODE_TYPES.ExpressionStatement && node.expression.type === TSESTree.AST_NODE_TYPES.AssignmentExpression;
|
|
20
|
+
var isIdentifierCallee = (node, excludedIdentifiers) => node.callee.type === TSESTree.AST_NODE_TYPES.Identifier && !excludedIdentifiers.includes(node.callee.name);
|
|
21
|
+
var isMemberExpressionCallee = (node, excludedIdentifiers) => node.callee.type === TSESTree.AST_NODE_TYPES.MemberExpression && node.callee.object.type === TSESTree.AST_NODE_TYPES.Identifier && node.callee.property.type === TSESTree.AST_NODE_TYPES.Identifier && !excludedIdentifiers.includes(`${node.callee.object.name}.${node.callee.property.name}`);
|
|
22
|
+
var isNonIdentifierObjectMemberExpressionCallee = (node) => node.callee.type === TSESTree.AST_NODE_TYPES.MemberExpression && node.callee.object.type !== TSESTree.AST_NODE_TYPES.Identifier;
|
|
23
|
+
var isCallExpressionCalleeMemberExpression = (statement, excludedIdentifiers) => isExpressionStatement(statement) && statement.expression.type === TSESTree.AST_NODE_TYPES.CallExpression && statement.expression.callee.type === TSESTree.AST_NODE_TYPES.MemberExpression && statement.expression.callee.object.type === TSESTree.AST_NODE_TYPES.Identifier && statement.expression.callee.property.type === TSESTree.AST_NODE_TYPES.Identifier && !excludedIdentifiers.includes(statement.expression.callee.object.name) && !excludedIdentifiers.includes(
|
|
24
|
+
`${statement.expression.callee.object.name}.${statement.expression.callee.property.name}`
|
|
25
|
+
);
|
|
26
|
+
var isVariableDeclarationCallExpression = (node, excludedIdentifiers) => {
|
|
28
27
|
if (node.type !== TSESTree.AST_NODE_TYPES.VariableDeclaration || node.declarations.length === 0) {
|
|
29
28
|
return false;
|
|
30
29
|
}
|
|
@@ -32,18 +31,71 @@ function isVariableDeclarationCallExpression(node, excludedIdentifiers) {
|
|
|
32
31
|
if (init?.type !== TSESTree.AST_NODE_TYPES.CallExpression) {
|
|
33
32
|
return false;
|
|
34
33
|
}
|
|
34
|
+
const callee = init.callee;
|
|
35
|
+
if (callee.type === TSESTree.AST_NODE_TYPES.ArrowFunctionExpression || callee.type === TSESTree.AST_NODE_TYPES.FunctionExpression) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
35
38
|
return isIdentifierCallee(init, excludedIdentifiers) || isMemberExpressionCallee(init, excludedIdentifiers) || isNonIdentifierObjectMemberExpressionCallee(init);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
39
|
+
};
|
|
40
|
+
var isExportNamedDeclarationWithSideEffects = (statement, excludedIdentifiers) => statement.type === TSESTree.AST_NODE_TYPES.ExportNamedDeclaration && statement.declaration !== null && (isVariableDeclarationAwaitExpression(statement.declaration) || isVariableDeclarationCallExpression(statement.declaration, excludedIdentifiers));
|
|
41
|
+
var isExpressionStatementWithSideEffects = (statement, excludedIdentifiers) => statement.type === TSESTree.AST_NODE_TYPES.ExpressionStatement && statement.expression.type === TSESTree.AST_NODE_TYPES.CallExpression && (statement.expression.callee.type === TSESTree.AST_NODE_TYPES.Identifier && !excludedIdentifiers.includes(statement.expression.callee.name) || statement.expression.callee.type === TSESTree.AST_NODE_TYPES.MemberExpression && statement.expression.callee.object.type === TSESTree.AST_NODE_TYPES.Identifier && statement.expression.callee.property.type === TSESTree.AST_NODE_TYPES.Identifier && !excludedIdentifiers.includes(
|
|
42
|
+
`${statement.expression.callee.object.name}.${statement.expression.callee.property.name}`
|
|
43
|
+
));
|
|
44
|
+
var isVariableDeclarationNewExpression = (node) => {
|
|
45
|
+
if (node.type !== TSESTree.AST_NODE_TYPES.VariableDeclaration || node.declarations.length === 0) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
const init = node.declarations[0]?.init;
|
|
49
|
+
return init?.type === TSESTree.AST_NODE_TYPES.NewExpression;
|
|
50
|
+
};
|
|
51
|
+
var isFunctionDeclarationAwaitExpression = (node) => node.type === TSESTree.AST_NODE_TYPES.FunctionDeclaration && node.body.body.some(
|
|
52
|
+
(statement) => statement.type === TSESTree.AST_NODE_TYPES.ExpressionStatement && statement.expression.type === TSESTree.AST_NODE_TYPES.AwaitExpression
|
|
53
|
+
);
|
|
54
|
+
var hasSideEffects = (statement, excludedIdentifiers) => {
|
|
55
|
+
if (isAwaitExpression(statement)) {
|
|
56
|
+
return TSESTree.AST_NODE_TYPES.AwaitExpression;
|
|
57
|
+
}
|
|
58
|
+
if (isCallExpressionCalleeMemberExpression(statement, excludedIdentifiers)) {
|
|
59
|
+
return "CallExpressionCalleeMemberExpression";
|
|
60
|
+
}
|
|
61
|
+
if (isVariableDeclarationAwaitExpression(statement)) {
|
|
62
|
+
return "VariableDeclarationAwaitExpression";
|
|
63
|
+
}
|
|
64
|
+
if (isVariableDeclarationCallExpression(statement, excludedIdentifiers)) {
|
|
65
|
+
return "VariableDeclarationCallExpression";
|
|
66
|
+
}
|
|
67
|
+
if (isVariableDeclarationNewExpression(statement)) {
|
|
68
|
+
return "VariableDeclarationNewExpression";
|
|
69
|
+
}
|
|
70
|
+
if (isExportNamedDeclarationWithSideEffects(statement, excludedIdentifiers)) {
|
|
71
|
+
return "ExportNamedDeclarationWithSideEffects";
|
|
72
|
+
}
|
|
73
|
+
if (isExpressionStatementWithSideEffects(statement, excludedIdentifiers)) {
|
|
74
|
+
return "ExpressionStatementWithSideEffects";
|
|
75
|
+
}
|
|
76
|
+
if (isControlFlowStatement(statement)) {
|
|
77
|
+
return "ControlFlowStatement";
|
|
78
|
+
}
|
|
79
|
+
if (isNotValidVariableDeclaration(statement)) {
|
|
80
|
+
return "NotValidVariableDeclaration";
|
|
81
|
+
}
|
|
82
|
+
if (isAssignmentExpression(statement)) {
|
|
83
|
+
return TSESTree.AST_NODE_TYPES.AssignmentExpression;
|
|
84
|
+
}
|
|
85
|
+
if (isFunctionDeclarationAwaitExpression(statement)) {
|
|
86
|
+
return "FunctionDeclarationAwaitExpression";
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
};
|
|
90
|
+
var createRule = ESLintUtils.RuleCreator(
|
|
91
|
+
(name) => getDocumentationUrl(name)
|
|
92
|
+
);
|
|
41
93
|
var rule = createRule({
|
|
42
94
|
name: ruleId,
|
|
43
95
|
meta: {
|
|
44
96
|
type: "problem",
|
|
45
97
|
docs: {
|
|
46
|
-
description: "Ensure no side effects can occur at the module-level"
|
|
98
|
+
description: "Ensure no side effects can occur at the module-level only if exporting module"
|
|
47
99
|
},
|
|
48
100
|
schema: [
|
|
49
101
|
{
|
|
@@ -74,10 +126,14 @@ var rule = createRule({
|
|
|
74
126
|
return;
|
|
75
127
|
}
|
|
76
128
|
node.body.forEach((statement) => {
|
|
77
|
-
|
|
129
|
+
const sideEffectType = hasSideEffects(statement, excludedIdentifiers);
|
|
130
|
+
if (sideEffectType !== null) {
|
|
78
131
|
context.report({
|
|
79
132
|
node: statement,
|
|
80
|
-
messageId: NO_SIDE_EFFECTS
|
|
133
|
+
messageId: NO_SIDE_EFFECTS,
|
|
134
|
+
data: {
|
|
135
|
+
sideEffectType
|
|
136
|
+
}
|
|
81
137
|
});
|
|
82
138
|
}
|
|
83
139
|
});
|
|
@@ -90,4 +146,4 @@ export {
|
|
|
90
146
|
no_side_effects_default as default,
|
|
91
147
|
ruleId
|
|
92
148
|
};
|
|
93
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
149
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL25vLXNpZGUtZWZmZWN0cy50cyJdLAogICJtYXBwaW5ncyI6ICI7QUFRQSxTQUFTLG1CQUFtQjtBQUM1QixTQUFTLGdCQUFnQjtBQUN6QixPQUFPLHlCQUF5QjtBQU16QixJQUFNLFNBQVM7QUFDdEIsSUFBTSxrQkFBa0I7QUFLeEIsSUFBTSx3QkFBd0IsQ0FBQyxTQUM3QixLQUFLLFNBQVMsU0FBUyxlQUFlO0FBR3hDLElBQU0sb0JBQW9CLENBQUMsY0FDekIsc0JBQXNCLFNBQVMsS0FBSyxVQUFVLFdBQVcsU0FBUyxTQUFTLG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CQUFNLGlCQUFpQixlQUFlLFdBQVcsbUJBQW1CO0FBQ3BFLGNBQUksbUJBQW1CLE1BQU07QUFDM0Isb0JBQVEsT0FBTztBQUFBLGNBQ2IsTUFBTTtBQUFBLGNBQ04sV0FBVztBQUFBLGNBQ1gsTUFBTTtBQUFBLGdCQUNKO0FBQUEsY0FDRjtBQUFBLFlBQ0YsQ0FBQztBQUFBLFVBQ0g7QUFBQSxRQUNGLENBQUM7QUFBQSxNQUNIO0FBQUEsSUFDRjtBQUFBLEVBQ0Y7QUFDRixDQUFDO0FBRUQsSUFBTywwQkFBUTsiLAogICJuYW1lcyI6IFtdCn0K
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// src/no-util.ts
|
|
2
|
+
import { AST_TOKEN_TYPES, ESLintUtils } from "@typescript-eslint/utils";
|
|
3
|
+
var ruleId = "no-util";
|
|
4
|
+
var NO_UTIL = "NO_UTIL";
|
|
5
|
+
var createRule = ESLintUtils.RuleCreator((name) => name);
|
|
6
|
+
var rule = createRule({
|
|
7
|
+
name: ruleId,
|
|
8
|
+
meta: {
|
|
9
|
+
type: "problem",
|
|
10
|
+
docs: {
|
|
11
|
+
description: "Detects if file name is util"
|
|
12
|
+
},
|
|
13
|
+
schema: [],
|
|
14
|
+
messages: {
|
|
15
|
+
[NO_UTIL]: "File name '{{filename}}' contains banned 'util' pattern."
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
defaultOptions: [],
|
|
19
|
+
create(context) {
|
|
20
|
+
return {
|
|
21
|
+
Program() {
|
|
22
|
+
const filename = context.filename;
|
|
23
|
+
const utilRegex = /(?:^|[-_/])util(?=[-_./]|$)/iu;
|
|
24
|
+
if (utilRegex.test(filename)) {
|
|
25
|
+
const sourceCode = context.sourceCode;
|
|
26
|
+
const tokens = sourceCode.tokensAndComments;
|
|
27
|
+
const firstNonCommentToken = tokens.find(
|
|
28
|
+
(token) => token.type !== AST_TOKEN_TYPES.Block && token.type !== AST_TOKEN_TYPES.Line
|
|
29
|
+
);
|
|
30
|
+
if (firstNonCommentToken !== void 0) {
|
|
31
|
+
context.report({
|
|
32
|
+
messageId: NO_UTIL,
|
|
33
|
+
data: { filename },
|
|
34
|
+
node: firstNonCommentToken
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
var no_util_default = rule;
|
|
43
|
+
export {
|
|
44
|
+
no_util_default as default,
|
|
45
|
+
ruleId
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL25vLXV0aWwudHMiXSwKICAibWFwcGluZ3MiOiAiO0FBUUEsU0FBUyxpQkFBaUIsbUJBQW1CO0FBRXRDLElBQU0sU0FBUztBQUN0QixJQUFNLFVBQVU7QUFFaEIsSUFBTSxhQUFhLFlBQVksWUFBWSxDQUFDLFNBQVMsSUFBSTtBQUV6RCxJQUFNLE9BQStDLFdBQVc7QUFBQSxFQUM5RCxNQUFNO0FBQUEsRUFDTixNQUFNO0FBQUEsSUFDSixNQUFNO0FBQUEsSUFDTixNQUFNO0FBQUEsTUFDSixhQUFhO0FBQUEsSUFDZjtBQUFBLElBQ0EsUUFBUSxDQUFDO0FBQUEsSUFDVCxVQUFVO0FBQUEsTUFDUixDQUFDLE9BQU8sR0FBRztBQUFBLElBQ2I7QUFBQSxFQUNGO0FBQUEsRUFDQSxnQkFBZ0IsQ0FBQztBQUFBLEVBQ2pCLE9BQU8sU0FBUztBQUNkLFdBQU87QUFBQSxNQUNMLFVBQVU7QUFDUixjQUFNLFdBQVcsUUFBUTtBQUN6QixjQUFNLFlBQVk7QUFDbEIsWUFBSSxVQUFVLEtBQUssUUFBUSxHQUFHO0FBQzVCLGdCQUFNLGFBQWEsUUFBUTtBQUMzQixnQkFBTSxTQUFTLFdBQVc7QUFDMUIsZ0JBQU0sdUJBQXVCLE9BQU87QUFBQSxZQUNsQyxDQUFDLFVBQVUsTUFBTSxTQUFTLGdCQUFnQixTQUFTLE1BQU0sU0FBUyxnQkFBZ0I7QUFBQSxVQUNwRjtBQUNBLGNBQUkseUJBQXlCLFFBQVc7QUFDdEMsb0JBQVEsT0FBTztBQUFBLGNBQ2IsV0FBVztBQUFBLGNBQ1gsTUFBTSxFQUFFLFNBQVM7QUFBQSxjQUNqQixNQUFNO0FBQUEsWUFDUixDQUFDO0FBQUEsVUFDSDtBQUFBLFFBQ0Y7QUFBQSxNQUNGO0FBQUEsSUFDRjtBQUFBLEVBQ0Y7QUFDRixDQUFDO0FBRUQsSUFBTyxrQkFBUTsiLAogICJuYW1lcyI6IFtdCn0K
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@checkdigit/eslint-plugin","version":"7.14.0-PR.
|
|
1
|
+
{"name":"@checkdigit/eslint-plugin","version":"7.14.0-PR.57-987f","description":"Check Digit eslint plugins","keywords":["eslint","eslintplugin"],"homepage":"https://github.com/checkdigit/eslint-plugin#readme","bugs":{"url":"https://github.com/checkdigit/eslint-plugin/issues"},"repository":{"type":"git","url":"https://github.com/checkdigit/eslint-plugin"},"license":"MIT","author":"Check Digit, LLC","sideEffects":false,"type":"module","exports":{".":{"types":"./dist-types/index.d.ts","import":"./dist-mjs/index.mjs","default":"./dist-mjs/index.mjs"}},"files":["src","dist-types","dist-mjs","!src/**/test/**","!src/**/*.test.ts","!src/**/*.spec.ts","!dist-types/**/test/**","!dist-types/**/*.test.d.ts","!dist-types/**/*.spec.d.ts","!dist-mjs/**/test/**","!dist-mjs/**/*.test.mjs","!dist-mjs/**/*.spec.mjs","SECURITY.md"],"scripts":{"build:dist-mjs":"rimraf dist-mjs && npx builder --type=module --sourceMap --outDir=dist-mjs && node dist-mjs/index.mjs","build:dist-types":"rimraf dist-types && npx builder --type=types --outDir=dist-types","ci:compile":"tsc --noEmit","ci:coverage":"NODE_OPTIONS=\"--disable-warning ExperimentalWarning --experimental-vm-modules\" jest --coverage=true","ci:lint":"npm run lint","ci:style":"npm run prettier","ci:test":"NODE_OPTIONS=\"--disable-warning ExperimentalWarning --experimental-vm-modules\" jest --coverage=false","lint":"eslint --max-warnings 0 .","lint:fix":"eslint --max-warnings 0 --fix .","prepare":"","prepublishOnly":"npm run build:dist-types && npm run build:dist-mjs","prettier":"prettier --ignore-path .gitignore --list-different .","prettier:fix":"prettier --ignore-path .gitignore --write .","test":"npm run ci:compile && npm run ci:test && npm run ci:lint && npm run ci:style"},"prettier":"@checkdigit/prettier-config","jest":{"preset":"@checkdigit/jest-config"},"dependencies":{"@typescript-eslint/type-utils":"^8.23.0","@typescript-eslint/utils":"^8.23.0","http-status-codes":"^2.3.0","ts-api-utils":"^2.0.1"},"devDependencies":{"@checkdigit/jest-config":"^6.0.2","@checkdigit/prettier-config":"^6.1.0","@checkdigit/typescript-config":"^9.0.0","@eslint/js":"^9.19.0","@types/eslint":"^9.6.1","@types/eslint-config-prettier":"^6.11.3","@typescript-eslint/parser":"^8.23.0","@typescript-eslint/rule-tester":"^8.23.0","eslint":"^9.19.0","eslint-config-prettier":"^10.0.1","eslint-import-resolver-typescript":"^3.7.0","eslint-plugin-eslint-plugin":"^6.4.0","eslint-plugin-import":"^2.31.0","eslint-plugin-no-only-tests":"^3.3.0","eslint-plugin-no-secrets":"^2.2.1","eslint-plugin-node":"^11.1.0","eslint-plugin-sonarjs":"1.0.4","rimraf":"^6.0.1","typescript-eslint":"^8.23.0"},"peerDependencies":{"eslint":">=9 <10"},"engines":{"node":">=22.14"}}
|
package/src/file-path-comment.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -32,7 +32,7 @@ import noEnum from './no-enum.ts';
|
|
|
32
32
|
import noSideEffects from './no-side-effects.ts';
|
|
33
33
|
import noRandomV4UUID from './no-random-v4-uuid.ts';
|
|
34
34
|
import noTestImport from './no-test-import.ts';
|
|
35
|
-
import
|
|
35
|
+
import noUtil from './no-util.ts';
|
|
36
36
|
import noUuid from './no-uuid.ts';
|
|
37
37
|
import noWallabyComment from './no-wallaby-comment.ts';
|
|
38
38
|
import objectLiteralResponse from './object-literal-response.ts';
|
|
@@ -48,6 +48,7 @@ const rules: Record<string, TSESLint.LooseRuleDefinition> = {
|
|
|
48
48
|
'no-enum': noEnum,
|
|
49
49
|
'no-random-v4-uuid': noRandomV4UUID,
|
|
50
50
|
'no-status-code-assert': noStatusCodeAssert,
|
|
51
|
+
'no-util': noUtil,
|
|
51
52
|
'no-uuid': noUuid,
|
|
52
53
|
'require-assert-message': requireAssertMessage,
|
|
53
54
|
'require-strict-assert': requireStrictAssert,
|
|
@@ -55,7 +56,6 @@ const rules: Record<string, TSESLint.LooseRuleDefinition> = {
|
|
|
55
56
|
'no-test-import': noTestImport,
|
|
56
57
|
'no-wallaby-comment': noWallabyComment,
|
|
57
58
|
'no-side-effects': noSideEffects,
|
|
58
|
-
'no-type-assertion-as': noTypeAssertionAs,
|
|
59
59
|
'regular-expression-comment': regexComment,
|
|
60
60
|
'require-assert-predicate-rejects-throws': requireAssertPredicateRejectsThrows,
|
|
61
61
|
'object-literal-response': objectLiteralResponse,
|
|
@@ -87,16 +87,13 @@ const configs: Record<string, TSESLint.FlatConfig.Config[]> = {
|
|
|
87
87
|
'@checkdigit/file-path-comment': 'error',
|
|
88
88
|
'@checkdigit/no-random-v4-uuid': 'error',
|
|
89
89
|
'@checkdigit/no-status-code-assert': 'error',
|
|
90
|
+
'@checkdigit/no-util': 'error',
|
|
90
91
|
'@checkdigit/no-uuid': 'error',
|
|
91
92
|
'@checkdigit/require-assert-message': 'error',
|
|
92
93
|
'@checkdigit/require-strict-assert': 'error',
|
|
93
94
|
'@checkdigit/require-ts-extension-imports-exports': 'error',
|
|
94
95
|
'@checkdigit/no-wallaby-comment': 'error',
|
|
95
|
-
'@checkdigit/no-side-effects':
|
|
96
|
-
'error',
|
|
97
|
-
{ excludedIdentifiers: ['assert', 'debug', 'log', 'promisify', 'Symbol.for'] },
|
|
98
|
-
],
|
|
99
|
-
'@checkdigit/no-type-assertion-as': 'error',
|
|
96
|
+
'@checkdigit/no-side-effects': 'error',
|
|
100
97
|
'@checkdigit/regular-expression-comment': 'error',
|
|
101
98
|
'@checkdigit/require-assert-predicate-rejects-throws': 'error',
|
|
102
99
|
'@checkdigit/object-literal-response': 'error',
|
|
@@ -125,13 +122,13 @@ const configs: Record<string, TSESLint.FlatConfig.Config[]> = {
|
|
|
125
122
|
'@checkdigit/file-path-comment': 'off',
|
|
126
123
|
'@checkdigit/no-random-v4-uuid': 'error',
|
|
127
124
|
'@checkdigit/no-status-code-assert': 'error',
|
|
125
|
+
'@checkdigit/no-util': 'error',
|
|
128
126
|
'@checkdigit/no-uuid': 'error',
|
|
129
127
|
'@checkdigit/require-assert-message': 'error',
|
|
130
128
|
'@checkdigit/require-strict-assert': 'error',
|
|
131
129
|
'@checkdigit/require-ts-extension-imports-exports': 'error',
|
|
132
130
|
'@checkdigit/no-wallaby-comment': 'off',
|
|
133
131
|
'@checkdigit/no-side-effects': 'error',
|
|
134
|
-
'@checkdigit/no-type-assertion-as': 'error',
|
|
135
132
|
'@checkdigit/regular-expression-comment': 'error',
|
|
136
133
|
'@checkdigit/require-assert-predicate-rejects-throws': 'error',
|
|
137
134
|
'@checkdigit/object-literal-response': 'error',
|
package/src/no-side-effects.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
// no-side-effects.ts
|
|
2
2
|
|
|
3
3
|
/*
|
|
4
|
-
* Copyright (c) 2022-
|
|
4
|
+
* Copyright (c) 2022-2025 Check Digit, LLC
|
|
5
5
|
*
|
|
6
6
|
* This code is licensed under the MIT license (see LICENSE.txt for details).
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
10
10
|
import { TSESTree } from '@typescript-eslint/typescript-estree';
|
|
11
|
+
import getDocumentationUrl from './get-documentation-url.ts';
|
|
11
12
|
|
|
12
13
|
interface RuleOptions {
|
|
13
14
|
excludedIdentifiers: string[];
|
|
@@ -16,61 +17,74 @@ interface RuleOptions {
|
|
|
16
17
|
export const ruleId = 'no-side-effects';
|
|
17
18
|
const NO_SIDE_EFFECTS = 'NO_SIDE_EFFECTS';
|
|
18
19
|
|
|
19
|
-
// Type
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
//
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
20
|
+
// Type guards
|
|
21
|
+
|
|
22
|
+
// Checks if a node is an ExpressionStatement
|
|
23
|
+
const isExpressionStatement = (node: TSESTree.Node): node is TSESTree.ExpressionStatement =>
|
|
24
|
+
node.type === TSESTree.AST_NODE_TYPES.ExpressionStatement;
|
|
25
|
+
|
|
26
|
+
// Checks if a statement is an AwaitExpression
|
|
27
|
+
const isAwaitExpression = (statement: TSESTree.Node): boolean =>
|
|
28
|
+
isExpressionStatement(statement) && statement.expression.type === TSESTree.AST_NODE_TYPES.AwaitExpression;
|
|
29
|
+
|
|
30
|
+
// Checks if a node is a VariableDeclaration with an AwaitExpression
|
|
31
|
+
const isVariableDeclarationAwaitExpression = (node: TSESTree.Node): boolean =>
|
|
32
|
+
node.type === TSESTree.AST_NODE_TYPES.VariableDeclaration &&
|
|
33
|
+
node.declarations.length > 0 &&
|
|
34
|
+
node.declarations[0]?.init?.type === TSESTree.AST_NODE_TYPES.AwaitExpression;
|
|
35
|
+
|
|
36
|
+
// Checks if a node is a VariableDeclaration that is not const or using
|
|
37
|
+
const isNotValidVariableDeclaration = (node: TSESTree.Node): boolean =>
|
|
38
|
+
node.type === TSESTree.AST_NODE_TYPES.VariableDeclaration && node.kind !== 'const' && node.kind !== 'using';
|
|
39
|
+
|
|
40
|
+
// Checks if a node is a control flow statement
|
|
41
|
+
const isControlFlowStatement = (node: TSESTree.Node): boolean =>
|
|
42
|
+
[
|
|
43
|
+
TSESTree.AST_NODE_TYPES.TryStatement,
|
|
44
|
+
TSESTree.AST_NODE_TYPES.IfStatement,
|
|
45
|
+
TSESTree.AST_NODE_TYPES.SwitchStatement,
|
|
46
|
+
TSESTree.AST_NODE_TYPES.ForStatement,
|
|
47
|
+
TSESTree.AST_NODE_TYPES.WhileStatement,
|
|
48
|
+
TSESTree.AST_NODE_TYPES.DoWhileStatement,
|
|
49
|
+
].includes(node.type);
|
|
50
|
+
|
|
51
|
+
// Checks if a node is an AssignmentExpression
|
|
52
|
+
const isAssignmentExpression = (node: TSESTree.Node): boolean =>
|
|
53
|
+
node.type === TSESTree.AST_NODE_TYPES.ExpressionStatement &&
|
|
54
|
+
node.expression.type === TSESTree.AST_NODE_TYPES.AssignmentExpression;
|
|
55
|
+
|
|
56
|
+
// Helper functions
|
|
57
|
+
|
|
58
|
+
// Checks if the callee is an identifier and not excluded
|
|
59
|
+
const isIdentifierCallee = (node: TSESTree.CallExpression, excludedIdentifiers: string[]): boolean =>
|
|
60
|
+
node.callee.type === TSESTree.AST_NODE_TYPES.Identifier && !excludedIdentifiers.includes(node.callee.name);
|
|
61
|
+
|
|
62
|
+
// Checks if the callee is a member expression and not excluded
|
|
63
|
+
const isMemberExpressionCallee = (node: TSESTree.CallExpression, excludedIdentifiers: string[]): boolean =>
|
|
64
|
+
node.callee.type === TSESTree.AST_NODE_TYPES.MemberExpression &&
|
|
65
|
+
node.callee.object.type === TSESTree.AST_NODE_TYPES.Identifier &&
|
|
66
|
+
node.callee.property.type === TSESTree.AST_NODE_TYPES.Identifier &&
|
|
67
|
+
!excludedIdentifiers.includes(`${node.callee.object.name}.${node.callee.property.name}`);
|
|
68
|
+
|
|
69
|
+
// Checks if the callee is a member expression with a non-identifier object
|
|
70
|
+
const isNonIdentifierObjectMemberExpressionCallee = (node: TSESTree.CallExpression): boolean =>
|
|
71
|
+
node.callee.type === TSESTree.AST_NODE_TYPES.MemberExpression &&
|
|
72
|
+
node.callee.object.type !== TSESTree.AST_NODE_TYPES.Identifier;
|
|
73
|
+
|
|
74
|
+
// Checks if a statement is a CallExpression with a member expression callee
|
|
75
|
+
const isCallExpressionCalleeMemberExpression = (statement: TSESTree.Node, excludedIdentifiers: string[]): boolean =>
|
|
76
|
+
isExpressionStatement(statement) &&
|
|
77
|
+
statement.expression.type === TSESTree.AST_NODE_TYPES.CallExpression &&
|
|
78
|
+
statement.expression.callee.type === TSESTree.AST_NODE_TYPES.MemberExpression &&
|
|
79
|
+
statement.expression.callee.object.type === TSESTree.AST_NODE_TYPES.Identifier &&
|
|
80
|
+
statement.expression.callee.property.type === TSESTree.AST_NODE_TYPES.Identifier &&
|
|
81
|
+
!excludedIdentifiers.includes(statement.expression.callee.object.name) &&
|
|
82
|
+
!excludedIdentifiers.includes(
|
|
83
|
+
`${statement.expression.callee.object.name}.${statement.expression.callee.property.name}`,
|
|
37
84
|
);
|
|
38
|
-
}
|
|
39
85
|
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
return (
|
|
43
|
-
node.type === TSESTree.AST_NODE_TYPES.VariableDeclaration &&
|
|
44
|
-
node.declarations.length > 0 &&
|
|
45
|
-
node.declarations[0]?.init?.type === TSESTree.AST_NODE_TYPES.AwaitExpression
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Helper function to check if the callee is an identifier and not excluded
|
|
50
|
-
function isIdentifierCallee(node: TSESTree.CallExpression, excludedIdentifiers: string[]): boolean {
|
|
51
|
-
return node.callee.type === TSESTree.AST_NODE_TYPES.Identifier && !excludedIdentifiers.includes(node.callee.name);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Helper function to check if the callee is a member expression and not excluded
|
|
55
|
-
function isMemberExpressionCallee(node: TSESTree.CallExpression, excludedIdentifiers: string[]): boolean {
|
|
56
|
-
return (
|
|
57
|
-
node.callee.type === TSESTree.AST_NODE_TYPES.MemberExpression &&
|
|
58
|
-
node.callee.object.type === TSESTree.AST_NODE_TYPES.Identifier &&
|
|
59
|
-
node.callee.property.type === TSESTree.AST_NODE_TYPES.Identifier &&
|
|
60
|
-
!excludedIdentifiers.includes(`${node.callee.object.name}.${node.callee.property.name}`)
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Helper function to check if the callee is a member expression with a non-identifier object
|
|
65
|
-
function isNonIdentifierObjectMemberExpressionCallee(node: TSESTree.CallExpression): boolean {
|
|
66
|
-
return (
|
|
67
|
-
node.callee.type === TSESTree.AST_NODE_TYPES.MemberExpression &&
|
|
68
|
-
node.callee.object.type !== TSESTree.AST_NODE_TYPES.Identifier
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// To check if it is a variable declaration with a call expression i.e const configuration = new Class(); or Member Expressions i.e const server = http.createServer();
|
|
73
|
-
function isVariableDeclarationCallExpression(node: TSESTree.Node, excludedIdentifiers: string[]): boolean {
|
|
86
|
+
// Checks if a node is a VariableDeclaration with a CallExpression
|
|
87
|
+
const isVariableDeclarationCallExpression = (node: TSESTree.Node, excludedIdentifiers: string[]): boolean => {
|
|
74
88
|
if (node.type !== TSESTree.AST_NODE_TYPES.VariableDeclaration || node.declarations.length === 0) {
|
|
75
89
|
return false;
|
|
76
90
|
}
|
|
@@ -80,35 +94,108 @@ function isVariableDeclarationCallExpression(node: TSESTree.Node, excludedIdenti
|
|
|
80
94
|
return false;
|
|
81
95
|
}
|
|
82
96
|
|
|
97
|
+
const callee = init.callee;
|
|
98
|
+
if (
|
|
99
|
+
callee.type === TSESTree.AST_NODE_TYPES.ArrowFunctionExpression ||
|
|
100
|
+
callee.type === TSESTree.AST_NODE_TYPES.FunctionExpression
|
|
101
|
+
) {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
|
|
83
105
|
return (
|
|
84
106
|
isIdentifierCallee(init, excludedIdentifiers) ||
|
|
85
107
|
isMemberExpressionCallee(init, excludedIdentifiers) ||
|
|
86
108
|
isNonIdentifierObjectMemberExpressionCallee(init)
|
|
87
109
|
);
|
|
88
|
-
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// Checks if an ExportNamedDeclaration has side effects
|
|
113
|
+
const isExportNamedDeclarationWithSideEffects = (statement: TSESTree.Node, excludedIdentifiers: string[]): boolean =>
|
|
114
|
+
statement.type === TSESTree.AST_NODE_TYPES.ExportNamedDeclaration &&
|
|
115
|
+
statement.declaration !== null &&
|
|
116
|
+
(isVariableDeclarationAwaitExpression(statement.declaration) ||
|
|
117
|
+
isVariableDeclarationCallExpression(statement.declaration, excludedIdentifiers));
|
|
118
|
+
|
|
119
|
+
// Checks if an ExpressionStatement has side effects
|
|
120
|
+
const isExpressionStatementWithSideEffects = (statement: TSESTree.Node, excludedIdentifiers: string[]): boolean =>
|
|
121
|
+
statement.type === TSESTree.AST_NODE_TYPES.ExpressionStatement &&
|
|
122
|
+
statement.expression.type === TSESTree.AST_NODE_TYPES.CallExpression &&
|
|
123
|
+
((statement.expression.callee.type === TSESTree.AST_NODE_TYPES.Identifier &&
|
|
124
|
+
!excludedIdentifiers.includes(statement.expression.callee.name)) ||
|
|
125
|
+
(statement.expression.callee.type === TSESTree.AST_NODE_TYPES.MemberExpression &&
|
|
126
|
+
statement.expression.callee.object.type === TSESTree.AST_NODE_TYPES.Identifier &&
|
|
127
|
+
statement.expression.callee.property.type === TSESTree.AST_NODE_TYPES.Identifier &&
|
|
128
|
+
!excludedIdentifiers.includes(
|
|
129
|
+
`${statement.expression.callee.object.name}.${statement.expression.callee.property.name}`,
|
|
130
|
+
)));
|
|
131
|
+
|
|
132
|
+
// Checks if a node is a VariableDeclaration with a NewExpression
|
|
133
|
+
const isVariableDeclarationNewExpression = (node: TSESTree.Node): boolean => {
|
|
134
|
+
if (node.type !== TSESTree.AST_NODE_TYPES.VariableDeclaration || node.declarations.length === 0) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
89
137
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
138
|
+
const init = node.declarations[0]?.init;
|
|
139
|
+
return init?.type === TSESTree.AST_NODE_TYPES.NewExpression;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// Checks if a node is a FunctionDeclaration with an AwaitExpression
|
|
143
|
+
const isFunctionDeclarationAwaitExpression = (node: TSESTree.Node): boolean =>
|
|
144
|
+
node.type === TSESTree.AST_NODE_TYPES.FunctionDeclaration &&
|
|
145
|
+
node.body.body.some(
|
|
146
|
+
(statement) =>
|
|
147
|
+
statement.type === TSESTree.AST_NODE_TYPES.ExpressionStatement &&
|
|
148
|
+
statement.expression.type === TSESTree.AST_NODE_TYPES.AwaitExpression,
|
|
101
149
|
);
|
|
102
|
-
}
|
|
103
150
|
|
|
104
|
-
|
|
151
|
+
// Update the hasSideEffects function to return a string indicating the type of side effect
|
|
152
|
+
const hasSideEffects = (statement: TSESTree.Node, excludedIdentifiers: string[]): string | null => {
|
|
153
|
+
if (isAwaitExpression(statement)) {
|
|
154
|
+
return TSESTree.AST_NODE_TYPES.AwaitExpression;
|
|
155
|
+
}
|
|
156
|
+
if (isCallExpressionCalleeMemberExpression(statement, excludedIdentifiers)) {
|
|
157
|
+
return 'CallExpressionCalleeMemberExpression';
|
|
158
|
+
}
|
|
159
|
+
if (isVariableDeclarationAwaitExpression(statement)) {
|
|
160
|
+
return 'VariableDeclarationAwaitExpression';
|
|
161
|
+
}
|
|
162
|
+
if (isVariableDeclarationCallExpression(statement, excludedIdentifiers)) {
|
|
163
|
+
return 'VariableDeclarationCallExpression';
|
|
164
|
+
}
|
|
165
|
+
if (isVariableDeclarationNewExpression(statement)) {
|
|
166
|
+
return 'VariableDeclarationNewExpression';
|
|
167
|
+
}
|
|
168
|
+
if (isExportNamedDeclarationWithSideEffects(statement, excludedIdentifiers)) {
|
|
169
|
+
return 'ExportNamedDeclarationWithSideEffects';
|
|
170
|
+
}
|
|
171
|
+
if (isExpressionStatementWithSideEffects(statement, excludedIdentifiers)) {
|
|
172
|
+
return 'ExpressionStatementWithSideEffects';
|
|
173
|
+
}
|
|
174
|
+
if (isControlFlowStatement(statement)) {
|
|
175
|
+
return 'ControlFlowStatement';
|
|
176
|
+
}
|
|
177
|
+
if (isNotValidVariableDeclaration(statement)) {
|
|
178
|
+
return 'NotValidVariableDeclaration';
|
|
179
|
+
}
|
|
180
|
+
if (isAssignmentExpression(statement)) {
|
|
181
|
+
return TSESTree.AST_NODE_TYPES.AssignmentExpression;
|
|
182
|
+
}
|
|
183
|
+
if (isFunctionDeclarationAwaitExpression(statement)) {
|
|
184
|
+
return 'FunctionDeclarationAwaitExpression';
|
|
185
|
+
}
|
|
186
|
+
return null;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const createRule: ReturnType<typeof ESLintUtils.RuleCreator> = ESLintUtils.RuleCreator((name) =>
|
|
190
|
+
getDocumentationUrl(name),
|
|
191
|
+
);
|
|
105
192
|
|
|
106
193
|
const rule: ReturnType<typeof createRule> = createRule({
|
|
107
194
|
name: ruleId,
|
|
108
195
|
meta: {
|
|
109
196
|
type: 'problem',
|
|
110
197
|
docs: {
|
|
111
|
-
description: 'Ensure no side effects can occur at the module-level',
|
|
198
|
+
description: 'Ensure no side effects can occur at the module-level only if exporting module',
|
|
112
199
|
},
|
|
113
200
|
schema: [
|
|
114
201
|
{
|
|
@@ -144,10 +231,14 @@ const rule: ReturnType<typeof createRule> = createRule({
|
|
|
144
231
|
}
|
|
145
232
|
|
|
146
233
|
node.body.forEach((statement: TSESTree.Node) => {
|
|
147
|
-
|
|
234
|
+
const sideEffectType = hasSideEffects(statement, excludedIdentifiers);
|
|
235
|
+
if (sideEffectType !== null) {
|
|
148
236
|
context.report({
|
|
149
237
|
node: statement,
|
|
150
238
|
messageId: NO_SIDE_EFFECTS,
|
|
239
|
+
data: {
|
|
240
|
+
sideEffectType,
|
|
241
|
+
},
|
|
151
242
|
});
|
|
152
243
|
}
|
|
153
244
|
});
|
package/src/no-util.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// no-util.ts
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2021-2025 Check Digit, LLC
|
|
5
|
+
*
|
|
6
|
+
* This code is licensed under the MIT license (see LICENSE.txt for details).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { AST_TOKEN_TYPES, ESLintUtils } from '@typescript-eslint/utils';
|
|
10
|
+
|
|
11
|
+
export const ruleId = 'no-util';
|
|
12
|
+
const NO_UTIL = 'NO_UTIL';
|
|
13
|
+
|
|
14
|
+
const createRule = ESLintUtils.RuleCreator((name) => name);
|
|
15
|
+
|
|
16
|
+
const rule: ESLintUtils.RuleModule<typeof NO_UTIL> = createRule({
|
|
17
|
+
name: ruleId,
|
|
18
|
+
meta: {
|
|
19
|
+
type: 'problem',
|
|
20
|
+
docs: {
|
|
21
|
+
description: 'Detects if file name is util',
|
|
22
|
+
},
|
|
23
|
+
schema: [],
|
|
24
|
+
messages: {
|
|
25
|
+
[NO_UTIL]: "File name '{{filename}}' contains banned 'util' pattern.",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
defaultOptions: [],
|
|
29
|
+
create(context) {
|
|
30
|
+
return {
|
|
31
|
+
Program() {
|
|
32
|
+
const filename = context.filename;
|
|
33
|
+
const utilRegex = /(?:^|[-_/])util(?=[-_./]|$)/iu;
|
|
34
|
+
if (utilRegex.test(filename)) {
|
|
35
|
+
const sourceCode = context.sourceCode;
|
|
36
|
+
const tokens = sourceCode.tokensAndComments;
|
|
37
|
+
const firstNonCommentToken = tokens.find(
|
|
38
|
+
(token) => token.type !== AST_TOKEN_TYPES.Block && token.type !== AST_TOKEN_TYPES.Line,
|
|
39
|
+
);
|
|
40
|
+
if (firstNonCommentToken !== undefined) {
|
|
41
|
+
context.report({
|
|
42
|
+
messageId: NO_UTIL,
|
|
43
|
+
data: { filename },
|
|
44
|
+
node: firstNonCommentToken,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
export default rule;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
// src/no-type-assertion-as.ts
|
|
2
|
-
import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
|
|
3
|
-
var ruleId = "no-as-type-assertion";
|
|
4
|
-
var NO_AS_TYPE_ASSERTION = "NO_AS_TYPE_ASSERTION";
|
|
5
|
-
var createRule = ESLintUtils.RuleCreator((name) => name);
|
|
6
|
-
var rule = createRule({
|
|
7
|
-
name: ruleId,
|
|
8
|
-
meta: {
|
|
9
|
-
type: "problem",
|
|
10
|
-
docs: {
|
|
11
|
-
description: "Disallow the use of `as` type assertions and suggest using `satisfies` instead"
|
|
12
|
-
},
|
|
13
|
-
schema: [],
|
|
14
|
-
messages: {
|
|
15
|
-
[NO_AS_TYPE_ASSERTION]: "Avoid using `as` type assertions. Use `satisfies` instead."
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
defaultOptions: [],
|
|
19
|
-
create(context) {
|
|
20
|
-
return {
|
|
21
|
-
TSAsExpression(node) {
|
|
22
|
-
const isUnknownUnionOrIntersection = (node.typeAnnotation.type === AST_NODE_TYPES.TSUnionType || node.typeAnnotation.type === AST_NODE_TYPES.TSIntersectionType) && node.typeAnnotation.types.some((type) => type.type === AST_NODE_TYPES.TSUnknownKeyword);
|
|
23
|
-
if (node.typeAnnotation.type === AST_NODE_TYPES.TSUnknownKeyword || node.expression.type === AST_NODE_TYPES.TSAsExpression && node.expression.typeAnnotation.type === AST_NODE_TYPES.TSUnknownKeyword || isUnknownUnionOrIntersection) {
|
|
24
|
-
if (node.parent.type !== AST_NODE_TYPES.TSAsExpression) {
|
|
25
|
-
context.report({
|
|
26
|
-
node,
|
|
27
|
-
messageId: NO_AS_TYPE_ASSERTION
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
} else {
|
|
31
|
-
context.report({
|
|
32
|
-
node,
|
|
33
|
-
messageId: NO_AS_TYPE_ASSERTION
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
var no_type_assertion_as_default = rule;
|
|
41
|
-
export {
|
|
42
|
-
no_type_assertion_as_default as default,
|
|
43
|
-
ruleId
|
|
44
|
-
};
|
|
45
|
-
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL25vLXR5cGUtYXNzZXJ0aW9uLWFzLnRzIl0sCiAgIm1hcHBpbmdzIjogIjtBQVFBLFNBQVMsZ0JBQWdCLG1CQUE2QjtBQUUvQyxJQUFNLFNBQVM7QUFDdEIsSUFBTSx1QkFBdUI7QUFFN0IsSUFBTSxhQUFhLFlBQVksWUFBWSxDQUFDLFNBQVMsSUFBSTtBQUV6RCxJQUFNLE9BQTRELFdBQVc7QUFBQSxFQUMzRSxNQUFNO0FBQUEsRUFDTixNQUFNO0FBQUEsSUFDSixNQUFNO0FBQUEsSUFDTixNQUFNO0FBQUEsTUFDSixhQUFhO0FBQUEsSUFDZjtBQUFBLElBQ0EsUUFBUSxDQUFDO0FBQUEsSUFDVCxVQUFVO0FBQUEsTUFDUixDQUFDLG9CQUFvQixHQUFHO0FBQUEsSUFDMUI7QUFBQSxFQUNGO0FBQUEsRUFDQSxnQkFBZ0IsQ0FBQztBQUFBLEVBQ2pCLE9BQU8sU0FBUztBQUNkLFdBQU87QUFBQSxNQUNMLGVBQWUsTUFBK0I7QUFDNUMsY0FBTSxnQ0FDSCxLQUFLLGVBQWUsU0FBUyxlQUFlLGVBQzNDLEtBQUssZUFBZSxTQUFTLGVBQWUsdUJBQzlDLEtBQUssZUFBZSxNQUFNLEtBQUssQ0FBQyxTQUFTLEtBQUssU0FBUyxlQUFlLGdCQUFnQjtBQUV4RixZQUNFLEtBQUssZUFBZSxTQUFTLGVBQWUsb0JBQzNDLEtBQUssV0FBVyxTQUFTLGVBQWUsa0JBQ3ZDLEtBQUssV0FBVyxlQUFlLFNBQVMsZUFBZSxvQkFDekQsOEJBQ0E7QUFDQSxjQUFJLEtBQUssT0FBTyxTQUFTLGVBQWUsZ0JBQWdCO0FBQ3RELG9CQUFRLE9BQU87QUFBQSxjQUNiO0FBQUEsY0FDQSxXQUFXO0FBQUEsWUFDYixDQUFDO0FBQUEsVUFDSDtBQUFBLFFBQ0YsT0FBTztBQUNMLGtCQUFRLE9BQU87QUFBQSxZQUNiO0FBQUEsWUFDQSxXQUFXO0FBQUEsVUFDYixDQUFDO0FBQUEsUUFDSDtBQUFBLE1BQ0Y7QUFBQSxJQUNGO0FBQUEsRUFDRjtBQUNGLENBQUM7QUFFRCxJQUFPLCtCQUFROyIsCiAgIm5hbWVzIjogW10KfQo=
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
-
export declare const ruleId = "no-as-type-assertion";
|
|
3
|
-
declare const NO_AS_TYPE_ASSERTION = "NO_AS_TYPE_ASSERTION";
|
|
4
|
-
declare const rule: ESLintUtils.RuleModule<typeof NO_AS_TYPE_ASSERTION>;
|
|
5
|
-
export default rule;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
// no-type-assertion-as.ts
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
* Copyright (c) 2021-2025 Check Digit, LLC
|
|
5
|
-
*
|
|
6
|
-
* This code is licensed under the MIT license (see LICENSE.txt for details).
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { AST_NODE_TYPES, ESLintUtils, TSESTree } from '@typescript-eslint/utils';
|
|
10
|
-
|
|
11
|
-
export const ruleId = 'no-as-type-assertion';
|
|
12
|
-
const NO_AS_TYPE_ASSERTION = 'NO_AS_TYPE_ASSERTION';
|
|
13
|
-
|
|
14
|
-
const createRule = ESLintUtils.RuleCreator((name) => name);
|
|
15
|
-
|
|
16
|
-
const rule: ESLintUtils.RuleModule<typeof NO_AS_TYPE_ASSERTION> = createRule({
|
|
17
|
-
name: ruleId,
|
|
18
|
-
meta: {
|
|
19
|
-
type: 'problem',
|
|
20
|
-
docs: {
|
|
21
|
-
description: 'Disallow the use of `as` type assertions and suggest using `satisfies` instead',
|
|
22
|
-
},
|
|
23
|
-
schema: [],
|
|
24
|
-
messages: {
|
|
25
|
-
[NO_AS_TYPE_ASSERTION]: 'Avoid using `as` type assertions. Use `satisfies` instead.',
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
defaultOptions: [],
|
|
29
|
-
create(context) {
|
|
30
|
-
return {
|
|
31
|
-
TSAsExpression(node: TSESTree.TSAsExpression) {
|
|
32
|
-
const isUnknownUnionOrIntersection =
|
|
33
|
-
(node.typeAnnotation.type === AST_NODE_TYPES.TSUnionType ||
|
|
34
|
-
node.typeAnnotation.type === AST_NODE_TYPES.TSIntersectionType) &&
|
|
35
|
-
node.typeAnnotation.types.some((type) => type.type === AST_NODE_TYPES.TSUnknownKeyword);
|
|
36
|
-
|
|
37
|
-
if (
|
|
38
|
-
node.typeAnnotation.type === AST_NODE_TYPES.TSUnknownKeyword ||
|
|
39
|
-
(node.expression.type === AST_NODE_TYPES.TSAsExpression &&
|
|
40
|
-
node.expression.typeAnnotation.type === AST_NODE_TYPES.TSUnknownKeyword) ||
|
|
41
|
-
isUnknownUnionOrIntersection
|
|
42
|
-
) {
|
|
43
|
-
if (node.parent.type !== AST_NODE_TYPES.TSAsExpression) {
|
|
44
|
-
context.report({
|
|
45
|
-
node,
|
|
46
|
-
messageId: NO_AS_TYPE_ASSERTION,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
} else {
|
|
50
|
-
context.report({
|
|
51
|
-
node,
|
|
52
|
-
messageId: NO_AS_TYPE_ASSERTION,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
export default rule;
|