@checkdigit/eslint-plugin 6.6.0-PR.75-3378 → 6.6.0-PR.75-7c7f
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/metafile.json
CHANGED
|
@@ -416,7 +416,7 @@
|
|
|
416
416
|
"format": "cjs"
|
|
417
417
|
},
|
|
418
418
|
"node_modules/ms/index.js": {
|
|
419
|
-
"bytes":
|
|
419
|
+
"bytes": 3135,
|
|
420
420
|
"imports": [],
|
|
421
421
|
"format": "cjs"
|
|
422
422
|
},
|
|
@@ -432,7 +432,7 @@
|
|
|
432
432
|
"format": "cjs"
|
|
433
433
|
},
|
|
434
434
|
"node_modules/debug/src/browser.js": {
|
|
435
|
-
"bytes":
|
|
435
|
+
"bytes": 6131,
|
|
436
436
|
"imports": [
|
|
437
437
|
{
|
|
438
438
|
"path": "node_modules/debug/src/common.js",
|
|
@@ -12166,7 +12166,7 @@
|
|
|
12166
12166
|
"format": "esm"
|
|
12167
12167
|
},
|
|
12168
12168
|
"package.json": {
|
|
12169
|
-
"bytes":
|
|
12169
|
+
"bytes": 2913,
|
|
12170
12170
|
"imports": [],
|
|
12171
12171
|
"format": "esm",
|
|
12172
12172
|
"with": {
|
|
@@ -12324,7 +12324,7 @@
|
|
|
12324
12324
|
"format": "esm"
|
|
12325
12325
|
},
|
|
12326
12326
|
"src/agent/fix-function-call-arguments.ts": {
|
|
12327
|
-
"bytes":
|
|
12327
|
+
"bytes": 5924,
|
|
12328
12328
|
"imports": [
|
|
12329
12329
|
{
|
|
12330
12330
|
"path": "node_modules/@typescript-eslint/utils/dist/index.js",
|
|
@@ -12336,6 +12336,11 @@
|
|
|
12336
12336
|
"kind": "import-statement",
|
|
12337
12337
|
"external": true
|
|
12338
12338
|
},
|
|
12339
|
+
{
|
|
12340
|
+
"path": "node_modules/debug/src/index.js",
|
|
12341
|
+
"kind": "import-statement",
|
|
12342
|
+
"original": "debug"
|
|
12343
|
+
},
|
|
12339
12344
|
{
|
|
12340
12345
|
"path": "src/get-documentation-url.ts",
|
|
12341
12346
|
"kind": "import-statement",
|
|
@@ -13566,16 +13571,16 @@
|
|
|
13566
13571
|
"bytesInOutput": 4583
|
|
13567
13572
|
},
|
|
13568
13573
|
"node_modules/eslint/node_modules/minimatch/minimatch.js": {
|
|
13569
|
-
"bytesInOutput":
|
|
13574
|
+
"bytesInOutput": 18248
|
|
13570
13575
|
},
|
|
13571
13576
|
"node_modules/ms/index.js": {
|
|
13572
13577
|
"bytesInOutput": 2883
|
|
13573
13578
|
},
|
|
13574
13579
|
"node_modules/debug/src/common.js": {
|
|
13575
|
-
"bytesInOutput":
|
|
13580
|
+
"bytesInOutput": 5483
|
|
13576
13581
|
},
|
|
13577
13582
|
"node_modules/debug/src/browser.js": {
|
|
13578
|
-
"bytesInOutput":
|
|
13583
|
+
"bytesInOutput": 4675
|
|
13579
13584
|
},
|
|
13580
13585
|
"node_modules/has-flag/index.js": {
|
|
13581
13586
|
"bytesInOutput": 459
|
|
@@ -13584,7 +13589,7 @@
|
|
|
13584
13589
|
"bytesInOutput": 3132
|
|
13585
13590
|
},
|
|
13586
13591
|
"node_modules/debug/src/node.js": {
|
|
13587
|
-
"bytesInOutput":
|
|
13592
|
+
"bytesInOutput": 4325
|
|
13588
13593
|
},
|
|
13589
13594
|
"node_modules/debug/src/index.js": {
|
|
13590
13595
|
"bytesInOutput": 316
|
|
@@ -13611,7 +13616,7 @@
|
|
|
13611
13616
|
"bytesInOutput": 4594
|
|
13612
13617
|
},
|
|
13613
13618
|
"node_modules/@eslint/eslintrc/node_modules/minimatch/minimatch.js": {
|
|
13614
|
-
"bytesInOutput":
|
|
13619
|
+
"bytesInOutput": 18260
|
|
13615
13620
|
},
|
|
13616
13621
|
"node_modules/uri-js/dist/es5/uri.all.js": {
|
|
13617
13622
|
"bytesInOutput": 49104
|
|
@@ -13758,7 +13763,7 @@
|
|
|
13758
13763
|
"bytesInOutput": 157
|
|
13759
13764
|
},
|
|
13760
13765
|
"node_modules/@eslint/eslintrc/dist/eslintrc.cjs": {
|
|
13761
|
-
"bytesInOutput":
|
|
13766
|
+
"bytesInOutput": 103422
|
|
13762
13767
|
},
|
|
13763
13768
|
"node_modules/@eslint/js/src/configs/eslint-all.js": {
|
|
13764
13769
|
"bytesInOutput": 7567
|
|
@@ -13770,7 +13775,7 @@
|
|
|
13770
13775
|
"bytesInOutput": 260
|
|
13771
13776
|
},
|
|
13772
13777
|
"node_modules/eslint/lib/cli-engine/file-enumerator.js": {
|
|
13773
|
-
"bytesInOutput":
|
|
13778
|
+
"bytesInOutput": 12998
|
|
13774
13779
|
},
|
|
13775
13780
|
"node_modules/yocto-queue/index.js": {
|
|
13776
13781
|
"bytesInOutput": 1290
|
|
@@ -13818,7 +13823,7 @@
|
|
|
13818
13823
|
"bytesInOutput": 28051
|
|
13819
13824
|
},
|
|
13820
13825
|
"node_modules/eslint/lib/shared/traverser.js": {
|
|
13821
|
-
"bytesInOutput":
|
|
13826
|
+
"bytesInOutput": 4740
|
|
13822
13827
|
},
|
|
13823
13828
|
"node_modules/eslint/lib/source-code/token-store/cursor.js": {
|
|
13824
13829
|
"bytesInOutput": 1074
|
|
@@ -13899,7 +13904,7 @@
|
|
|
13899
13904
|
"bytesInOutput": 895
|
|
13900
13905
|
},
|
|
13901
13906
|
"node_modules/eslint/lib/linter/config-comment-parser.js": {
|
|
13902
|
-
"bytesInOutput":
|
|
13907
|
+
"bytesInOutput": 4702
|
|
13903
13908
|
},
|
|
13904
13909
|
"node_modules/eslint/lib/source-code/source-code.js": {
|
|
13905
13910
|
"bytesInOutput": 27533
|
|
@@ -13908,10 +13913,10 @@
|
|
|
13908
13913
|
"bytesInOutput": 206
|
|
13909
13914
|
},
|
|
13910
13915
|
"node_modules/eslint/lib/linter/code-path-analysis/debug-helpers.js": {
|
|
13911
|
-
"bytesInOutput":
|
|
13916
|
+
"bytesInOutput": 5637
|
|
13912
13917
|
},
|
|
13913
13918
|
"node_modules/eslint/lib/linter/code-path-analysis/code-path-segment.js": {
|
|
13914
|
-
"bytesInOutput":
|
|
13919
|
+
"bytesInOutput": 5779
|
|
13915
13920
|
},
|
|
13916
13921
|
"node_modules/eslint/lib/linter/code-path-analysis/fork-context.js": {
|
|
13917
13922
|
"bytesInOutput": 7677
|
|
@@ -13926,7 +13931,7 @@
|
|
|
13926
13931
|
"bytesInOutput": 7482
|
|
13927
13932
|
},
|
|
13928
13933
|
"node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js": {
|
|
13929
|
-
"bytesInOutput":
|
|
13934
|
+
"bytesInOutput": 17048
|
|
13930
13935
|
},
|
|
13931
13936
|
"node_modules/eslint/lib/linter/apply-disable-directives.js": {
|
|
13932
13937
|
"bytesInOutput": 10137
|
|
@@ -13947,7 +13952,7 @@
|
|
|
13947
13952
|
"bytesInOutput": 7454
|
|
13948
13953
|
},
|
|
13949
13954
|
"node_modules/eslint/lib/rules/utils/lazy-loading-rule-map.js": {
|
|
13950
|
-
"bytesInOutput":
|
|
13955
|
+
"bytesInOutput": 2555
|
|
13951
13956
|
},
|
|
13952
13957
|
"node_modules/esutils/lib/ast.js": {
|
|
13953
13958
|
"bytesInOutput": 3324
|
|
@@ -14910,7 +14915,7 @@
|
|
|
14910
14915
|
"bytesInOutput": 733
|
|
14911
14916
|
},
|
|
14912
14917
|
"node_modules/eslint/lib/linter/source-code-fixer.js": {
|
|
14913
|
-
"bytesInOutput":
|
|
14918
|
+
"bytesInOutput": 2590
|
|
14914
14919
|
},
|
|
14915
14920
|
"node_modules/eslint/lib/linter/timing.js": {
|
|
14916
14921
|
"bytesInOutput": 2606
|
|
@@ -14925,7 +14930,7 @@
|
|
|
14925
14930
|
"bytesInOutput": 4605
|
|
14926
14931
|
},
|
|
14927
14932
|
"node_modules/@humanwhocodes/config-array/node_modules/minimatch/minimatch.js": {
|
|
14928
|
-
"bytesInOutput":
|
|
14933
|
+
"bytesInOutput": 18271
|
|
14929
14934
|
},
|
|
14930
14935
|
"node_modules/@humanwhocodes/object-schema/src/merge-strategy.js": {
|
|
14931
14936
|
"bytesInOutput": 1449
|
|
@@ -14940,7 +14945,7 @@
|
|
|
14940
14945
|
"bytesInOutput": 326
|
|
14941
14946
|
},
|
|
14942
14947
|
"node_modules/@humanwhocodes/config-array/api.js": {
|
|
14943
|
-
"bytesInOutput":
|
|
14948
|
+
"bytesInOutput": 22297
|
|
14944
14949
|
},
|
|
14945
14950
|
"node_modules/@ungap/structured-clone/cjs/types.js": {
|
|
14946
14951
|
"bytesInOutput": 588
|
|
@@ -14976,7 +14981,7 @@
|
|
|
14976
14981
|
"bytesInOutput": 6248
|
|
14977
14982
|
},
|
|
14978
14983
|
"node_modules/eslint/lib/linter/linter.js": {
|
|
14979
|
-
"bytesInOutput":
|
|
14984
|
+
"bytesInOutput": 57092
|
|
14980
14985
|
},
|
|
14981
14986
|
"node_modules/eslint/lib/linter/index.js": {
|
|
14982
14987
|
"bytesInOutput": 372
|
|
@@ -15096,7 +15101,7 @@
|
|
|
15096
15101
|
"bytesInOutput": 4582
|
|
15097
15102
|
},
|
|
15098
15103
|
"node_modules/glob/node_modules/minimatch/minimatch.js": {
|
|
15099
|
-
"bytesInOutput":
|
|
15104
|
+
"bytesInOutput": 18248
|
|
15100
15105
|
},
|
|
15101
15106
|
"node_modules/inherits/inherits_browser.js": {
|
|
15102
15107
|
"bytesInOutput": 897
|
|
@@ -15141,10 +15146,10 @@
|
|
|
15141
15146
|
"bytesInOutput": 2959
|
|
15142
15147
|
},
|
|
15143
15148
|
"node_modules/eslint/lib/cli-engine/lint-result-cache.js": {
|
|
15144
|
-
"bytesInOutput":
|
|
15149
|
+
"bytesInOutput": 5086
|
|
15145
15150
|
},
|
|
15146
15151
|
"node_modules/eslint/lib/eslint/flat-eslint.js": {
|
|
15147
|
-
"bytesInOutput":
|
|
15152
|
+
"bytesInOutput": 25131
|
|
15148
15153
|
},
|
|
15149
15154
|
"node_modules/eslint/lib/rule-tester/flat-rule-tester.js": {
|
|
15150
15155
|
"bytesInOutput": 31667
|
|
@@ -15156,7 +15161,7 @@
|
|
|
15156
15161
|
"bytesInOutput": 745
|
|
15157
15162
|
},
|
|
15158
15163
|
"node_modules/eslint/lib/cli-engine/cli-engine.js": {
|
|
15159
|
-
"bytesInOutput":
|
|
15164
|
+
"bytesInOutput": 23895
|
|
15160
15165
|
},
|
|
15161
15166
|
"node_modules/eslint/lib/eslint/eslint.js": {
|
|
15162
15167
|
"bytesInOutput": 19446
|
|
@@ -15708,7 +15713,7 @@
|
|
|
15708
15713
|
"bytesInOutput": 745
|
|
15709
15714
|
},
|
|
15710
15715
|
"package.json": {
|
|
15711
|
-
"bytesInOutput":
|
|
15716
|
+
"bytesInOutput": 3015
|
|
15712
15717
|
},
|
|
15713
15718
|
"src/get-documentation-url.ts": {
|
|
15714
15719
|
"bytesInOutput": 148
|
|
@@ -15738,7 +15743,7 @@
|
|
|
15738
15743
|
"bytesInOutput": 12231
|
|
15739
15744
|
},
|
|
15740
15745
|
"src/agent/fix-function-call-arguments.ts": {
|
|
15741
|
-
"bytesInOutput":
|
|
15746
|
+
"bytesInOutput": 5235
|
|
15742
15747
|
},
|
|
15743
15748
|
"src/invalid-json-stringify.ts": {
|
|
15744
15749
|
"bytesInOutput": 2473
|
|
@@ -15816,7 +15821,7 @@
|
|
|
15816
15821
|
"bytesInOutput": 3362
|
|
15817
15822
|
}
|
|
15818
15823
|
},
|
|
15819
|
-
"bytes":
|
|
15824
|
+
"bytes": 4371841
|
|
15820
15825
|
}
|
|
15821
15826
|
}
|
|
15822
15827
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
// src/agent/fix-function-call-arguments.ts
|
|
2
|
-
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
+
import { ESLintUtils, TSESTree } from "@typescript-eslint/utils";
|
|
3
3
|
import { strict as assert } from "node:assert";
|
|
4
|
+
import debug from "debug";
|
|
4
5
|
import getDocumentationUrl from "../get-documentation-url.mjs";
|
|
5
6
|
var ruleId = "fix-function-call-arguments";
|
|
6
7
|
var createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
|
|
8
|
+
var log = debug("eslint-plugin:fix-function-call-arguments");
|
|
7
9
|
var rule = createRule({
|
|
8
10
|
name: ruleId,
|
|
9
11
|
meta: {
|
|
@@ -25,42 +27,73 @@ var rule = createRule({
|
|
|
25
27
|
const sourceCode = context.sourceCode;
|
|
26
28
|
return {
|
|
27
29
|
CallExpression(callExpression) {
|
|
30
|
+
if (callExpression.callee.type === TSESTree.AST_NODE_TYPES.MemberExpression) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
log("===== file name:", context.filename);
|
|
34
|
+
log("callExpression:", sourceCode.getText(callExpression));
|
|
28
35
|
try {
|
|
29
36
|
const calleeTsNode = parserServices.esTreeNodeToTSNodeMap.get(callExpression.callee);
|
|
30
37
|
const calleeType = typeChecker.getTypeAtLocation(calleeTsNode);
|
|
31
|
-
const
|
|
32
|
-
if (
|
|
38
|
+
const signatures = calleeType.getCallSignatures();
|
|
39
|
+
if (
|
|
40
|
+
// ignore complex signatures with overloads
|
|
41
|
+
signatures.length > 1
|
|
42
|
+
) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const signature = signatures[0];
|
|
46
|
+
if (!signature || // ignore complex signatures
|
|
47
|
+
signature.typeParameters !== void 0 && signature.typeParameters.length > 0) {
|
|
33
48
|
return;
|
|
34
49
|
}
|
|
35
50
|
const signatureParameters = signature.getParameters();
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
if (
|
|
51
|
+
const expectedParametersCount = signatureParameters.length;
|
|
52
|
+
const actualParameters = callExpression.arguments;
|
|
53
|
+
const actualParametersCount = actualParameters.length;
|
|
54
|
+
if (actualParametersCount === 0 || actualParametersCount === expectedParametersCount) {
|
|
40
55
|
return;
|
|
41
56
|
}
|
|
42
|
-
const
|
|
43
|
-
if (
|
|
44
|
-
let
|
|
45
|
-
for (const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
typeChecker.
|
|
57
|
+
const parametersToKeep = [];
|
|
58
|
+
if (expectedParametersCount > 0) {
|
|
59
|
+
let expectedParameterIndex = 0;
|
|
60
|
+
for (const [actualParameterIndex, actualParameter] of actualParameters.entries()) {
|
|
61
|
+
if (expectedParameterIndex >= expectedParametersCount) {
|
|
62
|
+
parametersToKeep.push(actualParameter);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const expectedParameter = signatureParameters[expectedParameterIndex];
|
|
66
|
+
assert.ok(expectedParameter, "Expected parameter not found.");
|
|
67
|
+
const expectedType = typeChecker.getTypeOfSymbol(expectedParameter);
|
|
68
|
+
const actualType = typeChecker.getTypeAtLocation(
|
|
69
|
+
parserServices.esTreeNodeToTSNodeMap.get(actualParameter)
|
|
70
|
+
);
|
|
71
|
+
log(
|
|
72
|
+
"expected type: #",
|
|
73
|
+
expectedParameterIndex,
|
|
74
|
+
expectedParameter.escapedName,
|
|
75
|
+
typeChecker.typeToString(expectedType)
|
|
76
|
+
);
|
|
77
|
+
log(
|
|
78
|
+
"actual type: #",
|
|
79
|
+
actualParameterIndex,
|
|
80
|
+
sourceCode.getText(actualParameter),
|
|
81
|
+
typeChecker.typeToString(actualType)
|
|
82
|
+
);
|
|
53
83
|
if (typeChecker.isTypeAssignableTo(actualType, expectedType) === true) {
|
|
54
|
-
|
|
55
|
-
|
|
84
|
+
parametersToKeep.push(actualParameter);
|
|
85
|
+
expectedParameterIndex++;
|
|
86
|
+
log("matched");
|
|
87
|
+
} else {
|
|
88
|
+
log("not matched");
|
|
56
89
|
}
|
|
57
90
|
}
|
|
58
91
|
}
|
|
59
|
-
if (
|
|
92
|
+
if (parametersToKeep.length === actualParametersCount) {
|
|
60
93
|
return;
|
|
61
94
|
}
|
|
62
|
-
const firstParameter =
|
|
63
|
-
const lastParameter =
|
|
95
|
+
const firstParameter = actualParameters[0];
|
|
96
|
+
const lastParameter = actualParameters.at(-1);
|
|
64
97
|
assert.ok(firstParameter !== void 0 && lastParameter !== void 0);
|
|
65
98
|
const tokenAfterParameters = sourceCode.getTokenAfter(lastParameter);
|
|
66
99
|
context.report({
|
|
@@ -72,7 +105,7 @@ var rule = createRule({
|
|
|
72
105
|
firstParameter.range[0],
|
|
73
106
|
tokenAfterParameters?.value === "," ? tokenAfterParameters.range[1] : lastParameter.range[1]
|
|
74
107
|
],
|
|
75
|
-
|
|
108
|
+
parametersToKeep.map((arg) => sourceCode.getText(arg)).join(", ")
|
|
76
109
|
);
|
|
77
110
|
}
|
|
78
111
|
});
|
|
@@ -96,4 +129,4 @@ export {
|
|
|
96
129
|
fix_function_call_arguments_default as default,
|
|
97
130
|
ruleId
|
|
98
131
|
};
|
|
99
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
132
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vLi4vc3JjL2FnZW50L2ZpeC1mdW5jdGlvbi1jYWxsLWFyZ3VtZW50cy50cyJdLAogICJtYXBwaW5ncyI6ICI7QUFRQSxTQUFTLGFBQWEsZ0JBQWdCO0FBQ3RDLFNBQVMsVUFBVSxjQUFjO0FBQ2pDLE9BQU8sV0FBVztBQUNsQixPQUFPLHlCQUF5QjtBQUV6QixJQUFNLFNBQVM7QUFFdEIsSUFBTSxhQUFhLFlBQVksWUFBWSxDQUFDLFNBQVMsb0JBQW9CLElBQUksQ0FBQztBQUM5RSxJQUFNLE1BQU0sTUFBTSwyQ0FBMkM7QUFFN0QsSUFBTSxPQUFPLFdBQVc7QUFBQSxFQUN0QixNQUFNO0FBQUEsRUFDTixNQUFNO0FBQUEsSUFDSixNQUFNO0FBQUEsSUFDTixNQUFNO0FBQUEsTUFDSixhQUFhO0FBQUEsSUFDZjtBQUFBLElBQ0EsVUFBVTtBQUFBLE1BQ1IscUNBQXFDO0FBQUEsTUFDckMsY0FB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{"name":"@checkdigit/eslint-plugin","version":"6.6.0-PR.75-7c7f","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","debug":"^4.3.7","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/debug":"^4.1.12","@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"}}
|
|
@@ -8,11 +8,13 @@
|
|
|
8
8
|
|
|
9
9
|
import { ESLintUtils, TSESTree } from '@typescript-eslint/utils';
|
|
10
10
|
import { strict as assert } from 'node:assert';
|
|
11
|
+
import debug from 'debug';
|
|
11
12
|
import getDocumentationUrl from '../get-documentation-url';
|
|
12
13
|
|
|
13
14
|
export const ruleId = 'fix-function-call-arguments';
|
|
14
15
|
|
|
15
16
|
const createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
|
|
17
|
+
const log = debug('eslint-plugin:fix-function-call-arguments');
|
|
16
18
|
|
|
17
19
|
const rule = createRule({
|
|
18
20
|
name: ruleId,
|
|
@@ -36,50 +38,92 @@ const rule = createRule({
|
|
|
36
38
|
|
|
37
39
|
return {
|
|
38
40
|
CallExpression(callExpression) {
|
|
41
|
+
// ignore calls like `foo.bar()` which are likely to be 3rd party module calls
|
|
42
|
+
// we only focus on calls against local functions or functions imported from the same module
|
|
43
|
+
if (callExpression.callee.type === TSESTree.AST_NODE_TYPES.MemberExpression) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
log('===== file name:', context.filename);
|
|
48
|
+
log('callExpression:', sourceCode.getText(callExpression));
|
|
39
49
|
try {
|
|
40
50
|
const calleeTsNode = parserServices.esTreeNodeToTSNodeMap.get(callExpression.callee);
|
|
41
51
|
const calleeType = typeChecker.getTypeAtLocation(calleeTsNode);
|
|
42
|
-
|
|
43
|
-
|
|
52
|
+
|
|
53
|
+
const signatures = calleeType.getCallSignatures();
|
|
54
|
+
if (
|
|
55
|
+
// ignore complex signatures with overloads
|
|
56
|
+
signatures.length > 1
|
|
57
|
+
) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const signature = signatures[0];
|
|
62
|
+
if (
|
|
63
|
+
!signature ||
|
|
64
|
+
// ignore complex signatures
|
|
65
|
+
(signature.typeParameters !== undefined && signature.typeParameters.length > 0)
|
|
66
|
+
) {
|
|
44
67
|
return;
|
|
45
68
|
}
|
|
46
69
|
|
|
47
70
|
const signatureParameters = signature.getParameters();
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
if (
|
|
71
|
+
const expectedParametersCount = signatureParameters.length;
|
|
72
|
+
const actualParameters = callExpression.arguments;
|
|
73
|
+
const actualParametersCount = actualParameters.length;
|
|
74
|
+
if (actualParametersCount === 0 || actualParametersCount === expectedParametersCount) {
|
|
52
75
|
return;
|
|
53
76
|
}
|
|
54
|
-
const
|
|
77
|
+
const parametersToKeep: TSESTree.CallExpressionArgument[] = [];
|
|
55
78
|
|
|
56
|
-
if (
|
|
57
|
-
let
|
|
58
|
-
for (const
|
|
59
|
-
|
|
60
|
-
|
|
79
|
+
if (expectedParametersCount > 0) {
|
|
80
|
+
let expectedParameterIndex = 0;
|
|
81
|
+
for (const [actualParameterIndex, actualParameter] of actualParameters.entries()) {
|
|
82
|
+
if (expectedParameterIndex >= expectedParametersCount) {
|
|
83
|
+
parametersToKeep.push(actualParameter);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const expectedParameter = signatureParameters[expectedParameterIndex];
|
|
88
|
+
assert.ok(expectedParameter, 'Expected parameter not found.');
|
|
89
|
+
|
|
90
|
+
const expectedType = typeChecker.getTypeOfSymbol(expectedParameter);
|
|
91
|
+
const actualType = typeChecker.getTypeAtLocation(
|
|
92
|
+
parserServices.esTreeNodeToTSNodeMap.get(actualParameter),
|
|
93
|
+
);
|
|
61
94
|
|
|
62
|
-
const expectedType = typeChecker.getTypeOfSymbol(currentExpectedArg);
|
|
63
95
|
// eslint-disable-next-line no-console
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
96
|
+
log(
|
|
97
|
+
'expected type: #',
|
|
98
|
+
expectedParameterIndex,
|
|
99
|
+
expectedParameter.escapedName,
|
|
100
|
+
typeChecker.typeToString(expectedType),
|
|
101
|
+
);
|
|
102
|
+
// eslint-disable-next-line no-console
|
|
103
|
+
log(
|
|
104
|
+
'actual type: #',
|
|
105
|
+
actualParameterIndex,
|
|
106
|
+
sourceCode.getText(actualParameter),
|
|
107
|
+
typeChecker.typeToString(actualType),
|
|
108
|
+
);
|
|
68
109
|
// @ts-expect-error: internal API
|
|
69
110
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
70
111
|
if (typeChecker.isTypeAssignableTo(actualType, expectedType) === true) {
|
|
71
|
-
|
|
72
|
-
|
|
112
|
+
parametersToKeep.push(actualParameter);
|
|
113
|
+
expectedParameterIndex++;
|
|
114
|
+
log('matched');
|
|
115
|
+
} else {
|
|
116
|
+
log('not matched');
|
|
73
117
|
}
|
|
74
118
|
}
|
|
75
119
|
}
|
|
76
120
|
|
|
77
|
-
if (
|
|
121
|
+
if (parametersToKeep.length === actualParametersCount) {
|
|
78
122
|
return;
|
|
79
123
|
}
|
|
80
124
|
|
|
81
|
-
const firstParameter =
|
|
82
|
-
const lastParameter =
|
|
125
|
+
const firstParameter = actualParameters[0];
|
|
126
|
+
const lastParameter = actualParameters.at(-1);
|
|
83
127
|
assert.ok(firstParameter !== undefined && lastParameter !== undefined);
|
|
84
128
|
const tokenAfterParameters = sourceCode.getTokenAfter(lastParameter);
|
|
85
129
|
|
|
@@ -92,7 +136,7 @@ const rule = createRule({
|
|
|
92
136
|
firstParameter.range[0],
|
|
93
137
|
tokenAfterParameters?.value === ',' ? tokenAfterParameters.range[1] : lastParameter.range[1],
|
|
94
138
|
],
|
|
95
|
-
|
|
139
|
+
parametersToKeep.map((arg) => sourceCode.getText(arg)).join(', '),
|
|
96
140
|
);
|
|
97
141
|
},
|
|
98
142
|
});
|