@checkdigit/eslint-plugin 7.1.0-PR.89-7502 → 7.2.0-PR.66-49d4
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 -1
- package/dist-mjs/index.mjs +15 -13
- package/dist-mjs/no-duplicated-imports.mjs +87 -0
- package/dist-mjs/no-side-effects.mjs +68 -0
- package/dist-mjs/require-fixed-services-import.mjs +46 -0
- package/dist-types/no-duplicated-imports.d.ts +4 -0
- package/dist-types/no-side-effects.d.ts +5 -0
- package/dist-types/require-fixed-services-import.d.ts +4 -0
- package/package.json +1 -1
- package/src/index.ts +12 -11
- package/src/no-duplicated-imports.ts +118 -0
- package/src/no-side-effects.ts +111 -0
- package/src/require-fixed-services-import.ts +53 -0
- package/dist-mjs/no-random-v4-uuid.mjs +0 -67
- package/dist-types/no-random-v4-uuid.d.ts +0 -5
- package/src/no-random-v4-uuid.ts +0 -92
package/README.md
CHANGED
|
@@ -6,7 +6,6 @@ Copyright (c) 2021-2024 [Check Digit, LLC](https://checkdigit.com)
|
|
|
6
6
|
|
|
7
7
|
- `@checkdigit/no-card-numbers`
|
|
8
8
|
- `@checkdigit/file-path-comment`
|
|
9
|
-
- `@checkdigit/no-random-v4-uuid`
|
|
10
9
|
- `@checkdigit/no-uuid`
|
|
11
10
|
- `@checkdigit/require-strict-assert`
|
|
12
11
|
- `@checkdigit/no-wallaby-comment`
|
|
@@ -14,6 +13,7 @@ Copyright (c) 2021-2024 [Check Digit, LLC](https://checkdigit.com)
|
|
|
14
13
|
- `@checkdigit/require-assert-predicate-rejects-throws`
|
|
15
14
|
- `@checkdigit/object-literal-response`
|
|
16
15
|
- `@checkdigit/no-test-import`
|
|
16
|
+
- `@checkdigit/no-side-effects`
|
|
17
17
|
- `@checkdigit/no-promise-instance-method`
|
|
18
18
|
- `@checkdigit/invalid-json-stringify`
|
|
19
19
|
- `@checkdigit/no-full-response`
|
package/dist-mjs/index.mjs
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import fs from "node:fs";
|
|
3
2
|
import invalidJsonStringify, { ruleId as invalidJsonStringifyRuleId } from "./invalid-json-stringify.mjs";
|
|
3
|
+
import noDuplicatedImports, { ruleId as noDuplicatedImportsRuleId } from "./no-duplicated-imports.mjs";
|
|
4
4
|
import noFullResponse, { ruleId as noFullResponseRuleId } from "./agent/no-full-response.mjs";
|
|
5
5
|
import noPromiseInstanceMethod, { ruleId as noPromiseInstanceMethodRuleId } from "./no-promise-instance-method.mjs";
|
|
6
|
+
import requireFixedServicesImport, {
|
|
7
|
+
ruleId as requireFixedServicesImportRuleId
|
|
8
|
+
} from "./require-fixed-services-import.mjs";
|
|
6
9
|
import requireResolveFullResponse, {
|
|
7
10
|
ruleId as requireResolveFullResponseRuleId
|
|
8
11
|
} from "./require-resolve-full-response.mjs";
|
|
@@ -11,7 +14,7 @@ import requireTypeOutOfTypeOnlyImports, {
|
|
|
11
14
|
} from "./require-type-out-of-type-only-imports.mjs";
|
|
12
15
|
import filePathComment from "./file-path-comment.mjs";
|
|
13
16
|
import noCardNumbers from "./no-card-numbers.mjs";
|
|
14
|
-
import
|
|
17
|
+
import noSideEffects from "./no-side-effects.mjs";
|
|
15
18
|
import noTestImport from "./no-test-import.mjs";
|
|
16
19
|
import noUuid from "./no-uuid.mjs";
|
|
17
20
|
import noWallabyComment from "./no-wallaby-comment.mjs";
|
|
@@ -22,11 +25,11 @@ import requireStrictAssert from "./require-strict-assert.mjs";
|
|
|
22
25
|
var rules = {
|
|
23
26
|
"file-path-comment": filePathComment,
|
|
24
27
|
"no-card-numbers": noCardNumbers,
|
|
25
|
-
"no-random-v4-uuid": noRandomV4UUID,
|
|
26
28
|
"no-uuid": noUuid,
|
|
27
29
|
"require-strict-assert": requireStrictAssert,
|
|
28
30
|
"no-test-import": noTestImport,
|
|
29
31
|
"no-wallaby-comment": noWallabyComment,
|
|
32
|
+
"no-side-effects": noSideEffects,
|
|
30
33
|
"regular-expression-comment": regexComment,
|
|
31
34
|
"require-assert-predicate-rejects-throws": requireAssertPredicateRejectsThrows,
|
|
32
35
|
"object-literal-response": objectLiteralResponse,
|
|
@@ -34,14 +37,11 @@ var rules = {
|
|
|
34
37
|
[noPromiseInstanceMethodRuleId]: noPromiseInstanceMethod,
|
|
35
38
|
[noFullResponseRuleId]: noFullResponse,
|
|
36
39
|
[requireResolveFullResponseRuleId]: requireResolveFullResponse,
|
|
37
|
-
[requireTypeOutOfTypeOnlyImportsRuleId]: requireTypeOutOfTypeOnlyImports
|
|
40
|
+
[requireTypeOutOfTypeOnlyImportsRuleId]: requireTypeOutOfTypeOnlyImports,
|
|
41
|
+
[noDuplicatedImportsRuleId]: noDuplicatedImports,
|
|
42
|
+
[requireFixedServicesImportRuleId]: requireFixedServicesImport
|
|
38
43
|
};
|
|
39
|
-
var packageJson = JSON.parse(fs.readFileSync("package.json", "utf-8"));
|
|
40
44
|
var plugin = {
|
|
41
|
-
meta: {
|
|
42
|
-
name: packageJson.name,
|
|
43
|
-
version: packageJson.version
|
|
44
|
-
},
|
|
45
45
|
rules
|
|
46
46
|
};
|
|
47
47
|
var configs = {
|
|
@@ -52,10 +52,10 @@ var configs = {
|
|
|
52
52
|
rules: {
|
|
53
53
|
"@checkdigit/no-card-numbers": "error",
|
|
54
54
|
"@checkdigit/file-path-comment": "error",
|
|
55
|
-
"@checkdigit/no-random-v4-uuid": "error",
|
|
56
55
|
"@checkdigit/no-uuid": "error",
|
|
57
56
|
"@checkdigit/require-strict-assert": "error",
|
|
58
57
|
"@checkdigit/no-wallaby-comment": "error",
|
|
58
|
+
"@checkdigit/no-side-effects": ["error", { excludedIdentifiers: ["assert", "debug", "log", "promisify"] }],
|
|
59
59
|
"@checkdigit/regular-expression-comment": "error",
|
|
60
60
|
"@checkdigit/require-assert-predicate-rejects-throws": "error",
|
|
61
61
|
"@checkdigit/object-literal-response": "error",
|
|
@@ -64,7 +64,9 @@ var configs = {
|
|
|
64
64
|
[`@checkdigit/${noPromiseInstanceMethodRuleId}`]: "error",
|
|
65
65
|
[`@checkdigit/${noFullResponseRuleId}`]: "error",
|
|
66
66
|
[`@checkdigit/${requireResolveFullResponseRuleId}`]: "error",
|
|
67
|
-
[`@checkdigit/${requireTypeOutOfTypeOnlyImportsRuleId}`]: "error"
|
|
67
|
+
[`@checkdigit/${requireTypeOutOfTypeOnlyImportsRuleId}`]: "error",
|
|
68
|
+
[`@checkdigit/${noDuplicatedImportsRuleId}`]: "error",
|
|
69
|
+
[`@checkdigit/${requireFixedServicesImportRuleId}`]: "error"
|
|
68
70
|
}
|
|
69
71
|
},
|
|
70
72
|
recommended: {
|
|
@@ -74,10 +76,10 @@ var configs = {
|
|
|
74
76
|
rules: {
|
|
75
77
|
"@checkdigit/no-card-numbers": "error",
|
|
76
78
|
"@checkdigit/file-path-comment": "off",
|
|
77
|
-
"@checkdigit/no-random-v4-uuid": "error",
|
|
78
79
|
"@checkdigit/no-uuid": "error",
|
|
79
80
|
"@checkdigit/require-strict-assert": "error",
|
|
80
81
|
"@checkdigit/no-wallaby-comment": "off",
|
|
82
|
+
"@checkdigit/no-side-effects": "error",
|
|
81
83
|
"@checkdigit/regular-expression-comment": "error",
|
|
82
84
|
"@checkdigit/require-assert-predicate-rejects-throws": "error",
|
|
83
85
|
"@checkdigit/object-literal-response": "error",
|
|
@@ -95,4 +97,4 @@ var src_default = pluginToExport;
|
|
|
95
97
|
export {
|
|
96
98
|
src_default as default
|
|
97
99
|
};
|
|
98
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
100
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL2luZGV4LnRzIl0sCiAgIm1hcHBpbmdzIjogIjtBQVVBLE9BQU8sd0JBQXdCLFVBQVUsa0NBQWtDO0FBQzNFLE9BQU8sdUJBQXVCLFVBQVUsaUNBQWlDO0FBQ3pFLE9BQU8sa0JBQWtCLFVBQVU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UFDMUMsdURBQXVEO0FBQUEsTUFDdkQsdUNBQXVDO0FBQUEsTUFDdkMsOEJBQThCO0FBQUEsTUFDOUIsQ0FBQyxlQUFlLDBCQUEwQixFQUFFLEdBQUc7QUFBQSxNQUMvQyxDQUFDLGVBQWUsNkJBQTZCLEVBQUUsR0FBRztBQUFBLElBQ3BEO0FBQUEsRUFDRjtBQUNGO0FBRUEsSUFBTSxpQkFBNkM7QUFBQSxFQUNqRCxHQUFHO0FBQUEsRUFDSDtBQUNGO0FBQ0EsSUFBTyxjQUFROyIsCiAgIm5hbWVzIjogW10KfQo=
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// src/no-duplicated-imports.ts
|
|
2
|
+
import { strict as assert } from "node:assert";
|
|
3
|
+
import { ESLintUtils, TSESTree } from "@typescript-eslint/utils";
|
|
4
|
+
import getDocumentationUrl from "./get-documentation-url.mjs";
|
|
5
|
+
var ruleId = "no-duplicated-imports";
|
|
6
|
+
var createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
|
|
7
|
+
var rule = createRule({
|
|
8
|
+
name: ruleId,
|
|
9
|
+
meta: {
|
|
10
|
+
type: "suggestion",
|
|
11
|
+
docs: {
|
|
12
|
+
description: 'Merge duplicated import statements with the same "from".'
|
|
13
|
+
},
|
|
14
|
+
messages: {
|
|
15
|
+
mergeDuplicatedImports: 'Merge duplicated import statements with the same "from".'
|
|
16
|
+
},
|
|
17
|
+
fixable: "code",
|
|
18
|
+
schema: []
|
|
19
|
+
},
|
|
20
|
+
defaultOptions: [],
|
|
21
|
+
create(context) {
|
|
22
|
+
const sourceCode = context.sourceCode;
|
|
23
|
+
const importDeclarations = /* @__PURE__ */ new Map();
|
|
24
|
+
return {
|
|
25
|
+
ImportDeclaration(node) {
|
|
26
|
+
const moduleName = node.source.value;
|
|
27
|
+
let declarations = importDeclarations.get(moduleName);
|
|
28
|
+
if (declarations === void 0) {
|
|
29
|
+
declarations = [];
|
|
30
|
+
importDeclarations.set(moduleName, declarations);
|
|
31
|
+
}
|
|
32
|
+
declarations.push(node);
|
|
33
|
+
},
|
|
34
|
+
"Program:exit"() {
|
|
35
|
+
for (const [moduleName, declarations] of importDeclarations.entries()) {
|
|
36
|
+
if (declarations.length <= 1) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const firstDeclaration = declarations[0];
|
|
40
|
+
assert.ok(firstDeclaration);
|
|
41
|
+
const isAllTypeOnly = declarations.every(
|
|
42
|
+
(declaration) => declaration.importKind === "type" || declaration.specifiers.every(
|
|
43
|
+
(specifier) => specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier && specifier.importKind === "type"
|
|
44
|
+
)
|
|
45
|
+
);
|
|
46
|
+
context.report({
|
|
47
|
+
messageId: "mergeDuplicatedImports",
|
|
48
|
+
node: firstDeclaration,
|
|
49
|
+
fix(fixer) {
|
|
50
|
+
const fixes = [];
|
|
51
|
+
const defaultSpecifier = declarations.flatMap(
|
|
52
|
+
(declaration) => declaration.specifiers.map(
|
|
53
|
+
(specifier) => specifier.type === TSESTree.AST_NODE_TYPES.ImportDefaultSpecifier ? specifier : void 0
|
|
54
|
+
)
|
|
55
|
+
).filter(Boolean);
|
|
56
|
+
const defaultSpecifierText = defaultSpecifier[0] ? sourceCode.getText(defaultSpecifier[0]) : void 0;
|
|
57
|
+
const mergedSpecifiers = declarations.flatMap((declaration) => {
|
|
58
|
+
const isCurrentDeclarationTypeOnly = declaration.importKind === "type" || declaration.specifiers.every(
|
|
59
|
+
(specifier) => specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier && specifier.importKind === "type"
|
|
60
|
+
);
|
|
61
|
+
return declaration.specifiers.filter((specifier) => specifier.type !== TSESTree.AST_NODE_TYPES.ImportDefaultSpecifier).map(
|
|
62
|
+
(specifier) => (
|
|
63
|
+
// eslint-disable-next-line no-nested-ternary
|
|
64
|
+
isAllTypeOnly ? sourceCode.getText(specifier).replace("type ", "") : isCurrentDeclarationTypeOnly ? `type ${sourceCode.getText(specifier)}` : sourceCode.getText(specifier)
|
|
65
|
+
)
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
const mergedSpecifiersText = `${isAllTypeOnly ? "type " : ""}{ ${mergedSpecifiers.join(", ")} }`;
|
|
69
|
+
const mergedImport = `import ${[defaultSpecifierText, mergedSpecifiersText].filter(Boolean).join(", ")} from '${moduleName}';`;
|
|
70
|
+
fixes.push(fixer.replaceText(firstDeclaration, mergedImport));
|
|
71
|
+
declarations.slice(1).forEach((declaration) => {
|
|
72
|
+
fixes.push(fixer.removeRange([declaration.range[0], declaration.range[1] + 1]));
|
|
73
|
+
});
|
|
74
|
+
return fixes;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
var no_duplicated_imports_default = rule;
|
|
83
|
+
export {
|
|
84
|
+
no_duplicated_imports_default as default,
|
|
85
|
+
ruleId
|
|
86
|
+
};
|
|
87
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL25vLWR1cGxpY2F0ZWQtaW1wb3J0cy50cyJdLAogICJtYXBwaW5ncyI6ICI7QUFRQSxTQUFTLFVBQVUsY0FBYztBQUVqQyxTQUFTLGFBQWEsZ0JBQWdCO0FBRXRDLE9BQU8seUJBQXlCO0FBRXpCLElBQU0sU0FBUztBQUV0QixJQUFNLGFBQWEsWUFBWSxZQUFZLENBQUMsU0FBUyxvQkFBb0IsSUFBSSxDQUFDO0FBRTlFLElBQU0sT0FBeUQsV0FBVztBQUFBLEVBQ3hFLE1BQU07QUFBQSxFQUNOLE1BQU07QUFBQSxJQUNKLE1BQU07QUFBQSxJQUNOLE1BQU07QUFBQSxNQUNKLGFBQWE7QUFBQSxJQUNmO0FBQUEsSUFDQSxVQUFVO0FBQUEsTUFDUix3QkFBd0I7QUFBQSxJQUMxQjtBQUFBLElBQ0E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xRQUFRLENBQUMsZ0JBQWdCO0FBQzdDLHNCQUFNLEtBQUssTUFBTSxZQUFZLENBQUMsWUFBWSxNQUFNLENBQUMsR0FBRyxZQUFZLE1BQU0sQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDO0FBQUEsY0FDaEYsQ0FBQztBQUVELHFCQUFPO0FBQUEsWUFDVDtBQUFBLFVBQ0YsQ0FBQztBQUFBLFFBQ0g7QUFBQSxNQUNGO0FBQUEsSUFDRjtBQUFBLEVBQ0Y7QUFDRixDQUFDO0FBRUQsSUFBTyxnQ0FBUTsiLAogICJuYW1lcyI6IFtdCn0K
|
|
@@ -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,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL25vLXNpZGUtZWZmZWN0cy50cyJdLAogICJtYXBwaW5ncyI6ICI7QUFRQSxTQUFTLG1CQUFtQjtBQUM1QixTQUFTLGdCQUFnQjtBQU1sQixJQUFNLFNBQVM7QUFDdEIsSUFBTSxrQkFBa0I7QUFHeEIsU0FBUyxzQkFBc0IsTUFBMkQ7QUFDeEYsU0FBTyxLQUFLLFNBQVMsU0FBUyxlQUFlO0FBQy9DO0FBR0EsU0FBUyxrQkFBa0IsV0FBbUM7QUFDNUQsU0FBTyxzQkFBc0IsU0FBUyxLQUFLLFVBQVUsV0FBVyxTQUFTLFNBQVMsZUFBZTtBQUNuRztBQUdBLFNBQVMsdUNBQXVDLFdBQTBCLHFCQUF3QztBQUNoSCxTQUNFLHNCQUFzQixTQUFTLEtBQy9CLFVBQVUsV0FBVyxTQUFTLFNBQVMsZUFBZSxrQkFDdEQsVUFBVSxXQUFXLE9BQU8sU0FBUyxTQUFTLGVBQWUsb0JBQzdELFVBQVUsV0FBVyxPQUFPLE9BQU8sU0FBUyxTQUFTLGVBQWUsY0FDcEUsQ0FBQyxvQkFBb0IsU0FBUyxVQUFVLFdBQVcsT0FBTyxPQUFPLElBQUk7QUFFekU7QUFHQSxTQUFTLHFDQUFxQyxNQUE4QjtBQUMxRSxTQUNFLEtBQUssU0FBUyxTQUFTLGVBQWUsdUJBQ3RDLEtBQUssYUFBYSxTQUFTLEtBQzNCLEtBQUssYUFBYSxDQUFDLEdBQUcsTUFBTSxTQUFT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Q2QsVUFBTSxVQUF1QixRQUFRLFFBQVEsQ0FBQztBQUM5QyxVQUFNLHNCQUFzQixRQUFRLG9CQUFvQixTQUFTLElBQUksUUFBUSxzQkFBc0IsQ0FBQztBQUVwRyxXQUFPO0FBQUEsTUFDTCxRQUFRLE1BQXdCO0FBQzlCLGFBQUssS0FBSyxRQUFRLENBQUMsY0FBYztBQUMvQixjQUNFLGtCQUFrQixTQUFTLEtBQzNCLHVDQUF1QyxXQUFXLG1CQUFtQixLQUNyRSxxQ0FBcUMsU0FBUyxLQUM5QyxvQ0FBb0MsV0FBVyxtQkFBbUIsR0FDbEU7QUFDQSxvQkFBUSxPQUFPO0FBQUEsY0FDYixNQUFNO0FBQUEsY0FDTixXQUFXO0FBQUEsWUFDYixDQUFDO0FBQUEsVUFDSDtBQUFBLFFBQ0YsQ0FBQztBQUFBLE1BQ0g7QUFBQSxJQUNGO0FBQUEsRUFDRjtBQUNGLENBQUM7QUFFRCxJQUFPLDBCQUFROyIsCiAgIm5hbWVzIjogW10KfQo=
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// src/require-fixed-services-import.ts
|
|
2
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
3
|
+
import getDocumentationUrl from "./get-documentation-url.mjs";
|
|
4
|
+
var ruleId = "require-fixed-services-import";
|
|
5
|
+
var createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
|
|
6
|
+
var SERVICE_TYPINGS_IMPORT_PATH_PREFIX = /(?<path>\.\.\/)+services\/.*/u;
|
|
7
|
+
var rule = createRule({
|
|
8
|
+
name: ruleId,
|
|
9
|
+
meta: {
|
|
10
|
+
type: "suggestion",
|
|
11
|
+
docs: {
|
|
12
|
+
description: 'Require fixed "from" with service typing imports from "src/services".'
|
|
13
|
+
},
|
|
14
|
+
messages: {
|
|
15
|
+
updateServicesImportFrom: 'Update service typing imports to be from the fixed "src/services" path.'
|
|
16
|
+
},
|
|
17
|
+
fixable: "code",
|
|
18
|
+
schema: []
|
|
19
|
+
},
|
|
20
|
+
defaultOptions: [],
|
|
21
|
+
create(context) {
|
|
22
|
+
return {
|
|
23
|
+
ImportDeclaration(node) {
|
|
24
|
+
const moduleName = node.source.value;
|
|
25
|
+
if (SERVICE_TYPINGS_IMPORT_PATH_PREFIX.test(moduleName)) {
|
|
26
|
+
context.report({
|
|
27
|
+
messageId: "updateServicesImportFrom",
|
|
28
|
+
node: node.source,
|
|
29
|
+
*fix(fixer) {
|
|
30
|
+
yield fixer.replaceText(
|
|
31
|
+
node.source,
|
|
32
|
+
`'${moduleName.slice(0, moduleName.indexOf("../services") + "../services".length)}'`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
var require_fixed_services_import_default = rule;
|
|
42
|
+
export {
|
|
43
|
+
require_fixed_services_import_default as default,
|
|
44
|
+
ruleId
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL3JlcXVpcmUtZml4ZWQtc2VydmljZXMtaW1wb3J0LnRzIl0sCiAgIm1hcHBpbmdzIjogIjtBQVFBLFNBQVMsbUJBQW1CO0FBRTVCLE9BQU8seUJBQXlCO0FBRXpCLElBQU0sU0FBUztBQUV0QixJQUFNLGFBQWEsWUFBWSxZQUFZLENBQUMsU0FBUyxvQkFBb0IsSUFBSSxDQUFDO0FBQzlFLElBQU0scUNBQXFDO0FBRTNDLElBQU0sT0FBMkQsV0FBVztBQUFBLEVBQzFFLE1BQU07QUFBQSxFQUNOLE1BQU07QUFBQSxJQUNKLE1BQU07QUFBQSxJQUNOLE1BQU07QUFBQSxNQUNKLGFBQWE7QUFBQSxJQUNmO0FBQUEsSUFDQSxVQUFVO0FBQUEsTUFDUiwwQkFBMEI7QUFBQSxJQUM1QjtBQUFBLElBQ0EsU0FBUztBQUFBLElBQ1QsUUFBUSxDQUFDO0FBQUEsRUFDWDtBQUFBLEVBQ0EsZ0JBQWdCLENBQUM7QUFBQSxFQUNqQixPQUFPLFNBQVM7QUFDZCxXQUFPO0FBQUEsTUFDTCxrQkFBa0IsTUFBTTtBQUN0QixjQUFNLGFBQWEsS0FBSyxPQUFPO0FBQy9CLFlBQUksbUNBQW1DLEtBQUssVUFBVSxHQUFHO0FBQ3ZELGtCQUFRLE9BQU87QUFBQSxZQUNiLFdBQVc7QUFBQSxZQUNYLE1BQU0sS0FBSztBQUFBLFlBQ1gsQ0FBQyxJQUFJLE9BQU87QUFDVixvQkFBTSxNQUFNO0FBQUEsZ0JBQ1YsS0FBSztBQUFBLGdCQUNMLElBQUksV0FBVyxNQUFNLEdBQUcsV0FBVyxRQUFRLGFBQWEsSUFBSSxjQUFjLE1BQU0sQ0FBQztBQUFBLGNBQ25GO0FBQUEsWUFDRjtBQUFBLFVBQ0YsQ0FBQztBQUFBLFFBQ0g7QUFBQSxNQUNGO0FBQUEsSUFDRjtBQUFBLEVBQ0Y7QUFDRixDQUFDO0FBRUQsSUFBTyx3Q0FBUTsiLAogICJuYW1lcyI6IFtdCn0K
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@checkdigit/eslint-plugin","version":"7.
|
|
1
|
+
{"name":"@checkdigit/eslint-plugin","version":"7.2.0-PR.66-49d4","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
|
@@ -6,13 +6,15 @@
|
|
|
6
6
|
* This code is licensed under the MIT license (see LICENSE.txt for details).
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import fs from 'node:fs';
|
|
10
|
-
|
|
11
9
|
import type { TSESLint } from '@typescript-eslint/utils';
|
|
12
10
|
|
|
13
11
|
import invalidJsonStringify, { ruleId as invalidJsonStringifyRuleId } from './invalid-json-stringify';
|
|
12
|
+
import noDuplicatedImports, { ruleId as noDuplicatedImportsRuleId } from './no-duplicated-imports';
|
|
14
13
|
import noFullResponse, { ruleId as noFullResponseRuleId } from './agent/no-full-response';
|
|
15
14
|
import noPromiseInstanceMethod, { ruleId as noPromiseInstanceMethodRuleId } from './no-promise-instance-method';
|
|
15
|
+
import requireFixedServicesImport, {
|
|
16
|
+
ruleId as requireFixedServicesImportRuleId,
|
|
17
|
+
} from './require-fixed-services-import';
|
|
16
18
|
import requireResolveFullResponse, {
|
|
17
19
|
ruleId as requireResolveFullResponseRuleId,
|
|
18
20
|
} from './require-resolve-full-response';
|
|
@@ -21,7 +23,7 @@ import requireTypeOutOfTypeOnlyImports, {
|
|
|
21
23
|
} from './require-type-out-of-type-only-imports';
|
|
22
24
|
import filePathComment from './file-path-comment';
|
|
23
25
|
import noCardNumbers from './no-card-numbers';
|
|
24
|
-
import
|
|
26
|
+
import noSideEffects from './no-side-effects';
|
|
25
27
|
import noTestImport from './no-test-import';
|
|
26
28
|
import noUuid from './no-uuid';
|
|
27
29
|
import noWallabyComment from './no-wallaby-comment';
|
|
@@ -33,11 +35,11 @@ import requireStrictAssert from './require-strict-assert';
|
|
|
33
35
|
const rules: Record<string, TSESLint.LooseRuleDefinition> = {
|
|
34
36
|
'file-path-comment': filePathComment,
|
|
35
37
|
'no-card-numbers': noCardNumbers,
|
|
36
|
-
'no-random-v4-uuid': noRandomV4UUID,
|
|
37
38
|
'no-uuid': noUuid,
|
|
38
39
|
'require-strict-assert': requireStrictAssert,
|
|
39
40
|
'no-test-import': noTestImport,
|
|
40
41
|
'no-wallaby-comment': noWallabyComment,
|
|
42
|
+
'no-side-effects': noSideEffects,
|
|
41
43
|
'regular-expression-comment': regexComment,
|
|
42
44
|
'require-assert-predicate-rejects-throws': requireAssertPredicateRejectsThrows,
|
|
43
45
|
'object-literal-response': objectLiteralResponse,
|
|
@@ -46,14 +48,11 @@ const rules: Record<string, TSESLint.LooseRuleDefinition> = {
|
|
|
46
48
|
[noFullResponseRuleId]: noFullResponse,
|
|
47
49
|
[requireResolveFullResponseRuleId]: requireResolveFullResponse,
|
|
48
50
|
[requireTypeOutOfTypeOnlyImportsRuleId]: requireTypeOutOfTypeOnlyImports,
|
|
51
|
+
[noDuplicatedImportsRuleId]: noDuplicatedImports,
|
|
52
|
+
[requireFixedServicesImportRuleId]: requireFixedServicesImport,
|
|
49
53
|
};
|
|
50
54
|
|
|
51
|
-
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf-8')) as { name: string; version: string };
|
|
52
55
|
const plugin: TSESLint.FlatConfig.Plugin = {
|
|
53
|
-
meta: {
|
|
54
|
-
name: packageJson.name,
|
|
55
|
-
version: packageJson.version,
|
|
56
|
-
},
|
|
57
56
|
rules,
|
|
58
57
|
};
|
|
59
58
|
|
|
@@ -65,10 +64,10 @@ const configs: Record<string, TSESLint.FlatConfig.Config> = {
|
|
|
65
64
|
rules: {
|
|
66
65
|
'@checkdigit/no-card-numbers': 'error',
|
|
67
66
|
'@checkdigit/file-path-comment': 'error',
|
|
68
|
-
'@checkdigit/no-random-v4-uuid': 'error',
|
|
69
67
|
'@checkdigit/no-uuid': 'error',
|
|
70
68
|
'@checkdigit/require-strict-assert': 'error',
|
|
71
69
|
'@checkdigit/no-wallaby-comment': 'error',
|
|
70
|
+
'@checkdigit/no-side-effects': ['error', { excludedIdentifiers: ['assert', 'debug', 'log', 'promisify'] }],
|
|
72
71
|
'@checkdigit/regular-expression-comment': 'error',
|
|
73
72
|
'@checkdigit/require-assert-predicate-rejects-throws': 'error',
|
|
74
73
|
'@checkdigit/object-literal-response': 'error',
|
|
@@ -78,6 +77,8 @@ const configs: Record<string, TSESLint.FlatConfig.Config> = {
|
|
|
78
77
|
[`@checkdigit/${noFullResponseRuleId}`]: 'error',
|
|
79
78
|
[`@checkdigit/${requireResolveFullResponseRuleId}`]: 'error',
|
|
80
79
|
[`@checkdigit/${requireTypeOutOfTypeOnlyImportsRuleId}`]: 'error',
|
|
80
|
+
[`@checkdigit/${noDuplicatedImportsRuleId}`]: 'error',
|
|
81
|
+
[`@checkdigit/${requireFixedServicesImportRuleId}`]: 'error',
|
|
81
82
|
},
|
|
82
83
|
},
|
|
83
84
|
recommended: {
|
|
@@ -87,10 +88,10 @@ const configs: Record<string, TSESLint.FlatConfig.Config> = {
|
|
|
87
88
|
rules: {
|
|
88
89
|
'@checkdigit/no-card-numbers': 'error',
|
|
89
90
|
'@checkdigit/file-path-comment': 'off',
|
|
90
|
-
'@checkdigit/no-random-v4-uuid': 'error',
|
|
91
91
|
'@checkdigit/no-uuid': 'error',
|
|
92
92
|
'@checkdigit/require-strict-assert': 'error',
|
|
93
93
|
'@checkdigit/no-wallaby-comment': 'off',
|
|
94
|
+
'@checkdigit/no-side-effects': 'error',
|
|
94
95
|
'@checkdigit/regular-expression-comment': 'error',
|
|
95
96
|
'@checkdigit/require-assert-predicate-rejects-throws': 'error',
|
|
96
97
|
'@checkdigit/object-literal-response': 'error',
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// no-duplicated-imports.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 { strict as assert } from 'node:assert';
|
|
10
|
+
|
|
11
|
+
import { ESLintUtils, TSESTree } from '@typescript-eslint/utils';
|
|
12
|
+
|
|
13
|
+
import getDocumentationUrl from './get-documentation-url';
|
|
14
|
+
|
|
15
|
+
export const ruleId = 'no-duplicated-imports';
|
|
16
|
+
|
|
17
|
+
const createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
|
|
18
|
+
|
|
19
|
+
const rule: ESLintUtils.RuleModule<'mergeDuplicatedImports'> = createRule({
|
|
20
|
+
name: ruleId,
|
|
21
|
+
meta: {
|
|
22
|
+
type: 'suggestion',
|
|
23
|
+
docs: {
|
|
24
|
+
description: 'Merge duplicated import statements with the same "from".',
|
|
25
|
+
},
|
|
26
|
+
messages: {
|
|
27
|
+
mergeDuplicatedImports: 'Merge duplicated import statements with the same "from".',
|
|
28
|
+
},
|
|
29
|
+
fixable: 'code',
|
|
30
|
+
schema: [],
|
|
31
|
+
},
|
|
32
|
+
defaultOptions: [],
|
|
33
|
+
create(context) {
|
|
34
|
+
const sourceCode = context.sourceCode;
|
|
35
|
+
const importDeclarations = new Map<string, TSESTree.ImportDeclaration[]>();
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
ImportDeclaration(node) {
|
|
39
|
+
const moduleName = node.source.value;
|
|
40
|
+
let declarations = importDeclarations.get(moduleName);
|
|
41
|
+
if (declarations === undefined) {
|
|
42
|
+
declarations = [];
|
|
43
|
+
importDeclarations.set(moduleName, declarations);
|
|
44
|
+
}
|
|
45
|
+
declarations.push(node);
|
|
46
|
+
},
|
|
47
|
+
'Program:exit'() {
|
|
48
|
+
for (const [moduleName, declarations] of importDeclarations.entries()) {
|
|
49
|
+
if (declarations.length <= 1) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const firstDeclaration = declarations[0];
|
|
54
|
+
assert.ok(firstDeclaration);
|
|
55
|
+
|
|
56
|
+
const isAllTypeOnly = declarations.every(
|
|
57
|
+
(declaration) =>
|
|
58
|
+
declaration.importKind === 'type' ||
|
|
59
|
+
declaration.specifiers.every(
|
|
60
|
+
(specifier) =>
|
|
61
|
+
specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier && specifier.importKind === 'type',
|
|
62
|
+
),
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
context.report({
|
|
66
|
+
messageId: 'mergeDuplicatedImports',
|
|
67
|
+
node: firstDeclaration,
|
|
68
|
+
fix(fixer) {
|
|
69
|
+
const fixes = [];
|
|
70
|
+
|
|
71
|
+
const defaultSpecifier = declarations
|
|
72
|
+
.flatMap((declaration) =>
|
|
73
|
+
declaration.specifiers.map((specifier) =>
|
|
74
|
+
specifier.type === TSESTree.AST_NODE_TYPES.ImportDefaultSpecifier ? specifier : undefined,
|
|
75
|
+
),
|
|
76
|
+
)
|
|
77
|
+
.filter(Boolean);
|
|
78
|
+
const defaultSpecifierText = defaultSpecifier[0] ? sourceCode.getText(defaultSpecifier[0]) : undefined;
|
|
79
|
+
|
|
80
|
+
const mergedSpecifiers = declarations.flatMap((declaration) => {
|
|
81
|
+
const isCurrentDeclarationTypeOnly =
|
|
82
|
+
declaration.importKind === 'type' ||
|
|
83
|
+
declaration.specifiers.every(
|
|
84
|
+
(specifier) =>
|
|
85
|
+
specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier && specifier.importKind === 'type',
|
|
86
|
+
);
|
|
87
|
+
return declaration.specifiers
|
|
88
|
+
.filter((specifier) => specifier.type !== TSESTree.AST_NODE_TYPES.ImportDefaultSpecifier)
|
|
89
|
+
.map((specifier) =>
|
|
90
|
+
// eslint-disable-next-line no-nested-ternary
|
|
91
|
+
isAllTypeOnly
|
|
92
|
+
? sourceCode.getText(specifier).replace('type ', '')
|
|
93
|
+
: isCurrentDeclarationTypeOnly
|
|
94
|
+
? `type ${sourceCode.getText(specifier)}`
|
|
95
|
+
: sourceCode.getText(specifier),
|
|
96
|
+
);
|
|
97
|
+
});
|
|
98
|
+
const mergedSpecifiersText = `${isAllTypeOnly ? 'type ' : ''}{ ${mergedSpecifiers.join(', ')} }`;
|
|
99
|
+
|
|
100
|
+
// Replace the first import with the merged import
|
|
101
|
+
const mergedImport = `import ${[defaultSpecifierText, mergedSpecifiersText].filter(Boolean).join(', ')} from '${moduleName}';`;
|
|
102
|
+
fixes.push(fixer.replaceText(firstDeclaration, mergedImport));
|
|
103
|
+
|
|
104
|
+
// Remove the remaining imports
|
|
105
|
+
declarations.slice(1).forEach((declaration) => {
|
|
106
|
+
fixes.push(fixer.removeRange([declaration.range[0], declaration.range[1] + 1]));
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
return fixes;
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
export default rule;
|
|
@@ -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;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// require-fixed-services-import.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 } from '@typescript-eslint/utils';
|
|
10
|
+
|
|
11
|
+
import getDocumentationUrl from './get-documentation-url';
|
|
12
|
+
|
|
13
|
+
export const ruleId = 'require-fixed-services-import';
|
|
14
|
+
|
|
15
|
+
const createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
|
|
16
|
+
const SERVICE_TYPINGS_IMPORT_PATH_PREFIX = /(?<path>\.\.\/)+services\/.*/u;
|
|
17
|
+
|
|
18
|
+
const rule: ESLintUtils.RuleModule<'updateServicesImportFrom'> = createRule({
|
|
19
|
+
name: ruleId,
|
|
20
|
+
meta: {
|
|
21
|
+
type: 'suggestion',
|
|
22
|
+
docs: {
|
|
23
|
+
description: 'Require fixed "from" with service typing imports from "src/services".',
|
|
24
|
+
},
|
|
25
|
+
messages: {
|
|
26
|
+
updateServicesImportFrom: 'Update service typing imports to be from the fixed "src/services" path.',
|
|
27
|
+
},
|
|
28
|
+
fixable: 'code',
|
|
29
|
+
schema: [],
|
|
30
|
+
},
|
|
31
|
+
defaultOptions: [],
|
|
32
|
+
create(context) {
|
|
33
|
+
return {
|
|
34
|
+
ImportDeclaration(node) {
|
|
35
|
+
const moduleName = node.source.value;
|
|
36
|
+
if (SERVICE_TYPINGS_IMPORT_PATH_PREFIX.test(moduleName)) {
|
|
37
|
+
context.report({
|
|
38
|
+
messageId: 'updateServicesImportFrom',
|
|
39
|
+
node: node.source,
|
|
40
|
+
*fix(fixer) {
|
|
41
|
+
yield fixer.replaceText(
|
|
42
|
+
node.source,
|
|
43
|
+
`'${moduleName.slice(0, moduleName.indexOf('../services') + '../services'.length)}'`,
|
|
44
|
+
);
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
export default rule;
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
// src/no-random-v4-uuid.ts
|
|
2
|
-
import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
|
|
3
|
-
import getDocumentationUrl from "./get-documentation-url.mjs";
|
|
4
|
-
var ruleId = "no-random-v4-uuid";
|
|
5
|
-
var NO_RANDOM_V4_UUID = "NO_RANDOM_V4_UUID";
|
|
6
|
-
var createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
|
|
7
|
-
var processImportDeclaration = (node, uuid4Alias, uuidDefaultAlias) => {
|
|
8
|
-
let updatedUuid4Alias = uuid4Alias;
|
|
9
|
-
let updatedUuidDefaultAlias = uuidDefaultAlias;
|
|
10
|
-
node.specifiers.forEach((specifier) => {
|
|
11
|
-
switch (specifier.type) {
|
|
12
|
-
case AST_NODE_TYPES.ImportSpecifier:
|
|
13
|
-
if (specifier.imported.type === AST_NODE_TYPES.Identifier && specifier.imported.name === "v4") {
|
|
14
|
-
updatedUuid4Alias = specifier.local.name;
|
|
15
|
-
}
|
|
16
|
-
break;
|
|
17
|
-
case AST_NODE_TYPES.ImportDefaultSpecifier:
|
|
18
|
-
updatedUuidDefaultAlias = specifier.local.name;
|
|
19
|
-
break;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
return { uuid4Alias: updatedUuid4Alias, uuidDefaultAlias: updatedUuidDefaultAlias };
|
|
23
|
-
};
|
|
24
|
-
var isUuid4Call = (node, uuid4Alias, uuidDefaultAlias) => node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === uuid4Alias || node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.object.type === AST_NODE_TYPES.Identifier && node.callee.object.name === uuidDefaultAlias && node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === "v4";
|
|
25
|
-
var rule = createRule({
|
|
26
|
-
name: ruleId,
|
|
27
|
-
meta: {
|
|
28
|
-
type: "problem",
|
|
29
|
-
docs: {
|
|
30
|
-
description: "Disallow the use of `uuid.v4` for generating random v4 UUIDs"
|
|
31
|
-
},
|
|
32
|
-
schema: [],
|
|
33
|
-
messages: {
|
|
34
|
-
[NO_RANDOM_V4_UUID]: "Avoid using `uuid.v4` for generating random v4 UUIDs."
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
defaultOptions: [],
|
|
38
|
-
create(context) {
|
|
39
|
-
let uuid4Alias;
|
|
40
|
-
let uuidDefaultAlias;
|
|
41
|
-
let hasUuidImport = false;
|
|
42
|
-
return {
|
|
43
|
-
ImportDeclaration(node) {
|
|
44
|
-
if (node.source.value === "uuid") {
|
|
45
|
-
hasUuidImport = true;
|
|
46
|
-
const result = processImportDeclaration(node, uuid4Alias, uuidDefaultAlias);
|
|
47
|
-
uuid4Alias = result.uuid4Alias;
|
|
48
|
-
uuidDefaultAlias = result.uuidDefaultAlias;
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
CallExpression(node) {
|
|
52
|
-
if (hasUuidImport && isUuid4Call(node, uuid4Alias, uuidDefaultAlias)) {
|
|
53
|
-
context.report({
|
|
54
|
-
node,
|
|
55
|
-
messageId: NO_RANDOM_V4_UUID
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
var no_random_v4_uuid_default = rule;
|
|
63
|
-
export {
|
|
64
|
-
no_random_v4_uuid_default as default,
|
|
65
|
-
ruleId
|
|
66
|
-
};
|
|
67
|
-
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL25vLXJhbmRvbS12NC11dWlkLnRzIl0sCiAgIm1hcHBpbmdzIjogIjtBQVFBLFNBQVM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sTUFBTTtBQUFBLE1BQ0osYUFBYTtBQUFBLElBQ2Y7QUFBQSxJQUNBLFFBQVEsQ0FBQztBQUFBLElBQ1QsVUFBVTtBQUFBLE1BQ1IsQ0FBQyxpQkFBaUIsR0FBRztBQUFBLElBQ3ZCO0FBQUEsRUFDRjtBQUFBLEVBQ0EsZ0JBQWdCLENBQUM7QUFBQSxFQUNqQixPQUFPLFNBQVM7QUFDZCxRQUFJO0FBQ0osUUFBSTtBQUNKLFFBQUksZ0JBQWdCO0FBRXBCLFdBQU87QUFBQSxNQUNMLGtCQUFrQixNQUFrQztBQUNsRCxZQUFJLEtBQUssT0FBTyxVQUFVLFFBQVE7QUFDaEMsMEJBQWdCO0FBQ2hCLGdCQUFNLFNBQVMseUJBQXlCLE1BQU0sWUFBWSxnQkFBZ0I7QUFDMUUsdUJBQWEsT0FBTztBQUNwQiw2QkFBbUIsT0FBTztBQUFBLFFBQzVCO0FBQUEsTUFDRjtBQUFBLE1BQ0EsZUFBZSxNQUErQjtBQUM1QyxZQUFJLGlCQUFpQixZQUFZLE1BQU0sWUFBWSxnQkFBZ0IsR0FBRztBQUNwRSxrQkFBUSxPQUFPO0FBQUEsWUFDYjtBQUFBLFlBQ0EsV0FBVztBQUFBLFVBQ2IsQ0FBQztBQUFBLFFBQ0g7QUFBQSxNQUNGO0FBQUEsSUFDRjtBQUFBLEVBQ0Y7QUFDRixDQUFDO0FBRUQsSUFBTyw0QkFBUTsiLAogICJuYW1lcyI6IFtdCn0K
|
package/src/no-random-v4-uuid.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
// no-random-v4-uuid.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 { AST_NODE_TYPES, ESLintUtils, TSESLint, TSESTree } from '@typescript-eslint/utils';
|
|
10
|
-
import getDocumentationUrl from './get-documentation-url';
|
|
11
|
-
|
|
12
|
-
export const ruleId = 'no-random-v4-uuid';
|
|
13
|
-
const NO_RANDOM_V4_UUID = 'NO_RANDOM_V4_UUID';
|
|
14
|
-
|
|
15
|
-
const createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
|
|
16
|
-
|
|
17
|
-
// process the import declaration to get the alias for uuid.v4 and uuid.
|
|
18
|
-
const processImportDeclaration = (
|
|
19
|
-
node: TSESTree.ImportDeclaration,
|
|
20
|
-
uuid4Alias: string | undefined,
|
|
21
|
-
uuidDefaultAlias: string | undefined,
|
|
22
|
-
) => {
|
|
23
|
-
let updatedUuid4Alias = uuid4Alias;
|
|
24
|
-
let updatedUuidDefaultAlias = uuidDefaultAlias;
|
|
25
|
-
node.specifiers.forEach((specifier) => {
|
|
26
|
-
switch (specifier.type) {
|
|
27
|
-
case AST_NODE_TYPES.ImportSpecifier:
|
|
28
|
-
if (specifier.imported.type === AST_NODE_TYPES.Identifier && specifier.imported.name === 'v4') {
|
|
29
|
-
updatedUuid4Alias = specifier.local.name;
|
|
30
|
-
}
|
|
31
|
-
break;
|
|
32
|
-
case AST_NODE_TYPES.ImportDefaultSpecifier:
|
|
33
|
-
updatedUuidDefaultAlias = specifier.local.name;
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
return { uuid4Alias: updatedUuid4Alias, uuidDefaultAlias: updatedUuidDefaultAlias };
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
// checks if the function call is either directly using the alias for uuid.v4 or using uuid.v4 as a member expression.
|
|
41
|
-
const isUuid4Call = (
|
|
42
|
-
node: TSESTree.CallExpression,
|
|
43
|
-
uuid4Alias: string | undefined,
|
|
44
|
-
uuidDefaultAlias: string | undefined,
|
|
45
|
-
): boolean =>
|
|
46
|
-
(node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === uuid4Alias) ||
|
|
47
|
-
(node.callee.type === AST_NODE_TYPES.MemberExpression &&
|
|
48
|
-
node.callee.object.type === AST_NODE_TYPES.Identifier &&
|
|
49
|
-
node.callee.object.name === uuidDefaultAlias &&
|
|
50
|
-
node.callee.property.type === AST_NODE_TYPES.Identifier &&
|
|
51
|
-
node.callee.property.name === 'v4');
|
|
52
|
-
|
|
53
|
-
const rule: TSESLint.RuleModule<typeof NO_RANDOM_V4_UUID> = createRule({
|
|
54
|
-
name: ruleId,
|
|
55
|
-
meta: {
|
|
56
|
-
type: 'problem',
|
|
57
|
-
docs: {
|
|
58
|
-
description: 'Disallow the use of `uuid.v4` for generating random v4 UUIDs',
|
|
59
|
-
},
|
|
60
|
-
schema: [],
|
|
61
|
-
messages: {
|
|
62
|
-
[NO_RANDOM_V4_UUID]: 'Avoid using `uuid.v4` for generating random v4 UUIDs.',
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
defaultOptions: [],
|
|
66
|
-
create(context) {
|
|
67
|
-
let uuid4Alias: string | undefined;
|
|
68
|
-
let uuidDefaultAlias: string | undefined;
|
|
69
|
-
let hasUuidImport = false;
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
ImportDeclaration(node: TSESTree.ImportDeclaration) {
|
|
73
|
-
if (node.source.value === 'uuid') {
|
|
74
|
-
hasUuidImport = true;
|
|
75
|
-
const result = processImportDeclaration(node, uuid4Alias, uuidDefaultAlias);
|
|
76
|
-
uuid4Alias = result.uuid4Alias;
|
|
77
|
-
uuidDefaultAlias = result.uuidDefaultAlias;
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
CallExpression(node: TSESTree.CallExpression) {
|
|
81
|
-
if (hasUuidImport && isUuid4Call(node, uuid4Alias, uuidDefaultAlias)) {
|
|
82
|
-
context.report({
|
|
83
|
-
node,
|
|
84
|
-
messageId: NO_RANDOM_V4_UUID,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
},
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
export default rule;
|