@checkdigit/eslint-plugin 7.3.0 → 7.4.0-PR.66-f2cc
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 +5 -1
- package/dist-mjs/no-side-effects.mjs +68 -0
- package/dist-types/no-side-effects.d.ts +5 -0
- package/package.json +1 -96
- package/src/index.ts +4 -0
- package/src/no-side-effects.ts +111 -0
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@ Copyright (c) 2021-2024 [Check Digit, LLC](https://checkdigit.com)
|
|
|
14
14
|
- `@checkdigit/require-assert-predicate-rejects-throws`
|
|
15
15
|
- `@checkdigit/object-literal-response`
|
|
16
16
|
- `@checkdigit/no-test-import`
|
|
17
|
+
- `@checkdigit/no-side-effects`
|
|
17
18
|
- `@checkdigit/no-promise-instance-method`
|
|
18
19
|
- `@checkdigit/invalid-json-stringify`
|
|
19
20
|
- `@checkdigit/no-full-response`
|
package/dist-mjs/index.mjs
CHANGED
|
@@ -15,6 +15,7 @@ import requireTypeOutOfTypeOnlyImports, {
|
|
|
15
15
|
import noServeRuntime, { ruleId as noServeRuntimeRuleId } from "./agent/no-serve-runtime.mjs";
|
|
16
16
|
import filePathComment from "./file-path-comment.mjs";
|
|
17
17
|
import noCardNumbers from "./no-card-numbers.mjs";
|
|
18
|
+
import noSideEffects from "./no-side-effects.mjs";
|
|
18
19
|
import noRandomV4UUID from "./no-random-v4-uuid.mjs";
|
|
19
20
|
import noTestImport from "./no-test-import.mjs";
|
|
20
21
|
import noUuid from "./no-uuid.mjs";
|
|
@@ -31,6 +32,7 @@ var rules = {
|
|
|
31
32
|
"require-strict-assert": requireStrictAssert,
|
|
32
33
|
"no-test-import": noTestImport,
|
|
33
34
|
"no-wallaby-comment": noWallabyComment,
|
|
35
|
+
"no-side-effects": noSideEffects,
|
|
34
36
|
"regular-expression-comment": regexComment,
|
|
35
37
|
"require-assert-predicate-rejects-throws": requireAssertPredicateRejectsThrows,
|
|
36
38
|
"object-literal-response": objectLiteralResponse,
|
|
@@ -58,6 +60,7 @@ var configs = {
|
|
|
58
60
|
"@checkdigit/no-uuid": "error",
|
|
59
61
|
"@checkdigit/require-strict-assert": "error",
|
|
60
62
|
"@checkdigit/no-wallaby-comment": "error",
|
|
63
|
+
"@checkdigit/no-side-effects": ["error", { excludedIdentifiers: ["assert", "debug", "log", "promisify"] }],
|
|
61
64
|
"@checkdigit/regular-expression-comment": "error",
|
|
62
65
|
"@checkdigit/require-assert-predicate-rejects-throws": "error",
|
|
63
66
|
"@checkdigit/object-literal-response": "error",
|
|
@@ -83,6 +86,7 @@ var configs = {
|
|
|
83
86
|
"@checkdigit/no-uuid": "error",
|
|
84
87
|
"@checkdigit/require-strict-assert": "error",
|
|
85
88
|
"@checkdigit/no-wallaby-comment": "off",
|
|
89
|
+
"@checkdigit/no-side-effects": "error",
|
|
86
90
|
"@checkdigit/regular-expression-comment": "error",
|
|
87
91
|
"@checkdigit/require-assert-predicate-rejects-throws": "error",
|
|
88
92
|
"@checkdigit/object-literal-response": "error",
|
|
@@ -100,4 +104,4 @@ var src_default = pluginToExport;
|
|
|
100
104
|
export {
|
|
101
105
|
src_default as default
|
|
102
106
|
};
|
|
103
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
107
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL2luZGV4LnRzIl0sCiAgIm1hcHBpbmdzIjogIjtBQVVBLE9BQU8sd0JBQXdCLFVBQVUsa0NBQWtDO0FBQzNFLE9BQU8sdUJBQXVCLFVBQVUsaUNBQWlDO0FBQ3pFLE9BQU8sa0JBQWtCLFVBQVUsNEJBQTRCO0FBQy9ELE9BQU8sMkJBQTJCLFVBQVUscUNBQXFDO0FBQ2pGLE9BQU87QUFBQSxFQUNMLFVBQVU7QUFBQSxPQUNMO0FBQ1AsT0FBTztBQUFBLEVBQ0wsVUFBVTtB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QXVCO0FBQUEsTUFDdkIscUNBQXFDO0FBQUEsTUFDckMsa0NBQWtDO0FBQUEsTUFDbEMsK0JBQStCO0FBQUEsTUFDL0IsMENBQTBDO0FBQUEsTUFDMUMsdURBQXVEO0FBQUEsTUFDdkQsdUNBQXVDO0FBQUEsTUFDdkMsOEJBQThCO0FBQUEsTUFDOUIsQ0FBQyxlQUFlLDBCQUEwQixFQUFFLEdBQUc7QUFBQSxNQUMvQyxDQUFDLGVBQWUsNkJBQTZCLEVBQUUsR0FBRztBQUFBLElBQ3BEO0FBQUEsRUFDRjtBQUNGO0FBRUEsSUFBTSxpQkFBNkM7QUFBQSxFQUNqRCxHQUFHO0FBQUEsRUFDSDtBQUNGO0FBQ0EsSUFBTyxjQUFROyIsCiAgIm5hbWVzIjogW10KfQo=
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// src/no-side-effects.ts
|
|
2
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
3
|
+
import { TSESTree } from "@typescript-eslint/typescript-estree";
|
|
4
|
+
var ruleId = "no-side-effects";
|
|
5
|
+
var NO_SIDE_EFFECTS = "NO_SIDE_EFFECTS";
|
|
6
|
+
function isExpressionStatement(node) {
|
|
7
|
+
return node.type === TSESTree.AST_NODE_TYPES.ExpressionStatement;
|
|
8
|
+
}
|
|
9
|
+
function isAwaitExpression(statement) {
|
|
10
|
+
return isExpressionStatement(statement) && statement.expression.type === TSESTree.AST_NODE_TYPES.AwaitExpression;
|
|
11
|
+
}
|
|
12
|
+
function isCallExpressionCalleeMemberExpression(statement, excludedIdentifiers) {
|
|
13
|
+
return 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 && !excludedIdentifiers.includes(statement.expression.callee.object.name);
|
|
14
|
+
}
|
|
15
|
+
function isVariableDeclarationAwaitExpression(node) {
|
|
16
|
+
return node.type === TSESTree.AST_NODE_TYPES.VariableDeclaration && node.declarations.length > 0 && node.declarations[0]?.init?.type === TSESTree.AST_NODE_TYPES.AwaitExpression;
|
|
17
|
+
}
|
|
18
|
+
function isVariableDeclarationCallExpression(node, 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);
|
|
20
|
+
}
|
|
21
|
+
var createRule = ESLintUtils.RuleCreator((name) => name);
|
|
22
|
+
var rule = createRule({
|
|
23
|
+
name: ruleId,
|
|
24
|
+
meta: {
|
|
25
|
+
type: "problem",
|
|
26
|
+
docs: {
|
|
27
|
+
description: "Ensure no side effects can occur at the module-level"
|
|
28
|
+
},
|
|
29
|
+
schema: [
|
|
30
|
+
{
|
|
31
|
+
type: "object",
|
|
32
|
+
properties: {
|
|
33
|
+
excludedIdentifiers: {
|
|
34
|
+
type: "array",
|
|
35
|
+
items: { type: "string" }
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
additionalProperties: false
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
messages: {
|
|
42
|
+
[NO_SIDE_EFFECTS]: "No side effects can occur at the module-level"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
defaultOptions: [{ excludedIdentifiers: [""] }],
|
|
46
|
+
create(context) {
|
|
47
|
+
const options = context.options[0];
|
|
48
|
+
const excludedIdentifiers = options.excludedIdentifiers.length > 0 ? options.excludedIdentifiers : [];
|
|
49
|
+
return {
|
|
50
|
+
Program(node) {
|
|
51
|
+
node.body.forEach((statement) => {
|
|
52
|
+
if (isAwaitExpression(statement) || isCallExpressionCalleeMemberExpression(statement, excludedIdentifiers) || isVariableDeclarationAwaitExpression(statement) || isVariableDeclarationCallExpression(statement, excludedIdentifiers)) {
|
|
53
|
+
context.report({
|
|
54
|
+
node: statement,
|
|
55
|
+
messageId: NO_SIDE_EFFECTS
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
var no_side_effects_default = rule;
|
|
64
|
+
export {
|
|
65
|
+
no_side_effects_default as default,
|
|
66
|
+
ruleId
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL25vLXNpZGUtZWZmZWN0cy50cyJdLAogICJtYXBwaW5ncyI6ICI7QUFRQSxTQUFTLG1CQUFtQjtBQUM1QixTQUFTLGdCQUFnQjtBQU1sQixJQUFNLFNBQVM7QUFDdEIsSUFBTSxrQkFBa0I7QUFHeEIsU0FBUyxzQkFBc0IsTUFBMkQ7QUFDeEYsU0FBTyxLQUFLLFNBQVMsU0FBUyxlQUFlO0FBQy9DO0FBR0EsU0FBUyxrQkFBa0IsV0FBbUM7QUFDNUQsU0FBTyxzQkFBc0IsU0FBUyxLQUFLLFVBQVUsV0FBVyxTQUFTLFNBQVMsZUFBZTtBQUNuRztBQUdBLFNBQVMsdUNBQXVDLFdBQTBCLHFCQUF3QztBQUNoSCxTQUNFLHNCQUFzQixTQUFTLEtBQy9CLFVBQVUsV0FBVyxTQUFTLFNBQVMsZUFBZSxrQkFDdEQsVUFBVSxXQUFXLE9BQU8sU0FBUyxTQUFTLGVBQWUsb0JBQzdELFVBQVUsV0FBVyxPQUFPLE9BQU8sU0FBUyxTQUFTLGVBQWUsY0FDcEUsQ0FBQyxvQkFBb0IsU0FBUyxVQUFVLFdBQVcsT0FBTyxPQUFPLElBQUk7QUFFekU7QUFHQSxTQUFTLHFDQUFxQyxNQUE4QjtBQUMxRSxTQUNFLEtBQUssU0FBU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nQkFBZ0IsQ0FBQyxFQUFFLHFCQUFxQixDQUFDLEVBQUUsRUFBRSxDQUFDO0FBQUEsRUFDOUMsT0FBTyxTQUFTO0FBQ2QsVUFBTSxVQUF1QixRQUFRLFFBQVEsQ0FBQztBQUM5QyxVQUFNLHNCQUFzQixRQUFRLG9CQUFvQixTQUFTLElBQUksUUFBUSxzQkFBc0IsQ0FBQztBQUVwRyxXQUFPO0FBQUEsTUFDTCxRQUFRLE1BQXdCO0FBQzlCLGFBQUssS0FBSyxRQUFRLENBQUMsY0FBYztBQUMvQixjQUNFLGtCQUFrQixTQUFTLEtBQzNCLHVDQUF1QyxXQUFXLG1CQUFtQixLQUNyRSxxQ0FBcUMsU0FBUyxLQUM5QyxvQ0FBb0MsV0FBVyxtQkFBbUIsR0FDbEU7QUFDQSxvQkFBUSxPQUFPO0FBQUEsY0FDYixNQUFNO0FBQUEsY0FDTixXQUFXO0FBQUEsWUFDYixDQUFDO0FBQUEsVUFDSDtBQUFBLFFBQ0YsQ0FBQztBQUFBLE1BQ0g7QUFBQSxJQUNGO0FBQUEsRUFDRjtBQUNGLENBQUM7QUFFRCxJQUFPLDBCQUFROyIsCiAgIm5hbWVzIjogW10KfQo=
|
package/package.json
CHANGED
|
@@ -1,96 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@checkdigit/eslint-plugin",
|
|
3
|
-
"version": "7.3.0",
|
|
4
|
-
"description": "Check Digit eslint plugins",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"eslint",
|
|
7
|
-
"eslintplugin"
|
|
8
|
-
],
|
|
9
|
-
"homepage": "https://github.com/checkdigit/eslint-plugin#readme",
|
|
10
|
-
"bugs": {
|
|
11
|
-
"url": "https://github.com/checkdigit/eslint-plugin/issues"
|
|
12
|
-
},
|
|
13
|
-
"repository": {
|
|
14
|
-
"type": "git",
|
|
15
|
-
"url": "https://github.com/checkdigit/eslint-plugin"
|
|
16
|
-
},
|
|
17
|
-
"license": "MIT",
|
|
18
|
-
"author": "Check Digit, LLC",
|
|
19
|
-
"sideEffects": false,
|
|
20
|
-
"type": "module",
|
|
21
|
-
"exports": {
|
|
22
|
-
".": {
|
|
23
|
-
"types": "./dist-types/index.d.ts",
|
|
24
|
-
"import": "./dist-mjs/index.mjs",
|
|
25
|
-
"default": "./dist-mjs/index.mjs"
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
"files": [
|
|
29
|
-
"src",
|
|
30
|
-
"dist-types",
|
|
31
|
-
"dist-mjs",
|
|
32
|
-
"!src/**/test/**",
|
|
33
|
-
"!src/**/*.test.ts",
|
|
34
|
-
"!src/**/*.spec.ts",
|
|
35
|
-
"!dist-types/**/test/**",
|
|
36
|
-
"!dist-types/**/*.test.d.ts",
|
|
37
|
-
"!dist-types/**/*.spec.d.ts",
|
|
38
|
-
"!dist-mjs/**/test/**",
|
|
39
|
-
"!dist-mjs/**/*.test.mjs",
|
|
40
|
-
"!dist-mjs/**/*.spec.mjs",
|
|
41
|
-
"SECURITY.md"
|
|
42
|
-
],
|
|
43
|
-
"scripts": {
|
|
44
|
-
"build:dist-mjs": "rimraf dist-mjs && npx builder --type=module --sourceMap --outDir=dist-mjs && node dist-mjs/index.mjs",
|
|
45
|
-
"build:dist-types": "rimraf dist-types && npx builder --type=types --outDir=dist-types",
|
|
46
|
-
"ci:compile": "tsc --noEmit",
|
|
47
|
-
"ci:coverage": "NODE_OPTIONS=\"--disable-warning ExperimentalWarning --experimental-vm-modules\" jest --coverage=true",
|
|
48
|
-
"ci:lint": "npm run lint",
|
|
49
|
-
"ci:style": "npm run prettier",
|
|
50
|
-
"ci:test": "NODE_OPTIONS=\"--disable-warning ExperimentalWarning --experimental-vm-modules\" jest --coverage=false",
|
|
51
|
-
"lint": "eslint --max-warnings 0 .",
|
|
52
|
-
"lint:fix": "eslint --max-warnings 0 --fix .",
|
|
53
|
-
"prepare": "",
|
|
54
|
-
"prepublishOnly": "npm run build:dist-types && npm run build:dist-mjs",
|
|
55
|
-
"prettier": "prettier --ignore-path .gitignore --list-different .",
|
|
56
|
-
"prettier:fix": "prettier --ignore-path .gitignore --write .",
|
|
57
|
-
"test": "npm run ci:compile && npm run ci:test && npm run ci:lint && npm run ci:style"
|
|
58
|
-
},
|
|
59
|
-
"prettier": "@checkdigit/prettier-config",
|
|
60
|
-
"jest": {
|
|
61
|
-
"preset": "@checkdigit/jest-config"
|
|
62
|
-
},
|
|
63
|
-
"dependencies": {
|
|
64
|
-
"@typescript-eslint/type-utils": "^8.10.0",
|
|
65
|
-
"@typescript-eslint/utils": "^8.10.0",
|
|
66
|
-
"ts-api-utils": "^1.3.0"
|
|
67
|
-
},
|
|
68
|
-
"devDependencies": {
|
|
69
|
-
"@checkdigit/jest-config": "^6.0.2",
|
|
70
|
-
"@checkdigit/prettier-config": "^5.5.1",
|
|
71
|
-
"@checkdigit/typescript-config": "^8.0.0",
|
|
72
|
-
"@eslint/js": "^9.13.0",
|
|
73
|
-
"@types/eslint": "^9.6.1",
|
|
74
|
-
"@types/eslint-config-prettier": "^6.11.3",
|
|
75
|
-
"@typescript-eslint/parser": "^8.10.0",
|
|
76
|
-
"@typescript-eslint/rule-tester": "^8.10.0",
|
|
77
|
-
"eslint": "^9.13.0",
|
|
78
|
-
"eslint-config-prettier": "^9.1.0",
|
|
79
|
-
"eslint-import-resolver-typescript": "^3.6.3",
|
|
80
|
-
"eslint-plugin-eslint-plugin": "^6.2.0",
|
|
81
|
-
"eslint-plugin-import": "^2.31.0",
|
|
82
|
-
"eslint-plugin-no-only-tests": "^3.3.0",
|
|
83
|
-
"eslint-plugin-no-secrets": "^1.0.2",
|
|
84
|
-
"eslint-plugin-node": "^11.1.0",
|
|
85
|
-
"eslint-plugin-sonarjs": "1.0.4",
|
|
86
|
-
"http-status-codes": "^2.3.0",
|
|
87
|
-
"rimraf": "^6.0.1",
|
|
88
|
-
"typescript-eslint": "^8.10.0"
|
|
89
|
-
},
|
|
90
|
-
"peerDependencies": {
|
|
91
|
-
"eslint": ">=9 <10"
|
|
92
|
-
},
|
|
93
|
-
"engines": {
|
|
94
|
-
"node": ">=20.17"
|
|
95
|
-
}
|
|
96
|
-
}
|
|
1
|
+
{"name":"@checkdigit/eslint-plugin","version":"7.4.0-PR.66-f2cc","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.10.0","@typescript-eslint/utils":"^8.10.0","ts-api-utils":"^1.3.0"},"devDependencies":{"@checkdigit/jest-config":"^6.0.2","@checkdigit/prettier-config":"^5.5.1","@checkdigit/typescript-config":"^8.0.0","@eslint/js":"^9.13.0","@types/eslint":"^9.6.1","@types/eslint-config-prettier":"^6.11.3","@typescript-eslint/parser":"^8.10.0","@typescript-eslint/rule-tester":"^8.10.0","eslint":"^9.13.0","eslint-config-prettier":"^9.1.0","eslint-import-resolver-typescript":"^3.6.3","eslint-plugin-eslint-plugin":"^6.2.0","eslint-plugin-import":"^2.31.0","eslint-plugin-no-only-tests":"^3.3.0","eslint-plugin-no-secrets":"^1.0.2","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.10.0"},"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 './agent/no-serve-runtime';
|
|
25
25
|
import filePathComment from './file-path-comment';
|
|
26
26
|
import noCardNumbers from './no-card-numbers';
|
|
27
|
+
import noSideEffects from './no-side-effects';
|
|
27
28
|
import noRandomV4UUID from './no-random-v4-uuid';
|
|
28
29
|
import noTestImport from './no-test-import';
|
|
29
30
|
import noUuid from './no-uuid';
|
|
@@ -41,6 +42,7 @@ const rules: Record<string, TSESLint.LooseRuleDefinition> = {
|
|
|
41
42
|
'require-strict-assert': requireStrictAssert,
|
|
42
43
|
'no-test-import': noTestImport,
|
|
43
44
|
'no-wallaby-comment': noWallabyComment,
|
|
45
|
+
'no-side-effects': noSideEffects,
|
|
44
46
|
'regular-expression-comment': regexComment,
|
|
45
47
|
'require-assert-predicate-rejects-throws': requireAssertPredicateRejectsThrows,
|
|
46
48
|
'object-literal-response': objectLiteralResponse,
|
|
@@ -70,6 +72,7 @@ const configs: Record<string, TSESLint.FlatConfig.Config> = {
|
|
|
70
72
|
'@checkdigit/no-uuid': 'error',
|
|
71
73
|
'@checkdigit/require-strict-assert': 'error',
|
|
72
74
|
'@checkdigit/no-wallaby-comment': 'error',
|
|
75
|
+
'@checkdigit/no-side-effects': ['error', { excludedIdentifiers: ['assert', 'debug', 'log', 'promisify'] }],
|
|
73
76
|
'@checkdigit/regular-expression-comment': 'error',
|
|
74
77
|
'@checkdigit/require-assert-predicate-rejects-throws': 'error',
|
|
75
78
|
'@checkdigit/object-literal-response': 'error',
|
|
@@ -95,6 +98,7 @@ const configs: Record<string, TSESLint.FlatConfig.Config> = {
|
|
|
95
98
|
'@checkdigit/no-uuid': 'error',
|
|
96
99
|
'@checkdigit/require-strict-assert': 'error',
|
|
97
100
|
'@checkdigit/no-wallaby-comment': 'off',
|
|
101
|
+
'@checkdigit/no-side-effects': 'error',
|
|
98
102
|
'@checkdigit/regular-expression-comment': 'error',
|
|
99
103
|
'@checkdigit/require-assert-predicate-rejects-throws': 'error',
|
|
100
104
|
'@checkdigit/object-literal-response': 'error',
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// no-side-effects.ts
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2022-2024 Check Digit, LLC
|
|
5
|
+
*
|
|
6
|
+
* This code is licensed under the MIT license (see LICENSE.txt for details).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
10
|
+
import { TSESTree } from '@typescript-eslint/typescript-estree';
|
|
11
|
+
|
|
12
|
+
interface RuleOptions {
|
|
13
|
+
excludedIdentifiers: string[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const ruleId = 'no-side-effects';
|
|
17
|
+
const NO_SIDE_EFFECTS = 'NO_SIDE_EFFECTS';
|
|
18
|
+
|
|
19
|
+
// Type guard to check if a node is an ExpressionStatement
|
|
20
|
+
function isExpressionStatement(node: TSESTree.Node): node is TSESTree.ExpressionStatement {
|
|
21
|
+
return node.type === TSESTree.AST_NODE_TYPES.ExpressionStatement;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Type guard to check if a node is an AwaitExpression
|
|
25
|
+
function isAwaitExpression(statement: TSESTree.Node): boolean {
|
|
26
|
+
return isExpressionStatement(statement) && statement.expression.type === TSESTree.AST_NODE_TYPES.AwaitExpression;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// To check if it is a call expression with a member expression i.e. module.method()
|
|
30
|
+
function isCallExpressionCalleeMemberExpression(statement: TSESTree.Node, excludedIdentifiers: string[]): boolean {
|
|
31
|
+
return (
|
|
32
|
+
isExpressionStatement(statement) &&
|
|
33
|
+
statement.expression.type === TSESTree.AST_NODE_TYPES.CallExpression &&
|
|
34
|
+
statement.expression.callee.type === TSESTree.AST_NODE_TYPES.MemberExpression &&
|
|
35
|
+
statement.expression.callee.object.type === TSESTree.AST_NODE_TYPES.Identifier &&
|
|
36
|
+
!excludedIdentifiers.includes(statement.expression.callee.object.name)
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// To check if it is a variable declaration with an await expression i.e. const configuration = await someFunction();
|
|
41
|
+
function isVariableDeclarationAwaitExpression(node: TSESTree.Node): boolean {
|
|
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
|
+
// To check if it is a variable declaration with a call expression
|
|
50
|
+
function isVariableDeclarationCallExpression(node: TSESTree.Node, excludedIdentifiers: string[]): boolean {
|
|
51
|
+
return (
|
|
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)
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const createRule: ReturnType<typeof ESLintUtils.RuleCreator> = ESLintUtils.RuleCreator((name) => name);
|
|
62
|
+
|
|
63
|
+
const rule: ReturnType<typeof createRule> = createRule({
|
|
64
|
+
name: ruleId,
|
|
65
|
+
meta: {
|
|
66
|
+
type: 'problem',
|
|
67
|
+
docs: {
|
|
68
|
+
description: 'Ensure no side effects can occur at the module-level',
|
|
69
|
+
},
|
|
70
|
+
schema: [
|
|
71
|
+
{
|
|
72
|
+
type: 'object',
|
|
73
|
+
properties: {
|
|
74
|
+
excludedIdentifiers: {
|
|
75
|
+
type: 'array',
|
|
76
|
+
items: { type: 'string' },
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
additionalProperties: false,
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
messages: {
|
|
83
|
+
[NO_SIDE_EFFECTS]: 'No side effects can occur at the module-level',
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
defaultOptions: [{ excludedIdentifiers: [''] }],
|
|
87
|
+
create(context) {
|
|
88
|
+
const options: RuleOptions = context.options[0] as RuleOptions;
|
|
89
|
+
const excludedIdentifiers = options.excludedIdentifiers.length > 0 ? options.excludedIdentifiers : [];
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
Program(node: TSESTree.Program) {
|
|
93
|
+
node.body.forEach((statement) => {
|
|
94
|
+
if (
|
|
95
|
+
isAwaitExpression(statement) ||
|
|
96
|
+
isCallExpressionCalleeMemberExpression(statement, excludedIdentifiers) ||
|
|
97
|
+
isVariableDeclarationAwaitExpression(statement) ||
|
|
98
|
+
isVariableDeclarationCallExpression(statement, excludedIdentifiers)
|
|
99
|
+
) {
|
|
100
|
+
context.report({
|
|
101
|
+
node: statement,
|
|
102
|
+
messageId: NO_SIDE_EFFECTS,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
export default rule;
|