@checkdigit/eslint-plugin 7.7.1-PR.101-95b3 → 7.8.0-PR.79-d6b4
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 +1 -0
- package/dist-mjs/index.mjs +6 -5
- package/dist-mjs/no-enum.mjs +52 -0
- package/dist-mjs/no-side-effects.mjs +3 -28
- package/dist-types/no-enum.d.ts +5 -0
- package/package.json +1 -1
- package/src/index.ts +5 -4
- package/src/no-enum.ts +68 -0
- package/src/no-side-effects.ts +15 -63
package/README.md
CHANGED
|
@@ -21,6 +21,7 @@ Copyright (c) 2021-2024 [Check Digit, LLC](https://checkdigit.com)
|
|
|
21
21
|
- `@checkdigit/require-resolve-full-response`
|
|
22
22
|
- `@checkdigit/require-type-out-of-type-only-imports`
|
|
23
23
|
- `@checkdigit/require-ts-extension-imports`
|
|
24
|
+
- `@checkdigit/no-enum`
|
|
24
25
|
|
|
25
26
|
## Configurations
|
|
26
27
|
|
package/dist-mjs/index.mjs
CHANGED
|
@@ -15,6 +15,7 @@ import requireTypeOutOfTypeOnlyImports, {
|
|
|
15
15
|
import noServeRuntime, { ruleId as noServeRuntimeRuleId } from "./no-serve-runtime.mjs";
|
|
16
16
|
import filePathComment from "./file-path-comment.mjs";
|
|
17
17
|
import noCardNumbers from "./no-card-numbers.mjs";
|
|
18
|
+
import noEnum from "./no-enum.mjs";
|
|
18
19
|
import noSideEffects from "./no-side-effects.mjs";
|
|
19
20
|
import noRandomV4UUID from "./no-random-v4-uuid.mjs";
|
|
20
21
|
import noTestImport from "./no-test-import.mjs";
|
|
@@ -28,6 +29,7 @@ import requireTsExtensionImports from "./require-ts-extension-imports.mjs";
|
|
|
28
29
|
var rules = {
|
|
29
30
|
"file-path-comment": filePathComment,
|
|
30
31
|
"no-card-numbers": noCardNumbers,
|
|
32
|
+
"no-enum": noEnum,
|
|
31
33
|
"no-random-v4-uuid": noRandomV4UUID,
|
|
32
34
|
"no-uuid": noUuid,
|
|
33
35
|
"require-strict-assert": requireStrictAssert,
|
|
@@ -59,16 +61,14 @@ var configs = {
|
|
|
59
61
|
},
|
|
60
62
|
rules: {
|
|
61
63
|
"@checkdigit/no-card-numbers": "error",
|
|
64
|
+
"@checkdigit/no-enum": "error",
|
|
62
65
|
"@checkdigit/file-path-comment": "error",
|
|
63
66
|
"@checkdigit/no-random-v4-uuid": "error",
|
|
64
67
|
"@checkdigit/no-uuid": "error",
|
|
65
68
|
"@checkdigit/require-strict-assert": "error",
|
|
66
69
|
"@checkdigit/require-ts-extension-imports": "error",
|
|
67
70
|
"@checkdigit/no-wallaby-comment": "error",
|
|
68
|
-
"@checkdigit/no-side-effects": [
|
|
69
|
-
"error",
|
|
70
|
-
{ excludedIdentifiers: ["assert", "debug", "log", "promisify", "Symbol.for"] }
|
|
71
|
-
],
|
|
71
|
+
"@checkdigit/no-side-effects": ["error", { excludedIdentifiers: ["assert", "debug", "log", "promisify"] }],
|
|
72
72
|
"@checkdigit/regular-expression-comment": "error",
|
|
73
73
|
"@checkdigit/require-assert-predicate-rejects-throws": "error",
|
|
74
74
|
"@checkdigit/object-literal-response": "error",
|
|
@@ -92,6 +92,7 @@ var configs = {
|
|
|
92
92
|
},
|
|
93
93
|
rules: {
|
|
94
94
|
"@checkdigit/no-card-numbers": "error",
|
|
95
|
+
"@checkdigit/no-enum": "error",
|
|
95
96
|
"@checkdigit/file-path-comment": "off",
|
|
96
97
|
"@checkdigit/no-random-v4-uuid": "error",
|
|
97
98
|
"@checkdigit/no-uuid": "error",
|
|
@@ -123,4 +124,4 @@ var src_default = defaultToExport;
|
|
|
123
124
|
export {
|
|
124
125
|
src_default as default
|
|
125
126
|
};
|
|
126
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
127
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL2luZGV4LnRzIl0sCiAgIm1hcHBpbmdzIjogIjtBQVVBLE9BQU8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QUFDLGVBQWUscUNBQXFDLEVBQUUsR0FBRztBQUFBLFFBQzFELENBQUMsZUFBZSxvQkFBb0IsRUFBRSxHQUFHO0FBQUEsTUFDM0M7QUFBQSxJQUNGO0FBQUEsRUFDRjtBQUNGO0FBRUEsSUFBTSxrQkFFRjtBQUFBLEVBQ0YsR0FBRztBQUFBLEVBQ0g7QUFDRjtBQUNBLElBQU8sY0FBUTsiLAogICJuYW1lcyI6IFtdCn0K
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// src/no-enum.ts
|
|
2
|
+
import { ESLintUtils, TSESTree } from "@typescript-eslint/utils";
|
|
3
|
+
var ruleId = "no-enum";
|
|
4
|
+
var NO_ENUM = "NO_ENUM";
|
|
5
|
+
var createRule = ESLintUtils.RuleCreator((name) => name);
|
|
6
|
+
function isJsonSchemaProperty(node) {
|
|
7
|
+
if (!node) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
if (node.type === TSESTree.AST_NODE_TYPES.Property && node.key.type === TSESTree.AST_NODE_TYPES.Identifier && node.key.name === "properties") {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
return isJsonSchemaProperty(node.parent);
|
|
14
|
+
}
|
|
15
|
+
var rule = createRule({
|
|
16
|
+
name: ruleId,
|
|
17
|
+
meta: {
|
|
18
|
+
type: "problem",
|
|
19
|
+
docs: {
|
|
20
|
+
description: "Disallow the use of `enum` in TypeScript"
|
|
21
|
+
},
|
|
22
|
+
schema: [],
|
|
23
|
+
messages: {
|
|
24
|
+
[NO_ENUM]: "Avoid using `enum` in TypeScript."
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
defaultOptions: [],
|
|
28
|
+
create(context) {
|
|
29
|
+
return {
|
|
30
|
+
TSEnumDeclaration(node) {
|
|
31
|
+
context.report({
|
|
32
|
+
node,
|
|
33
|
+
messageId: NO_ENUM
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
Property(node) {
|
|
37
|
+
if (node.key.type === TSESTree.AST_NODE_TYPES.Identifier && node.key.name === "enum" && node.value.type === TSESTree.AST_NODE_TYPES.ArrayExpression && !isJsonSchemaProperty(node.parent)) {
|
|
38
|
+
context.report({
|
|
39
|
+
node,
|
|
40
|
+
messageId: NO_ENUM
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
var no_enum_default = rule;
|
|
48
|
+
export {
|
|
49
|
+
no_enum_default as default,
|
|
50
|
+
ruleId
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL25vLWVudW0udHMiXSwKICAibWFwcGluZ3MiOiAiO0FBUUEsU0FBUyxhQUFhLGdCQUFnQjtBQUUvQixJQUFNLFNBQVM7QUFDdEIsSUFBTSxVQUFVO0FBRWhCLElBQU0sYUFBYSxZQUFZLFlBQVksQ0FBQyxTQUFTLElBQUk7QUFFekQsU0FBUyxxQkFBcUIsTUFBK0I7QUFDM0QsTUFBSSxDQUFDLE1BQU07QUFDVCxXQUFPO0FBQUEsRUFDVDtBQUNBLE1BQ0UsS0FBSyxTQUFTLFNBQVMsZUFBZSxZQUN0QyxLQUFLLElBQUksU0FBUyxTQUFTLGVBQWUsY0FDMUMsS0FBSyxJQUFJLFNBQVMsY0FDbEI7QUFDQSxXQUFPO0FBQUEsRUFDVDtBQUNBLFNBQU8scUJBQXFCLEtBQUssTUFBTTtBQUN6QztBQUVBLElBQU0sT0FBK0MsV0FBVztBQUFBLEVBQzlELE1BQU07QUFBQSxFQUNOLE1BQU07QUFBQSxJQUNKLE1BQU07QUFBQSxJQUNOLE1BQU07QUFBQSxNQUNKLGFBQWE7QUFBQSxJQUNmO0FBQUEsSUFDQSxRQUFRLENBQUM7QUFBQSxJQUNULFVBQVU7QUFBQSxNQUNSLENBQUMsT0FBTyxHQUFHO0FBQUEsSUFDYjtBQUFBLEVBQ0Y7QUFBQSxFQUNBLGdCQUFnQixDQUFDO0FBQUEsRUFDakIsT0FBTyxTQUFTO0FBQ2QsV0FBTztBQUFBLE1BQ0wsa0JBQWtCLE1BQWtDO0FBQ2xELGdCQUFRLE9BQU87QUFBQSxVQUNiO0FBQUEsVUFDQSxXQUFXO0FBQUEsUUFDYixDQUFDO0FBQUEsTUFDSDtBQUFBLE1BQ0EsU0FBUyxNQUF5QjtBQUNoQyxZQUNFLEtBQUssSUFBSSxTQUFTLFNBQVMsZUFBZSxjQUMxQyxLQUFLLElBQUksU0FBUyxVQUNsQixLQUFLLE1BQU0sU0FBUyxTQUFTLGVBQWUsbUJBQzVDLENBQUMscUJBQXFCLEtBQUssTUFBTSxHQUNqQztBQUNBLGtCQUFRLE9BQU87QUFBQSxZQUNiO0FBQUEsWUFDQSxXQUFXO0FBQUEsVUFDYixDQUFDO0FBQUEsUUFDSDtBQUFBLE1BQ0Y7QUFBQSxJQUNGO0FBQUEsRUFDRjtBQUNGLENBQUM7QUFFRCxJQUFPLGtCQUFROyIsCiAgIm5hbWVzIjogW10KfQo=
|
|
@@ -15,27 +15,8 @@ function isCallExpressionCalleeMemberExpression(statement, excludedIdentifiers)
|
|
|
15
15
|
function isVariableDeclarationAwaitExpression(node) {
|
|
16
16
|
return node.type === TSESTree.AST_NODE_TYPES.VariableDeclaration && node.declarations.length > 0 && node.declarations[0]?.init?.type === TSESTree.AST_NODE_TYPES.AwaitExpression;
|
|
17
17
|
}
|
|
18
|
-
function isIdentifierCallee(node, excludedIdentifiers) {
|
|
19
|
-
return node.callee.type === TSESTree.AST_NODE_TYPES.Identifier && !excludedIdentifiers.includes(node.callee.name);
|
|
20
|
-
}
|
|
21
|
-
function isMemberExpressionCallee(node, excludedIdentifiers) {
|
|
22
|
-
return 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}`);
|
|
23
|
-
}
|
|
24
|
-
function isNonIdentifierObjectMemberExpressionCallee(node) {
|
|
25
|
-
return node.callee.type === TSESTree.AST_NODE_TYPES.MemberExpression && node.callee.object.type !== TSESTree.AST_NODE_TYPES.Identifier;
|
|
26
|
-
}
|
|
27
18
|
function isVariableDeclarationCallExpression(node, excludedIdentifiers) {
|
|
28
|
-
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
const init = node.declarations[0]?.init;
|
|
32
|
-
if (init?.type !== TSESTree.AST_NODE_TYPES.CallExpression) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
return isIdentifierCallee(init, excludedIdentifiers) || isMemberExpressionCallee(init, excludedIdentifiers) || isNonIdentifierObjectMemberExpressionCallee(init);
|
|
36
|
-
}
|
|
37
|
-
function hasSideEffects(statement, excludedIdentifiers) {
|
|
38
|
-
return isAwaitExpression(statement) || isCallExpressionCalleeMemberExpression(statement, excludedIdentifiers) || isVariableDeclarationAwaitExpression(statement) || isVariableDeclarationCallExpression(statement, excludedIdentifiers) || statement.type === TSESTree.AST_NODE_TYPES.ExportNamedDeclaration && statement.declaration !== null && (isVariableDeclarationAwaitExpression(statement.declaration) || isVariableDeclarationCallExpression(statement.declaration, excludedIdentifiers));
|
|
19
|
+
return node.type === TSESTree.AST_NODE_TYPES.VariableDeclaration && node.declarations.length > 0 && node.declarations[0]?.init?.type === TSESTree.AST_NODE_TYPES.CallExpression && (node.declarations[0].init.callee.type === TSESTree.AST_NODE_TYPES.Identifier && !excludedIdentifiers.includes(node.declarations[0].init.callee.name) || node.declarations[0].init.callee.type === TSESTree.AST_NODE_TYPES.MemberExpression);
|
|
39
20
|
}
|
|
40
21
|
var createRule = ESLintUtils.RuleCreator((name) => name);
|
|
41
22
|
var rule = createRule({
|
|
@@ -67,14 +48,8 @@ var rule = createRule({
|
|
|
67
48
|
const excludedIdentifiers = options.excludedIdentifiers.length > 0 ? options.excludedIdentifiers : [];
|
|
68
49
|
return {
|
|
69
50
|
Program(node) {
|
|
70
|
-
const hasExport = node.body.some(
|
|
71
|
-
(statement) => statement.type === TSESTree.AST_NODE_TYPES.ExportNamedDeclaration || statement.type === TSESTree.AST_NODE_TYPES.ExportDefaultDeclaration || statement.type === TSESTree.AST_NODE_TYPES.ExportAllDeclaration
|
|
72
|
-
);
|
|
73
|
-
if (!hasExport) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
51
|
node.body.forEach((statement) => {
|
|
77
|
-
if (
|
|
52
|
+
if (isAwaitExpression(statement) || isCallExpressionCalleeMemberExpression(statement, excludedIdentifiers) || isVariableDeclarationAwaitExpression(statement) || isVariableDeclarationCallExpression(statement, excludedIdentifiers)) {
|
|
78
53
|
context.report({
|
|
79
54
|
node: statement,
|
|
80
55
|
messageId: NO_SIDE_EFFECTS
|
|
@@ -90,4 +65,4 @@ export {
|
|
|
90
65
|
no_side_effects_default as default,
|
|
91
66
|
ruleId
|
|
92
67
|
};
|
|
93
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
68
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL25vLXNpZGUtZWZmZWN0cy50cyJdLAogICJtYXBwaW5ncyI6ICI7QUFRQSxTQUFTLG1CQUFtQjtBQUM1QixTQUFTLGdCQUFnQjtBQU1sQixJQUFNLFNBQVM7QUFDdEIsSUFBTSxrQkFBa0I7QUFHeEIsU0FBUyxzQkFBc0IsTUFBMkQ7QUFDeEYsU0FBTyxLQUFLLFNBQVMsU0FBUyxlQUFlO0FBQy9DO0FBR0EsU0FBUyxrQkFBa0IsV0FBbUM7QUFDNUQsU0FBTyxzQkFBc0IsU0FBUyxLQUFLLFVBQVUsV0FBVyxTQUFTLFNBQVMsZUFBZTtBQUNuRztBQUdBLFNBQVMsdUNBQXVDLFdBQTBCLHFCQUF3QztBQUNoSCxTQUNFLHNCQU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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.18.1","@typescript-eslint/utils":"^8.18.1","ts-api-utils":"^2.0.0"},"devDependencies":{"@checkdigit/jest-config":"^6.0.2","@checkdigit/prettier-config":"^6.0.0","@checkdigit/typescript-config":"^9.0.0","@eslint/js":"^9.17.0","@types/eslint":"^9.6.1","@types/eslint-config-prettier":"^6.11.3","@typescript-eslint/parser":"^8.18.1","@typescript-eslint/rule-tester":"^8.18.1","eslint":"^9.17.0","eslint-config-prettier":"^9.1.0","eslint-import-resolver-typescript":"^3.7.0","eslint-plugin-eslint-plugin":"^6.3.2","eslint-plugin-import":"^2.31.0","eslint-plugin-no-only-tests":"^3.3.0","eslint-plugin-no-secrets":"^2.1.1","eslint-plugin-node":"^11.1.0","eslint-plugin-sonarjs":"1.0.4","http-status-codes":"^2.3.0","rimraf":"^6.0.1","typescript-eslint":"^8.18.1"},"peerDependencies":{"eslint":">=9 <10"},"engines":{"node":">=20.17"}}
|
package/src/index.ts
CHANGED
|
@@ -24,6 +24,7 @@ import requireTypeOutOfTypeOnlyImports, {
|
|
|
24
24
|
import noServeRuntime, { ruleId as noServeRuntimeRuleId } from './no-serve-runtime.ts';
|
|
25
25
|
import filePathComment from './file-path-comment.ts';
|
|
26
26
|
import noCardNumbers from './no-card-numbers.ts';
|
|
27
|
+
import noEnum from './no-enum.ts';
|
|
27
28
|
import noSideEffects from './no-side-effects.ts';
|
|
28
29
|
import noRandomV4UUID from './no-random-v4-uuid.ts';
|
|
29
30
|
import noTestImport from './no-test-import.ts';
|
|
@@ -38,6 +39,7 @@ import requireTsExtensionImports from './require-ts-extension-imports';
|
|
|
38
39
|
const rules: Record<string, TSESLint.LooseRuleDefinition> = {
|
|
39
40
|
'file-path-comment': filePathComment,
|
|
40
41
|
'no-card-numbers': noCardNumbers,
|
|
42
|
+
'no-enum': noEnum,
|
|
41
43
|
'no-random-v4-uuid': noRandomV4UUID,
|
|
42
44
|
'no-uuid': noUuid,
|
|
43
45
|
'require-strict-assert': requireStrictAssert,
|
|
@@ -71,16 +73,14 @@ const configs: Record<string, TSESLint.FlatConfig.Config[]> = {
|
|
|
71
73
|
},
|
|
72
74
|
rules: {
|
|
73
75
|
'@checkdigit/no-card-numbers': 'error',
|
|
76
|
+
'@checkdigit/no-enum': 'error',
|
|
74
77
|
'@checkdigit/file-path-comment': 'error',
|
|
75
78
|
'@checkdigit/no-random-v4-uuid': 'error',
|
|
76
79
|
'@checkdigit/no-uuid': 'error',
|
|
77
80
|
'@checkdigit/require-strict-assert': 'error',
|
|
78
81
|
'@checkdigit/require-ts-extension-imports': 'error',
|
|
79
82
|
'@checkdigit/no-wallaby-comment': 'error',
|
|
80
|
-
'@checkdigit/no-side-effects': [
|
|
81
|
-
'error',
|
|
82
|
-
{ excludedIdentifiers: ['assert', 'debug', 'log', 'promisify', 'Symbol.for'] },
|
|
83
|
-
],
|
|
83
|
+
'@checkdigit/no-side-effects': ['error', { excludedIdentifiers: ['assert', 'debug', 'log', 'promisify'] }],
|
|
84
84
|
'@checkdigit/regular-expression-comment': 'error',
|
|
85
85
|
'@checkdigit/require-assert-predicate-rejects-throws': 'error',
|
|
86
86
|
'@checkdigit/object-literal-response': 'error',
|
|
@@ -104,6 +104,7 @@ const configs: Record<string, TSESLint.FlatConfig.Config[]> = {
|
|
|
104
104
|
},
|
|
105
105
|
rules: {
|
|
106
106
|
'@checkdigit/no-card-numbers': 'error',
|
|
107
|
+
'@checkdigit/no-enum': 'error',
|
|
107
108
|
'@checkdigit/file-path-comment': 'off',
|
|
108
109
|
'@checkdigit/no-random-v4-uuid': 'error',
|
|
109
110
|
'@checkdigit/no-uuid': 'error',
|
package/src/no-enum.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// no-enum.ts
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2021-2024 Check Digit, LLC
|
|
5
|
+
*
|
|
6
|
+
* This code is licensed under the MIT license (see LICENSE.txt for details).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { ESLintUtils, TSESTree } from '@typescript-eslint/utils';
|
|
10
|
+
|
|
11
|
+
export const ruleId = 'no-enum';
|
|
12
|
+
const NO_ENUM = 'NO_ENUM';
|
|
13
|
+
|
|
14
|
+
const createRule = ESLintUtils.RuleCreator((name) => name);
|
|
15
|
+
|
|
16
|
+
function isJsonSchemaProperty(node?: TSESTree.Node): boolean {
|
|
17
|
+
if (!node) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
if (
|
|
21
|
+
node.type === TSESTree.AST_NODE_TYPES.Property &&
|
|
22
|
+
node.key.type === TSESTree.AST_NODE_TYPES.Identifier &&
|
|
23
|
+
node.key.name === 'properties'
|
|
24
|
+
) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
return isJsonSchemaProperty(node.parent);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const rule: ESLintUtils.RuleModule<typeof NO_ENUM> = createRule({
|
|
31
|
+
name: ruleId,
|
|
32
|
+
meta: {
|
|
33
|
+
type: 'problem',
|
|
34
|
+
docs: {
|
|
35
|
+
description: 'Disallow the use of `enum` in TypeScript',
|
|
36
|
+
},
|
|
37
|
+
schema: [],
|
|
38
|
+
messages: {
|
|
39
|
+
[NO_ENUM]: 'Avoid using `enum` in TypeScript.',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
defaultOptions: [],
|
|
43
|
+
create(context) {
|
|
44
|
+
return {
|
|
45
|
+
TSEnumDeclaration(node: TSESTree.TSEnumDeclaration) {
|
|
46
|
+
context.report({
|
|
47
|
+
node,
|
|
48
|
+
messageId: NO_ENUM,
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
Property(node: TSESTree.Property) {
|
|
52
|
+
if (
|
|
53
|
+
node.key.type === TSESTree.AST_NODE_TYPES.Identifier &&
|
|
54
|
+
node.key.name === 'enum' &&
|
|
55
|
+
node.value.type === TSESTree.AST_NODE_TYPES.ArrayExpression &&
|
|
56
|
+
!isJsonSchemaProperty(node.parent)
|
|
57
|
+
) {
|
|
58
|
+
context.report({
|
|
59
|
+
node,
|
|
60
|
+
messageId: NO_ENUM,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
export default rule;
|
package/src/no-side-effects.ts
CHANGED
|
@@ -46,58 +46,15 @@ function isVariableDeclarationAwaitExpression(node: TSESTree.Node): boolean {
|
|
|
46
46
|
);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
//
|
|
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();
|
|
49
|
+
// To check if it is a variable declaration with a call expression
|
|
73
50
|
function isVariableDeclarationCallExpression(node: TSESTree.Node, excludedIdentifiers: string[]): boolean {
|
|
74
|
-
if (node.type !== TSESTree.AST_NODE_TYPES.VariableDeclaration || node.declarations.length === 0) {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const init = node.declarations[0]?.init;
|
|
79
|
-
if (init?.type !== TSESTree.AST_NODE_TYPES.CallExpression) {
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return (
|
|
84
|
-
isIdentifierCallee(init, excludedIdentifiers) ||
|
|
85
|
-
isMemberExpressionCallee(init, excludedIdentifiers) ||
|
|
86
|
-
isNonIdentifierObjectMemberExpressionCallee(init)
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Helper function to check if a given AST node (statement) has any side effects that should be reported
|
|
91
|
-
function hasSideEffects(statement: TSESTree.Node, excludedIdentifiers: string[]): boolean {
|
|
92
51
|
return (
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
(isVariableDeclarationAwaitExpression(statement.declaration) ||
|
|
100
|
-
isVariableDeclarationCallExpression(statement.declaration, excludedIdentifiers)))
|
|
52
|
+
node.type === TSESTree.AST_NODE_TYPES.VariableDeclaration &&
|
|
53
|
+
node.declarations.length > 0 &&
|
|
54
|
+
node.declarations[0]?.init?.type === TSESTree.AST_NODE_TYPES.CallExpression &&
|
|
55
|
+
((node.declarations[0].init.callee.type === TSESTree.AST_NODE_TYPES.Identifier &&
|
|
56
|
+
!excludedIdentifiers.includes(node.declarations[0].init.callee.name)) ||
|
|
57
|
+
node.declarations[0].init.callee.type === TSESTree.AST_NODE_TYPES.MemberExpression)
|
|
101
58
|
);
|
|
102
59
|
}
|
|
103
60
|
|
|
@@ -130,21 +87,16 @@ const rule: ReturnType<typeof createRule> = createRule({
|
|
|
130
87
|
create(context) {
|
|
131
88
|
const options: RuleOptions = context.options[0] as RuleOptions;
|
|
132
89
|
const excludedIdentifiers = options.excludedIdentifiers.length > 0 ? options.excludedIdentifiers : [];
|
|
90
|
+
|
|
133
91
|
return {
|
|
134
92
|
Program(node: TSESTree.Program) {
|
|
135
|
-
|
|
136
|
-
(
|
|
137
|
-
statement
|
|
138
|
-
statement
|
|
139
|
-
statement
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if (!hasExport) {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
node.body.forEach((statement: TSESTree.Node) => {
|
|
147
|
-
if (hasSideEffects(statement, excludedIdentifiers)) {
|
|
93
|
+
node.body.forEach((statement) => {
|
|
94
|
+
if (
|
|
95
|
+
isAwaitExpression(statement) ||
|
|
96
|
+
isCallExpressionCalleeMemberExpression(statement, excludedIdentifiers) ||
|
|
97
|
+
isVariableDeclarationAwaitExpression(statement) ||
|
|
98
|
+
isVariableDeclarationCallExpression(statement, excludedIdentifiers)
|
|
99
|
+
) {
|
|
148
100
|
context.report({
|
|
149
101
|
node: statement,
|
|
150
102
|
messageId: NO_SIDE_EFFECTS,
|