@checkdigit/eslint-plugin 6.6.0-PR.75-edd9 → 6.6.0-PR.75-2a52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-cjs/index.cjs +846 -616
- package/dist-cjs/metafile.json +153 -37
- package/dist-mjs/agent/no-unused-function-argument.mjs +71 -0
- package/dist-mjs/index.mjs +23 -15
- package/dist-mjs/no-duplicated-imports.mjs +87 -0
- package/dist-mjs/require-fixed-services-import.mjs +46 -0
- package/dist-mjs/require-type-out-of-type-only-imports.mjs +48 -0
- package/dist-types/agent/no-unused-function-argument.d.ts +4 -0
- package/dist-types/index.d.ts +9 -11
- package/dist-types/no-duplicated-imports.d.ts +4 -0
- package/dist-types/require-fixed-services-import.d.ts +4 -0
- package/dist-types/require-type-out-of-type-only-imports.d.ts +4 -0
- package/package.json +1 -1
- package/src/agent/add-url-domain.ts +1 -1
- package/src/agent/fetch-response-body-json.ts +1 -1
- package/src/agent/fetch-response-header-getter.ts +1 -1
- package/src/agent/fetch-then.ts +1 -1
- package/src/agent/fetch.ts +1 -1
- package/src/agent/no-fixture.ts +1 -1
- package/src/agent/no-full-response.ts +1 -1
- package/src/agent/no-mapped-response.ts +1 -1
- package/src/agent/no-service-wrapper.ts +1 -1
- package/src/agent/no-status-code.ts +1 -1
- package/src/agent/no-unused-function-argument.ts +83 -0
- package/src/agent/response-reference.ts +1 -1
- package/src/agent/url.ts +1 -1
- package/src/index.ts +19 -11
- package/src/library/format.ts +1 -1
- package/src/library/tree.ts +1 -1
- package/src/library/ts-tree.ts +1 -1
- package/src/library/variable.ts +1 -1
- package/src/no-duplicated-imports.ts +116 -0
- package/src/require-fixed-services-import.ts +52 -0
- package/src/require-type-out-of-type-only-imports.ts +63 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// src/no-duplicated-imports.ts
|
|
2
|
+
import { ESLintUtils, TSESTree } from "@typescript-eslint/utils";
|
|
3
|
+
import { strict as assert } from "node:assert";
|
|
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,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL25vLWR1cGxpY2F0ZWQtaW1wb3J0cy50cyJdLAogICJtYXBwaW5ncyI6ICI7QUFRQSxTQUFTLGFBQWEsZ0JBQWdCO0FBQ3RDLFNBQVMsVUFBVSxjQUFjO0FBQ2pDLE9BQU8seUJBQXlCO0FBRXpCLElBQU0sU0FBUztBQUV0QixJQUFNLGFBQWEsWUFBWSxZQUFZLENBQUMsU0FBUyxvQkFBb0IsSUFBSSxDQUFDO0FBRTlFLElBQU0sT0FBTyxXQUFXO0FBQUEsRUFDdEIsTUFBTTtBQUFBLEVBQ04sTUFBTTtBQUFBLElBQ0osTUFBTTtBQUFBLElBQ04sTUFBTTtBQUFBLE1BQ0osYUFBYTtBQUFBLElBQ2Y7QUFBQSxJQUNBLFVBQVU7QUFBQSxNQUNSLHdCQUF3QjtBQUFBLElBQzFCO0FBQUEsSUFDQSxTQUFTO0FBQUEsSUFDVCxRQUFRLENBQUM7QUFBQSxFQUNYO0FBQUEsRUFDQSxnQkFBZ0IsQ0FBQztBQUFBLEVBQ2pCLE9BQU8sU0FBUztBQUNkLFVBQU0sYUFBYSxRQUFRO0FBQzNCLFVBQU0scUJBQXFCLG9CQUFJLElBQTBDO0FBRXpFLFdBQU87QUFBQSxNQUNMLGtCQUFrQixNQUFNO0FBQ3RCLGNBQU0sYUFBYSxLQUFLLE9BQU87QUFDL0IsWUFBSSxlQUFlLG1CQUFtQixJQUFJLFVBQVU7QUFDcEQsWUFBSSxpQkFBaUIsUUFBVztBQUM5Qix5QkFBZSxDQUFDO0FBQ2hCLDZCQUFtQixJQUFJLFlBQVksWUFBWTtBQUFBLFFBQ2pEO0FBQ0EscUJBQWEsS0FB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/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,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL3JlcXVpcmUtZml4ZWQtc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Qo=
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// src/require-type-out-of-type-only-imports.ts
|
|
2
|
+
import { ESLintUtils, TSESTree } from "@typescript-eslint/utils";
|
|
3
|
+
import getDocumentationUrl from "./get-documentation-url.mjs";
|
|
4
|
+
var ruleId = "require-type-out-of-type-only-imports";
|
|
5
|
+
var createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
|
|
6
|
+
var rule = createRule({
|
|
7
|
+
name: ruleId,
|
|
8
|
+
meta: {
|
|
9
|
+
type: "suggestion",
|
|
10
|
+
docs: {
|
|
11
|
+
description: 'Require "type" to be out side of type-only imports.'
|
|
12
|
+
},
|
|
13
|
+
messages: {
|
|
14
|
+
moveTypeOutside: 'Update the type-only imports to use "tpe" outside of the curly braces.'
|
|
15
|
+
},
|
|
16
|
+
fixable: "code",
|
|
17
|
+
schema: []
|
|
18
|
+
},
|
|
19
|
+
defaultOptions: [],
|
|
20
|
+
create(context) {
|
|
21
|
+
const sourceCode = context.sourceCode;
|
|
22
|
+
return {
|
|
23
|
+
ImportDeclaration(declaration) {
|
|
24
|
+
if (declaration.importKind === "type" || !declaration.specifiers.every(
|
|
25
|
+
(specifier) => specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier && specifier.importKind === "type"
|
|
26
|
+
)) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
context.report({
|
|
30
|
+
messageId: "moveTypeOutside",
|
|
31
|
+
node: declaration,
|
|
32
|
+
*fix(fixer) {
|
|
33
|
+
const moduleName = declaration.source.value;
|
|
34
|
+
const mergedSpecifiers = declaration.specifiers.filter((specifier) => specifier.type !== TSESTree.AST_NODE_TYPES.ImportDefaultSpecifier).map((specifier) => sourceCode.getText(specifier).replace("type ", ""));
|
|
35
|
+
const updatedImportDeclaration = `import type { ${mergedSpecifiers.join(", ")} } from '${moduleName}';`;
|
|
36
|
+
yield fixer.replaceText(declaration, updatedImportDeclaration);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
var require_type_out_of_type_only_imports_default = rule;
|
|
44
|
+
export {
|
|
45
|
+
require_type_out_of_type_only_imports_default as default,
|
|
46
|
+
ruleId
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL3JlcXVpcmUtdHlwZS1vdXQtb2YtdHlwZS1vbmx5LWltcG9ydHMudHMiXSwKICAibWFwcGluZ3MiOiAiO0FBUUEsU0FBUyxhQUFhLGdCQUFnQjtBQUN0QyxPQUFPLHlCQUF5QjtBQUV6QixJQUFNLFNBQVM7QUFFdEIsSUFBTSxhQUFhLFlBQVksWUFBWSxDQUFDLFNBQVMsb0JBQW9CLElBQUksQ0FBQztBQUU5RSxJQUFNLE9BQU8sV0FBVztBQUFBLEVBQ3RCLE1BQU07QUFBQSxFQUNOLE1BQU07QUFBQSxJQUNKLE1BQU07QUFBQSxJQUNOLE1BQU07QUFBQSxNQUNKLGFBQWE7QUFBQSxJQUNmO0FBQUEsSUFDQSxVQUFVO0FBQUEsTUFDUixpQkFBaUI7QUFBQSxJQUNuQjtBQUFBLElBQ0EsU0FBUztBQUFBLElBQ1QsUUFBUSxDQUFDO0FBQUEsRUFDWDtBQUFBLEVBQ0EsZ0JBQWdCLENBQUM7QUFBQSxFQUNqQixPQUFPLFNBQVM7QUFDZCxVQUFNLGFBQWEsUUFBUTtBQUUzQixXQUFPO0FBQUEsTUFDTCxrQkFBa0IsYUFBYTtBQUM3QixZQUNFLFlBQVksZUFBZSxVQUMzQixDQUFDLFlBQVksV0FBVztBQUFBLFVBQ3RCLENBQUMsY0FDQyxVQUFVLFNBQVMsU0FBUyxlQUFlLG1CQUFtQixVQUFVLGVBQWU7QUFBQSxRQUMzRixHQUNBO0FBQ0E7QUFBQSxRQUNGO0FBRUEsZ0JBQVEsT0FBTztBQUFBLFVBQ2IsV0FBVztBQUFBLFVBQ1gsTUFBTTtBQUFBLFVBQ04sQ0FBQyxJQUFJLE9BQU87QUFDVixrQkFBTSxhQUFhLFlBQVksT0FBTztBQUN0QyxrQkFBTSxtQkFBbUIsWUFBWSxXQUNsQyxPQUFPLENBQUMsY0FBYyxVQUFVLFNBQVMsU0FBUyxlQUFlLHNCQUFzQixFQUN2RixJQUFJLENBQUMsY0FBYyxXQUFXLFFBQVEsU0FBUyxFQUFFLFFBQVEsU0FBUyxFQUFFLENBQUM7QUFDeEUsa0JBQU0sMkJBQTJCLGlCQUFpQixpQkFBaUIsS0FBSyxJQUFJLENBQUMsWUFBWSxVQUFVO0FBRW5HLGtCQUFNLE1BQU0sWUFBWSxhQUFhLHdCQUF3QjtBQUFBLFVBQy9EO0FBQUEsUUFDRixDQUFDO0FBQUEsTUFDSDtBQUFBLElBQ0Y7QUFBQSxFQUNGO0FBQ0YsQ0FBQztBQUVELElBQU8sZ0RBQVE7IiwKICAibmFtZXMiOiBbXQp9Cg==
|
package/dist-types/index.d.ts
CHANGED
|
@@ -21,6 +21,10 @@ declare const _default: {
|
|
|
21
21
|
"no-full-response": import("@typescript-eslint/utils/ts-eslint").RuleModule<"unknownError" | "removeFullResponse", never[], import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
22
22
|
"no-mapped-response": import("@typescript-eslint/utils/ts-eslint").RuleModule<"unknownError" | "replaceFullResponseWithFetchResponse", never[], import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
23
23
|
"require-resolve-full-response": import("@typescript-eslint/utils/ts-eslint").RuleModule<"unknownError" | "invalidOptions", never[], import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
24
|
+
"no-duplicated-imports": import("@typescript-eslint/utils/ts-eslint").RuleModule<"mergeDuplicatedImports", never[], import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
25
|
+
"require-fixed-services-import": import("@typescript-eslint/utils/ts-eslint").RuleModule<"updateServicesImportFrom", never[], import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
26
|
+
"require-type-out-of-type-only-imports": import("@typescript-eslint/utils/ts-eslint").RuleModule<"moveTypeOutside", never[], import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
27
|
+
"no-unused-function-argument": import("@typescript-eslint/utils/ts-eslint").RuleModule<"unknownError" | "removeUnusedFunctionArguments", never[], import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
24
28
|
};
|
|
25
29
|
configs: {
|
|
26
30
|
all: {
|
|
@@ -38,13 +42,9 @@ declare const _default: {
|
|
|
38
42
|
"@checkdigit/no-promise-instance-method": string;
|
|
39
43
|
"@checkdigit/no-full-response": string;
|
|
40
44
|
"@checkdigit/require-resolve-full-response": string;
|
|
41
|
-
"@checkdigit/
|
|
42
|
-
"@checkdigit/
|
|
43
|
-
"@checkdigit/
|
|
44
|
-
"@checkdigit/no-status-code": string;
|
|
45
|
-
"@checkdigit/fetch-response-body-json": string;
|
|
46
|
-
"@checkdigit/fetch-response-header-getter-ts": string;
|
|
47
|
-
"@checkdigit/fetch-then": string;
|
|
45
|
+
"@checkdigit/no-duplicated-imports": string;
|
|
46
|
+
"@checkdigit/require-fixed-services-import": string;
|
|
47
|
+
"@checkdigit/require-type-out-of-type-only-imports": string;
|
|
48
48
|
};
|
|
49
49
|
};
|
|
50
50
|
recommended: {
|
|
@@ -67,8 +67,6 @@ declare const _default: {
|
|
|
67
67
|
files: string[];
|
|
68
68
|
}[];
|
|
69
69
|
rules: {
|
|
70
|
-
"@checkdigit/no-full-response": string;
|
|
71
|
-
"@checkdigit/require-resolve-full-response": string;
|
|
72
70
|
"@checkdigit/no-mapped-response": string;
|
|
73
71
|
"@checkdigit/add-url-domain": string;
|
|
74
72
|
"@checkdigit/no-fixture": string;
|
|
@@ -77,13 +75,12 @@ declare const _default: {
|
|
|
77
75
|
"@checkdigit/fetch-response-body-json": string;
|
|
78
76
|
"@checkdigit/fetch-response-header-getter-ts": string;
|
|
79
77
|
"@checkdigit/fetch-then": string;
|
|
78
|
+
"@checkdigit/no-unused-function-argument": string;
|
|
80
79
|
};
|
|
81
80
|
};
|
|
82
81
|
'agent-phase-2-production': {
|
|
83
82
|
ignorePatterns: string[];
|
|
84
83
|
rules: {
|
|
85
|
-
"@checkdigit/no-full-response": string;
|
|
86
|
-
"@checkdigit/require-resolve-full-response": string;
|
|
87
84
|
"@checkdigit/no-mapped-response": string;
|
|
88
85
|
"@checkdigit/add-url-domain": string;
|
|
89
86
|
"@checkdigit/no-fixture": string;
|
|
@@ -92,6 +89,7 @@ declare const _default: {
|
|
|
92
89
|
"@checkdigit/fetch-response-body-json": string;
|
|
93
90
|
"@checkdigit/fetch-response-header-getter-ts": string;
|
|
94
91
|
"@checkdigit/fetch-then": string;
|
|
92
|
+
"@checkdigit/no-unused-function-argument": string;
|
|
95
93
|
};
|
|
96
94
|
};
|
|
97
95
|
};
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@checkdigit/eslint-plugin","version":"6.6.0-PR.75-
|
|
1
|
+
{"name":"@checkdigit/eslint-plugin","version":"6.6.0-PR.75-2a52","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","require":"./dist-cjs/index.cjs","import":"./dist-mjs/index.mjs","default":"./dist-mjs/index.mjs"}},"files":["src","dist-types","dist-cjs","dist-mjs","!src/**/*.test.ts","!src/**/*.spec.ts","!dist-types/**/*.test.d.ts","!dist-types/**/*.spec.d.ts","!dist-cjs/**/*.test.cjs","!dist-cjs/**/*.spec.cjs","!dist-mjs/**/*.test.mjs","!dist-mjs/**/*.spec.mjs","SECURITY.md"],"scripts":{"build:dist-cjs":"rimraf dist-cjs && npx builder --type=commonjs --sourceMap --entryPoint=index.ts --outDir=dist-cjs --outFile=index.cjs --external=espree && echo \"module.exports = module.exports.default;\" >> dist-cjs/index.cjs","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 --ignore-path .gitignore .","lint:fix":"eslint --ignore-path .gitignore . --fix","prepublishOnly":"npm run build:dist-types && npm run build:dist-cjs && 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":"7.18.0","@typescript-eslint/utils":"7.18.0","ts-api-utils":"^1.3.0"},"devDependencies":{"@checkdigit/jest-config":"^6.0.2","@checkdigit/prettier-config":"^5.5.0","@checkdigit/typescript-config":"6.0.0","@types/eslint":"8.56.10","@typescript-eslint/eslint-plugin":"7.18.0","@typescript-eslint/parser":"7.18.0","@typescript-eslint/rule-tester":"7.18.0","eslint-config-prettier":"^9.1.0","eslint-plugin-eslint-plugin":"^6.2.0","eslint-plugin-import":"^2.29.1","eslint-plugin-no-only-tests":"^3.1.0","eslint-plugin-no-secrets":"^1.0.2","eslint-plugin-node":"^11.1.0","eslint-plugin-sonarjs":"0.24.0","http-status-codes":"^2.3.0"},"peerDependencies":{"eslint":">=8 <9"},"engines":{"node":">=20.14"}}
|
package/src/agent/fetch-then.ts
CHANGED
package/src/agent/fetch.ts
CHANGED
package/src/agent/no-fixture.ts
CHANGED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// agent/no-unused-function-argument.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
|
+
import { strict as assert } from 'node:assert';
|
|
11
|
+
import getDocumentationUrl from '../get-documentation-url';
|
|
12
|
+
|
|
13
|
+
export const ruleId = 'no-unused-function-argument';
|
|
14
|
+
|
|
15
|
+
const createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
|
|
16
|
+
|
|
17
|
+
const rule = createRule({
|
|
18
|
+
name: ruleId,
|
|
19
|
+
meta: {
|
|
20
|
+
type: 'suggestion',
|
|
21
|
+
docs: {
|
|
22
|
+
description: 'Remove unused function arguments.',
|
|
23
|
+
},
|
|
24
|
+
messages: {
|
|
25
|
+
removeUnusedFunctionArguments: 'Removing unused function arguments.',
|
|
26
|
+
unknownError: 'Unknown error occurred in file "{{fileName}}": {{ error }}.',
|
|
27
|
+
},
|
|
28
|
+
fixable: 'code',
|
|
29
|
+
schema: [],
|
|
30
|
+
},
|
|
31
|
+
defaultOptions: [],
|
|
32
|
+
create(context) {
|
|
33
|
+
const sourceCode = context.sourceCode;
|
|
34
|
+
|
|
35
|
+
// Function to check if a parameter is used in the function body
|
|
36
|
+
function isParameterUsed(parameter: TSESTree.Parameter, body: TSESTree.BlockStatement) {
|
|
37
|
+
if (parameter.type !== TSESTree.AST_NODE_TYPES.Identifier) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
const parameterName = parameter.name;
|
|
41
|
+
return sourceCode.getScope(body).references.some((ref) => ref.identifier.name === parameterName);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
FunctionDeclaration(functionDeclaration: TSESTree.FunctionDeclaration) {
|
|
46
|
+
try {
|
|
47
|
+
const parameters = functionDeclaration.params;
|
|
48
|
+
if (parameters.length === 0) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const body = functionDeclaration.body;
|
|
53
|
+
const parametersToKeep = parameters.filter((parameter) => isParameterUsed(parameter, body));
|
|
54
|
+
|
|
55
|
+
const updatedParameters = parametersToKeep.map((parameter) => sourceCode.getText(parameter)).join(', ');
|
|
56
|
+
context.report({
|
|
57
|
+
node: functionDeclaration,
|
|
58
|
+
messageId: 'removeUnusedFunctionArguments',
|
|
59
|
+
fix(fixer) {
|
|
60
|
+
const firstParameter = parameters[0];
|
|
61
|
+
const lastParameter = parameters.at(-1);
|
|
62
|
+
assert.ok(firstParameter !== undefined && lastParameter !== undefined);
|
|
63
|
+
return fixer.replaceTextRange([firstParameter.range[0], lastParameter.range[1]], updatedParameters);
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
} catch (error) {
|
|
67
|
+
// eslint-disable-next-line no-console
|
|
68
|
+
console.error(`Failed to apply ${ruleId} rule for file "${context.filename}":`, error);
|
|
69
|
+
context.report({
|
|
70
|
+
node: functionDeclaration,
|
|
71
|
+
messageId: 'unknownError',
|
|
72
|
+
data: {
|
|
73
|
+
fileName: context.filename,
|
|
74
|
+
error: error instanceof Error ? error.toString() : JSON.stringify(error),
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
export default rule;
|
package/src/agent/url.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -13,15 +13,25 @@ import fetchResponseHeaderGetter, {
|
|
|
13
13
|
} from './agent/fetch-response-header-getter';
|
|
14
14
|
import fetchThen, { ruleId as fetchThenRuleId } from './agent/fetch-then';
|
|
15
15
|
import invalidJsonStringify, { ruleId as invalidJsonStringifyRuleId } from './invalid-json-stringify';
|
|
16
|
+
import noDuplicatedImports, { ruleId as noDuplicatedImportsRuleId } from './no-duplicated-imports';
|
|
16
17
|
import noFixture, { ruleId as noFixtureRuleId } from './agent/no-fixture';
|
|
17
18
|
import noFullResponse, { ruleId as noFullResponseRuleId } from './agent/no-full-response';
|
|
18
19
|
import noMappedResponse, { ruleId as noMappedResponseRuleId } from './agent/no-mapped-response';
|
|
19
20
|
import noPromiseInstanceMethod, { ruleId as noPromiseInstanceMethodRuleId } from './no-promise-instance-method';
|
|
20
21
|
import noServiceWrapper, { ruleId as noServiceWrapperRuleId } from './agent/no-service-wrapper';
|
|
21
22
|
import noStatusCode, { ruleId as noStatusCodeRuleId } from './agent/no-status-code';
|
|
23
|
+
import noUnusedFunctionArguments, {
|
|
24
|
+
ruleId as noUnusedFunctionArgumentsRuleId,
|
|
25
|
+
} from './agent/no-unused-function-argument';
|
|
26
|
+
import requireFixedServicesImport, {
|
|
27
|
+
ruleId as requireFixedServicesImportRuleId,
|
|
28
|
+
} from './require-fixed-services-import';
|
|
22
29
|
import requireResolveFullResponse, {
|
|
23
30
|
ruleId as requireResolveFullResponseRuleId,
|
|
24
31
|
} from './require-resolve-full-response';
|
|
32
|
+
import requireTypeOutOfTypeOnlyImports, {
|
|
33
|
+
ruleId as requireTypeOutOfTypeOnlyImportsRuleId,
|
|
34
|
+
} from './require-type-out-of-type-only-imports';
|
|
25
35
|
import filePathComment from './file-path-comment';
|
|
26
36
|
import noCardNumbers from './no-card-numbers';
|
|
27
37
|
import noTestImport from './no-test-import';
|
|
@@ -55,6 +65,10 @@ export default {
|
|
|
55
65
|
[noFullResponseRuleId]: noFullResponse,
|
|
56
66
|
[noMappedResponseRuleId]: noMappedResponse,
|
|
57
67
|
[requireResolveFullResponseRuleId]: requireResolveFullResponse,
|
|
68
|
+
[noDuplicatedImportsRuleId]: noDuplicatedImports,
|
|
69
|
+
[requireFixedServicesImportRuleId]: requireFixedServicesImport,
|
|
70
|
+
[requireTypeOutOfTypeOnlyImportsRuleId]: requireTypeOutOfTypeOnlyImports,
|
|
71
|
+
[noUnusedFunctionArgumentsRuleId]: noUnusedFunctionArguments,
|
|
58
72
|
},
|
|
59
73
|
configs: {
|
|
60
74
|
all: {
|
|
@@ -72,13 +86,9 @@ export default {
|
|
|
72
86
|
[`@checkdigit/${noPromiseInstanceMethodRuleId}`]: 'error',
|
|
73
87
|
[`@checkdigit/${noFullResponseRuleId}`]: 'error',
|
|
74
88
|
[`@checkdigit/${requireResolveFullResponseRuleId}`]: 'error',
|
|
75
|
-
[`@checkdigit/${
|
|
76
|
-
[`@checkdigit/${
|
|
77
|
-
[`@checkdigit/${
|
|
78
|
-
[`@checkdigit/${noStatusCodeRuleId}`]: 'off',
|
|
79
|
-
[`@checkdigit/${fetchResponseBodyJsonRuleId}`]: 'off',
|
|
80
|
-
[`@checkdigit/${fetchResponseHeaderGetterRuleId}`]: 'off',
|
|
81
|
-
[`@checkdigit/${fetchThenRuleId}`]: 'off',
|
|
89
|
+
[`@checkdigit/${noDuplicatedImportsRuleId}`]: 'error',
|
|
90
|
+
[`@checkdigit/${requireFixedServicesImportRuleId}`]: 'error',
|
|
91
|
+
[`@checkdigit/${requireTypeOutOfTypeOnlyImportsRuleId}`]: 'error',
|
|
82
92
|
},
|
|
83
93
|
},
|
|
84
94
|
recommended: {
|
|
@@ -103,8 +113,6 @@ export default {
|
|
|
103
113
|
},
|
|
104
114
|
],
|
|
105
115
|
rules: {
|
|
106
|
-
[`@checkdigit/${noFullResponseRuleId}`]: 'error',
|
|
107
|
-
[`@checkdigit/${requireResolveFullResponseRuleId}`]: 'error',
|
|
108
116
|
[`@checkdigit/${noMappedResponseRuleId}`]: 'error',
|
|
109
117
|
[`@checkdigit/${addUrlDomainRuleId}`]: 'error',
|
|
110
118
|
[`@checkdigit/${noFixtureRuleId}`]: 'error',
|
|
@@ -113,13 +121,12 @@ export default {
|
|
|
113
121
|
[`@checkdigit/${fetchResponseBodyJsonRuleId}`]: 'error',
|
|
114
122
|
[`@checkdigit/${fetchResponseHeaderGetterRuleId}`]: 'error',
|
|
115
123
|
[`@checkdigit/${fetchThenRuleId}`]: 'error',
|
|
124
|
+
[`@checkdigit/${noUnusedFunctionArgumentsRuleId}`]: 'error',
|
|
116
125
|
},
|
|
117
126
|
},
|
|
118
127
|
'agent-phase-2-production': {
|
|
119
128
|
ignorePatterns: ['*.spec.ts', '*.test.ts'],
|
|
120
129
|
rules: {
|
|
121
|
-
[`@checkdigit/${noFullResponseRuleId}`]: 'error',
|
|
122
|
-
[`@checkdigit/${requireResolveFullResponseRuleId}`]: 'error',
|
|
123
130
|
[`@checkdigit/${noMappedResponseRuleId}`]: 'error',
|
|
124
131
|
[`@checkdigit/${addUrlDomainRuleId}`]: 'error',
|
|
125
132
|
[`@checkdigit/${noFixtureRuleId}`]: 'off',
|
|
@@ -128,6 +135,7 @@ export default {
|
|
|
128
135
|
[`@checkdigit/${fetchResponseBodyJsonRuleId}`]: 'error',
|
|
129
136
|
[`@checkdigit/${fetchResponseHeaderGetterRuleId}`]: 'error',
|
|
130
137
|
[`@checkdigit/${fetchThenRuleId}`]: 'error',
|
|
138
|
+
[`@checkdigit/${noUnusedFunctionArgumentsRuleId}`]: 'error',
|
|
131
139
|
},
|
|
132
140
|
},
|
|
133
141
|
},
|
package/src/library/format.ts
CHANGED
package/src/library/tree.ts
CHANGED
package/src/library/ts-tree.ts
CHANGED
package/src/library/variable.ts
CHANGED