@checkdigit/eslint-plugin 6.6.0-PR.75-b19c → 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 +584 -515
- package/dist-cjs/metafile.json +51 -17
- package/dist-mjs/agent/no-unused-function-argument.mjs +71 -0
- package/dist-mjs/index.mjs +10 -4
- package/dist-types/agent/no-unused-function-argument.d.ts +4 -0
- package/dist-types/index.d.ts +3 -0
- package/package.json +1 -1
- package/src/agent/no-unused-function-argument.ts +83 -0
- package/src/index.ts +6 -0
package/dist-cjs/metafile.json
CHANGED
|
@@ -12548,6 +12548,27 @@
|
|
|
12548
12548
|
],
|
|
12549
12549
|
"format": "esm"
|
|
12550
12550
|
},
|
|
12551
|
+
"src/agent/no-unused-function-argument.ts": {
|
|
12552
|
+
"bytes": 2862,
|
|
12553
|
+
"imports": [
|
|
12554
|
+
{
|
|
12555
|
+
"path": "node_modules/@typescript-eslint/utils/dist/index.js",
|
|
12556
|
+
"kind": "import-statement",
|
|
12557
|
+
"original": "@typescript-eslint/utils"
|
|
12558
|
+
},
|
|
12559
|
+
{
|
|
12560
|
+
"path": "node:assert",
|
|
12561
|
+
"kind": "import-statement",
|
|
12562
|
+
"external": true
|
|
12563
|
+
},
|
|
12564
|
+
{
|
|
12565
|
+
"path": "src/get-documentation-url.ts",
|
|
12566
|
+
"kind": "import-statement",
|
|
12567
|
+
"original": "../get-documentation-url"
|
|
12568
|
+
}
|
|
12569
|
+
],
|
|
12570
|
+
"format": "esm"
|
|
12571
|
+
},
|
|
12551
12572
|
"src/require-fixed-services-import.ts": {
|
|
12552
12573
|
"bytes": 1467,
|
|
12553
12574
|
"imports": [
|
|
@@ -12662,7 +12683,7 @@
|
|
|
12662
12683
|
"format": "esm"
|
|
12663
12684
|
},
|
|
12664
12685
|
"src/index.ts": {
|
|
12665
|
-
"bytes":
|
|
12686
|
+
"bytes": 6677,
|
|
12666
12687
|
"imports": [
|
|
12667
12688
|
{
|
|
12668
12689
|
"path": "src/agent/add-url-domain.ts",
|
|
@@ -12724,6 +12745,11 @@
|
|
|
12724
12745
|
"kind": "import-statement",
|
|
12725
12746
|
"original": "./agent/no-status-code"
|
|
12726
12747
|
},
|
|
12748
|
+
{
|
|
12749
|
+
"path": "src/agent/no-unused-function-argument.ts",
|
|
12750
|
+
"kind": "import-statement",
|
|
12751
|
+
"original": "./agent/no-unused-function-argument"
|
|
12752
|
+
},
|
|
12727
12753
|
{
|
|
12728
12754
|
"path": "src/require-fixed-services-import.ts",
|
|
12729
12755
|
"kind": "import-statement",
|
|
@@ -13326,6 +13352,11 @@
|
|
|
13326
13352
|
"kind": "require-call",
|
|
13327
13353
|
"external": true
|
|
13328
13354
|
},
|
|
13355
|
+
{
|
|
13356
|
+
"path": "node:assert",
|
|
13357
|
+
"kind": "require-call",
|
|
13358
|
+
"external": true
|
|
13359
|
+
},
|
|
13329
13360
|
{
|
|
13330
13361
|
"path": "node:assert",
|
|
13331
13362
|
"kind": "require-call",
|
|
@@ -13639,7 +13670,7 @@
|
|
|
13639
13670
|
"bytesInOutput": 157
|
|
13640
13671
|
},
|
|
13641
13672
|
"node_modules/@eslint/eslintrc/dist/eslintrc.cjs": {
|
|
13642
|
-
"bytesInOutput":
|
|
13673
|
+
"bytesInOutput": 103415
|
|
13643
13674
|
},
|
|
13644
13675
|
"node_modules/@eslint/js/src/configs/eslint-all.js": {
|
|
13645
13676
|
"bytesInOutput": 7567
|
|
@@ -13684,7 +13715,7 @@
|
|
|
13684
13715
|
"bytesInOutput": 2610
|
|
13685
13716
|
},
|
|
13686
13717
|
"node_modules/eslint-scope/dist/eslint-scope.cjs": {
|
|
13687
|
-
"bytesInOutput":
|
|
13718
|
+
"bytesInOutput": 44545
|
|
13688
13719
|
},
|
|
13689
13720
|
"node_modules/lodash.merge/index.js": {
|
|
13690
13721
|
"bytesInOutput": 25626
|
|
@@ -13738,7 +13769,7 @@
|
|
|
13738
13769
|
"bytesInOutput": 1193
|
|
13739
13770
|
},
|
|
13740
13771
|
"node_modules/eslint/lib/source-code/token-store/index.js": {
|
|
13741
|
-
"bytesInOutput":
|
|
13772
|
+
"bytesInOutput": 19918
|
|
13742
13773
|
},
|
|
13743
13774
|
"node_modules/eslint/conf/globals.js": {
|
|
13744
13775
|
"bytesInOutput": 2513
|
|
@@ -13795,7 +13826,7 @@
|
|
|
13795
13826
|
"bytesInOutput": 5777
|
|
13796
13827
|
},
|
|
13797
13828
|
"node_modules/eslint/lib/linter/code-path-analysis/fork-context.js": {
|
|
13798
|
-
"bytesInOutput":
|
|
13829
|
+
"bytesInOutput": 7677
|
|
13799
13830
|
},
|
|
13800
13831
|
"node_modules/eslint/lib/linter/code-path-analysis/code-path-state.js": {
|
|
13801
13832
|
"bytesInOutput": 45357
|
|
@@ -13807,7 +13838,7 @@
|
|
|
13807
13838
|
"bytesInOutput": 7482
|
|
13808
13839
|
},
|
|
13809
13840
|
"node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js": {
|
|
13810
|
-
"bytesInOutput":
|
|
13841
|
+
"bytesInOutput": 17036
|
|
13811
13842
|
},
|
|
13812
13843
|
"node_modules/eslint/lib/linter/apply-disable-directives.js": {
|
|
13813
13844
|
"bytesInOutput": 10137
|
|
@@ -13825,7 +13856,7 @@
|
|
|
13825
13856
|
"bytesInOutput": 467
|
|
13826
13857
|
},
|
|
13827
13858
|
"node_modules/eslint/lib/linter/report-translator.js": {
|
|
13828
|
-
"bytesInOutput":
|
|
13859
|
+
"bytesInOutput": 7454
|
|
13829
13860
|
},
|
|
13830
13861
|
"node_modules/eslint/lib/rules/utils/lazy-loading-rule-map.js": {
|
|
13831
13862
|
"bytesInOutput": 2552
|
|
@@ -14992,7 +15023,7 @@
|
|
|
14992
15023
|
"bytesInOutput": 6454
|
|
14993
15024
|
},
|
|
14994
15025
|
"node_modules/glob/sync.js": {
|
|
14995
|
-
"bytesInOutput":
|
|
15026
|
+
"bytesInOutput": 11019
|
|
14996
15027
|
},
|
|
14997
15028
|
"node_modules/wrappy/wrappy.js": {
|
|
14998
15029
|
"bytesInOutput": 841
|
|
@@ -15004,10 +15035,10 @@
|
|
|
15004
15035
|
"bytesInOutput": 1156
|
|
15005
15036
|
},
|
|
15006
15037
|
"node_modules/glob/glob.js": {
|
|
15007
|
-
"bytesInOutput":
|
|
15038
|
+
"bytesInOutput": 16997
|
|
15008
15039
|
},
|
|
15009
15040
|
"node_modules/rimraf/rimraf.js": {
|
|
15010
|
-
"bytesInOutput":
|
|
15041
|
+
"bytesInOutput": 8427
|
|
15011
15042
|
},
|
|
15012
15043
|
"node_modules/flat-cache/src/del.js": {
|
|
15013
15044
|
"bytesInOutput": 355
|
|
@@ -15022,13 +15053,13 @@
|
|
|
15022
15053
|
"bytesInOutput": 2959
|
|
15023
15054
|
},
|
|
15024
15055
|
"node_modules/eslint/lib/cli-engine/lint-result-cache.js": {
|
|
15025
|
-
"bytesInOutput":
|
|
15056
|
+
"bytesInOutput": 5078
|
|
15026
15057
|
},
|
|
15027
15058
|
"node_modules/eslint/lib/eslint/flat-eslint.js": {
|
|
15028
15059
|
"bytesInOutput": 25120
|
|
15029
15060
|
},
|
|
15030
15061
|
"node_modules/eslint/lib/rule-tester/flat-rule-tester.js": {
|
|
15031
|
-
"bytesInOutput":
|
|
15062
|
+
"bytesInOutput": 31667
|
|
15032
15063
|
},
|
|
15033
15064
|
"node_modules/eslint/conf/default-cli-options.js": {
|
|
15034
15065
|
"bytesInOutput": 783
|
|
@@ -15067,7 +15098,7 @@
|
|
|
15067
15098
|
"bytesInOutput": 7265
|
|
15068
15099
|
},
|
|
15069
15100
|
"node_modules/eslint/lib/rule-tester/rule-tester.js": {
|
|
15070
|
-
"bytesInOutput":
|
|
15101
|
+
"bytesInOutput": 33257
|
|
15071
15102
|
},
|
|
15072
15103
|
"node_modules/eslint/lib/rule-tester/index.js": {
|
|
15073
15104
|
"bytesInOutput": 206
|
|
@@ -15103,7 +15134,7 @@
|
|
|
15103
15134
|
"bytesInOutput": 608
|
|
15104
15135
|
},
|
|
15105
15136
|
"node_modules/@typescript-eslint/scope-manager/dist/assert.js": {
|
|
15106
|
-
"bytesInOutput":
|
|
15137
|
+
"bytesInOutput": 349
|
|
15107
15138
|
},
|
|
15108
15139
|
"node_modules/@typescript-eslint/scope-manager/dist/ID.js": {
|
|
15109
15140
|
"bytesInOutput": 671
|
|
@@ -15583,7 +15614,7 @@
|
|
|
15583
15614
|
"bytesInOutput": 2219
|
|
15584
15615
|
},
|
|
15585
15616
|
"src/index.ts": {
|
|
15586
|
-
"bytesInOutput":
|
|
15617
|
+
"bytesInOutput": 3993
|
|
15587
15618
|
},
|
|
15588
15619
|
"src/agent/url.ts": {
|
|
15589
15620
|
"bytesInOutput": 745
|
|
@@ -15648,8 +15679,11 @@
|
|
|
15648
15679
|
"src/agent/no-status-code.ts": {
|
|
15649
15680
|
"bytesInOutput": 2042
|
|
15650
15681
|
},
|
|
15682
|
+
"src/agent/no-unused-function-argument.ts": {
|
|
15683
|
+
"bytesInOutput": 2475
|
|
15684
|
+
},
|
|
15651
15685
|
"src/require-fixed-services-import.ts": {
|
|
15652
|
-
"bytesInOutput":
|
|
15686
|
+
"bytesInOutput": 1262
|
|
15653
15687
|
},
|
|
15654
15688
|
"src/require-resolve-full-response.ts": {
|
|
15655
15689
|
"bytesInOutput": 7200
|
|
@@ -15685,7 +15719,7 @@
|
|
|
15685
15719
|
"bytesInOutput": 3362
|
|
15686
15720
|
}
|
|
15687
15721
|
},
|
|
15688
|
-
"bytes":
|
|
15722
|
+
"bytes": 4349859
|
|
15689
15723
|
}
|
|
15690
15724
|
}
|
|
15691
15725
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// src/agent/no-unused-function-argument.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-unused-function-argument";
|
|
6
|
+
var createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
|
|
7
|
+
var rule = createRule({
|
|
8
|
+
name: ruleId,
|
|
9
|
+
meta: {
|
|
10
|
+
type: "suggestion",
|
|
11
|
+
docs: {
|
|
12
|
+
description: "Remove unused function arguments."
|
|
13
|
+
},
|
|
14
|
+
messages: {
|
|
15
|
+
removeUnusedFunctionArguments: "Removing unused function arguments.",
|
|
16
|
+
unknownError: 'Unknown error occurred in file "{{fileName}}": {{ error }}.'
|
|
17
|
+
},
|
|
18
|
+
fixable: "code",
|
|
19
|
+
schema: []
|
|
20
|
+
},
|
|
21
|
+
defaultOptions: [],
|
|
22
|
+
create(context) {
|
|
23
|
+
const sourceCode = context.sourceCode;
|
|
24
|
+
function isParameterUsed(parameter, body) {
|
|
25
|
+
if (parameter.type !== TSESTree.AST_NODE_TYPES.Identifier) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
const parameterName = parameter.name;
|
|
29
|
+
return sourceCode.getScope(body).references.some((ref) => ref.identifier.name === parameterName);
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
FunctionDeclaration(functionDeclaration) {
|
|
33
|
+
try {
|
|
34
|
+
const parameters = functionDeclaration.params;
|
|
35
|
+
if (parameters.length === 0) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const body = functionDeclaration.body;
|
|
39
|
+
const parametersToKeep = parameters.filter((parameter) => isParameterUsed(parameter, body));
|
|
40
|
+
const updatedParameters = parametersToKeep.map((parameter) => sourceCode.getText(parameter)).join(", ");
|
|
41
|
+
context.report({
|
|
42
|
+
node: functionDeclaration,
|
|
43
|
+
messageId: "removeUnusedFunctionArguments",
|
|
44
|
+
fix(fixer) {
|
|
45
|
+
const firstParameter = parameters[0];
|
|
46
|
+
const lastParameter = parameters.at(-1);
|
|
47
|
+
assert.ok(firstParameter !== void 0 && lastParameter !== void 0);
|
|
48
|
+
return fixer.replaceTextRange([firstParameter.range[0], lastParameter.range[1]], updatedParameters);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error(`Failed to apply ${ruleId} rule for file "${context.filename}":`, error);
|
|
53
|
+
context.report({
|
|
54
|
+
node: functionDeclaration,
|
|
55
|
+
messageId: "unknownError",
|
|
56
|
+
data: {
|
|
57
|
+
fileName: context.filename,
|
|
58
|
+
error: error instanceof Error ? error.toString() : JSON.stringify(error)
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
var no_unused_function_argument_default = rule;
|
|
67
|
+
export {
|
|
68
|
+
no_unused_function_argument_default as default,
|
|
69
|
+
ruleId
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vLi4vc3JjL2FnZW50L25vLXVudXNlZC1mdW5jdGlvbi1hcmd1bWVudC50cyJdLAogICJtYXBwaW5ncyI6ICI7QUFRQSxTQUFTLGFBQWEsZ0JBQWdCO0FBQ3RDLFNBQVMsVUFBVSxjQUFjO0FBQ2pDLE9BQU8seUJBQXlCO0FBRXpCLElBQU0sU0FBUztBQUV0QixJQUFNLGFBQWEsWUFBWSxZQUFZLENBQUMsU0FBUyxvQkFBb0IsSUFBSSxDQUFDO0FBRTlFLElBQU0sT0FBTyxXQUFXO0FBQUEsRUFDdEIsTUFBTTtBQUFBLEVBQ04sTUFBTTtBQUFBLElBQ0osTUFBTTtBQUFBLElBQ04sTUFBTTtBQUFBLE1BQ0osYUFBYTtBQUFBLElBQ2Y7QUFBQSxJQUNBLFVBQVU7QUFBQSxNQUNSLCtCQUErQjtBQUFBLE1BQy9CLGNBQWM7QUFBQSxJQUNoQjtBQUFBLElBQ0EsU0FBUztBQUFBLElBQ1QsUUFBUSxDQUFDO0FBQUEsRUFDWD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UFBQSxZQUNwRztBQUFBLFVBQ0YsQ0FBQztBQUFBLFFBQ0gsU0FBUyxPQUFPO0FBRWQsa0JBQVEsTUFBTSxtQkFBbUIsTUFBTSxtQkFBbUIsUUFBUSxRQUFRLE1BQU0sS0FBSztBQUNyRixrQkFBUSxPQUFPO0FBQUEsWUFDYixNQUFNO0FBQUEsWUFDTixXQUFXO0FBQUEsWUFDWCxNQUFNO0FBQUEsY0FDSixVQUFVLFFBQVE7QUFBQSxjQUNsQixPQUFPLGlCQUFpQixRQUFRLE1BQU0sU0FBUyxJQUFJLEtBQUssVUFBVSxLQUFLO0FBQUEsWUFDekU7QUFBQSxVQUNGLENBQUM7QUFBQSxRQUNIO0FBQUEsTUFDRjtBQUFBLElBQ0Y7QUFBQSxFQUNGO0FBQ0YsQ0FBQztBQUVELElBQU8sc0NBQVE7IiwKICAibmFtZXMiOiBbXQp9Cg==
|
package/dist-mjs/index.mjs
CHANGED
|
@@ -13,6 +13,9 @@ import noMappedResponse, { ruleId as noMappedResponseRuleId } from "./agent/no-m
|
|
|
13
13
|
import noPromiseInstanceMethod, { ruleId as noPromiseInstanceMethodRuleId } from "./no-promise-instance-method.mjs";
|
|
14
14
|
import noServiceWrapper, { ruleId as noServiceWrapperRuleId } from "./agent/no-service-wrapper.mjs";
|
|
15
15
|
import noStatusCode, { ruleId as noStatusCodeRuleId } from "./agent/no-status-code.mjs";
|
|
16
|
+
import noUnusedFunctionArguments, {
|
|
17
|
+
ruleId as noUnusedFunctionArgumentsRuleId
|
|
18
|
+
} from "./agent/no-unused-function-argument.mjs";
|
|
16
19
|
import requireFixedServicesImport, {
|
|
17
20
|
ruleId as requireFixedServicesImportRuleId
|
|
18
21
|
} from "./require-fixed-services-import.mjs";
|
|
@@ -56,7 +59,8 @@ var src_default = {
|
|
|
56
59
|
[requireResolveFullResponseRuleId]: requireResolveFullResponse,
|
|
57
60
|
[noDuplicatedImportsRuleId]: noDuplicatedImports,
|
|
58
61
|
[requireFixedServicesImportRuleId]: requireFixedServicesImport,
|
|
59
|
-
[requireTypeOutOfTypeOnlyImportsRuleId]: requireTypeOutOfTypeOnlyImports
|
|
62
|
+
[requireTypeOutOfTypeOnlyImportsRuleId]: requireTypeOutOfTypeOnlyImports,
|
|
63
|
+
[noUnusedFunctionArgumentsRuleId]: noUnusedFunctionArguments
|
|
60
64
|
},
|
|
61
65
|
configs: {
|
|
62
66
|
all: {
|
|
@@ -108,7 +112,8 @@ var src_default = {
|
|
|
108
112
|
[`@checkdigit/${noStatusCodeRuleId}`]: "error",
|
|
109
113
|
[`@checkdigit/${fetchResponseBodyJsonRuleId}`]: "error",
|
|
110
114
|
[`@checkdigit/${fetchResponseHeaderGetterRuleId}`]: "error",
|
|
111
|
-
[`@checkdigit/${fetchThenRuleId}`]: "error"
|
|
115
|
+
[`@checkdigit/${fetchThenRuleId}`]: "error",
|
|
116
|
+
[`@checkdigit/${noUnusedFunctionArgumentsRuleId}`]: "error"
|
|
112
117
|
}
|
|
113
118
|
},
|
|
114
119
|
"agent-phase-2-production": {
|
|
@@ -121,7 +126,8 @@ var src_default = {
|
|
|
121
126
|
[`@checkdigit/${noStatusCodeRuleId}`]: "error",
|
|
122
127
|
[`@checkdigit/${fetchResponseBodyJsonRuleId}`]: "error",
|
|
123
128
|
[`@checkdigit/${fetchResponseHeaderGetterRuleId}`]: "error",
|
|
124
|
-
[`@checkdigit/${fetchThenRuleId}`]: "error"
|
|
129
|
+
[`@checkdigit/${fetchThenRuleId}`]: "error",
|
|
130
|
+
[`@checkdigit/${noUnusedFunctionArgumentsRuleId}`]: "error"
|
|
125
131
|
}
|
|
126
132
|
}
|
|
127
133
|
}
|
|
@@ -129,4 +135,4 @@ var src_default = {
|
|
|
129
135
|
export {
|
|
130
136
|
src_default as default
|
|
131
137
|
};
|
|
132
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
138
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3Jj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/utils/ts-eslint").RuleModule<"mergeDuplicatedImports", never[], import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
25
25
|
"require-fixed-services-import": import("@typescript-eslint/utils/ts-eslint").RuleModule<"updateServicesImportFrom", never[], import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
26
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>;
|
|
27
28
|
};
|
|
28
29
|
configs: {
|
|
29
30
|
all: {
|
|
@@ -74,6 +75,7 @@ declare const _default: {
|
|
|
74
75
|
"@checkdigit/fetch-response-body-json": string;
|
|
75
76
|
"@checkdigit/fetch-response-header-getter-ts": string;
|
|
76
77
|
"@checkdigit/fetch-then": string;
|
|
78
|
+
"@checkdigit/no-unused-function-argument": string;
|
|
77
79
|
};
|
|
78
80
|
};
|
|
79
81
|
'agent-phase-2-production': {
|
|
@@ -87,6 +89,7 @@ declare const _default: {
|
|
|
87
89
|
"@checkdigit/fetch-response-body-json": string;
|
|
88
90
|
"@checkdigit/fetch-response-header-getter-ts": string;
|
|
89
91
|
"@checkdigit/fetch-then": string;
|
|
92
|
+
"@checkdigit/no-unused-function-argument": string;
|
|
90
93
|
};
|
|
91
94
|
};
|
|
92
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"}}
|
|
@@ -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/index.ts
CHANGED
|
@@ -20,6 +20,9 @@ import noMappedResponse, { ruleId as noMappedResponseRuleId } from './agent/no-m
|
|
|
20
20
|
import noPromiseInstanceMethod, { ruleId as noPromiseInstanceMethodRuleId } from './no-promise-instance-method';
|
|
21
21
|
import noServiceWrapper, { ruleId as noServiceWrapperRuleId } from './agent/no-service-wrapper';
|
|
22
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';
|
|
23
26
|
import requireFixedServicesImport, {
|
|
24
27
|
ruleId as requireFixedServicesImportRuleId,
|
|
25
28
|
} from './require-fixed-services-import';
|
|
@@ -65,6 +68,7 @@ export default {
|
|
|
65
68
|
[noDuplicatedImportsRuleId]: noDuplicatedImports,
|
|
66
69
|
[requireFixedServicesImportRuleId]: requireFixedServicesImport,
|
|
67
70
|
[requireTypeOutOfTypeOnlyImportsRuleId]: requireTypeOutOfTypeOnlyImports,
|
|
71
|
+
[noUnusedFunctionArgumentsRuleId]: noUnusedFunctionArguments,
|
|
68
72
|
},
|
|
69
73
|
configs: {
|
|
70
74
|
all: {
|
|
@@ -117,6 +121,7 @@ export default {
|
|
|
117
121
|
[`@checkdigit/${fetchResponseBodyJsonRuleId}`]: 'error',
|
|
118
122
|
[`@checkdigit/${fetchResponseHeaderGetterRuleId}`]: 'error',
|
|
119
123
|
[`@checkdigit/${fetchThenRuleId}`]: 'error',
|
|
124
|
+
[`@checkdigit/${noUnusedFunctionArgumentsRuleId}`]: 'error',
|
|
120
125
|
},
|
|
121
126
|
},
|
|
122
127
|
'agent-phase-2-production': {
|
|
@@ -130,6 +135,7 @@ export default {
|
|
|
130
135
|
[`@checkdigit/${fetchResponseBodyJsonRuleId}`]: 'error',
|
|
131
136
|
[`@checkdigit/${fetchResponseHeaderGetterRuleId}`]: 'error',
|
|
132
137
|
[`@checkdigit/${fetchThenRuleId}`]: 'error',
|
|
138
|
+
[`@checkdigit/${noUnusedFunctionArgumentsRuleId}`]: 'error',
|
|
133
139
|
},
|
|
134
140
|
},
|
|
135
141
|
},
|