@checkdigit/eslint-plugin 6.6.0-PR.75-e357 → 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
|
@@ -12323,19 +12323,8 @@
|
|
|
12323
12323
|
],
|
|
12324
12324
|
"format": "esm"
|
|
12325
12325
|
},
|
|
12326
|
-
"src/library/ts-tree.ts": {
|
|
12327
|
-
"bytes": 2883,
|
|
12328
|
-
"imports": [
|
|
12329
|
-
{
|
|
12330
|
-
"path": "node_modules/@typescript-eslint/utils/dist/index.js",
|
|
12331
|
-
"kind": "import-statement",
|
|
12332
|
-
"original": "@typescript-eslint/utils"
|
|
12333
|
-
}
|
|
12334
|
-
],
|
|
12335
|
-
"format": "esm"
|
|
12336
|
-
},
|
|
12337
12326
|
"src/agent/fix-function-call-arguments.ts": {
|
|
12338
|
-
"bytes":
|
|
12327
|
+
"bytes": 5924,
|
|
12339
12328
|
"imports": [
|
|
12340
12329
|
{
|
|
12341
12330
|
"path": "node_modules/@typescript-eslint/utils/dist/index.js",
|
|
@@ -12356,11 +12345,6 @@
|
|
|
12356
12345
|
"path": "src/get-documentation-url.ts",
|
|
12357
12346
|
"kind": "import-statement",
|
|
12358
12347
|
"original": "../get-documentation-url"
|
|
12359
|
-
},
|
|
12360
|
-
{
|
|
12361
|
-
"path": "src/library/ts-tree.ts",
|
|
12362
|
-
"kind": "import-statement",
|
|
12363
|
-
"original": "../library/ts-tree"
|
|
12364
12348
|
}
|
|
12365
12349
|
],
|
|
12366
12350
|
"format": "esm"
|
|
@@ -12469,6 +12453,17 @@
|
|
|
12469
12453
|
],
|
|
12470
12454
|
"format": "esm"
|
|
12471
12455
|
},
|
|
12456
|
+
"src/library/ts-tree.ts": {
|
|
12457
|
+
"bytes": 2883,
|
|
12458
|
+
"imports": [
|
|
12459
|
+
{
|
|
12460
|
+
"path": "node_modules/@typescript-eslint/utils/dist/index.js",
|
|
12461
|
+
"kind": "import-statement",
|
|
12462
|
+
"original": "@typescript-eslint/utils"
|
|
12463
|
+
}
|
|
12464
|
+
],
|
|
12465
|
+
"format": "esm"
|
|
12466
|
+
},
|
|
12472
12467
|
"src/agent/no-full-response.ts": {
|
|
12473
12468
|
"bytes": 2331,
|
|
12474
12469
|
"imports": [
|
|
@@ -15747,11 +15742,8 @@
|
|
|
15747
15742
|
"src/agent/fetch-then.ts": {
|
|
15748
15743
|
"bytesInOutput": 12231
|
|
15749
15744
|
},
|
|
15750
|
-
"src/library/ts-tree.ts": {
|
|
15751
|
-
"bytesInOutput": 2095
|
|
15752
|
-
},
|
|
15753
15745
|
"src/agent/fix-function-call-arguments.ts": {
|
|
15754
|
-
"bytesInOutput":
|
|
15746
|
+
"bytesInOutput": 5235
|
|
15755
15747
|
},
|
|
15756
15748
|
"src/invalid-json-stringify.ts": {
|
|
15757
15749
|
"bytesInOutput": 2473
|
|
@@ -15765,6 +15757,9 @@
|
|
|
15765
15757
|
"src/agent/no-fixture.ts": {
|
|
15766
15758
|
"bytesInOutput": 16455
|
|
15767
15759
|
},
|
|
15760
|
+
"src/library/ts-tree.ts": {
|
|
15761
|
+
"bytesInOutput": 2095
|
|
15762
|
+
},
|
|
15768
15763
|
"src/agent/no-full-response.ts": {
|
|
15769
15764
|
"bytesInOutput": 2006
|
|
15770
15765
|
},
|
|
@@ -15826,7 +15821,7 @@
|
|
|
15826
15821
|
"bytesInOutput": 3362
|
|
15827
15822
|
}
|
|
15828
15823
|
},
|
|
15829
|
-
"bytes":
|
|
15824
|
+
"bytes": 4371841
|
|
15830
15825
|
}
|
|
15831
15826
|
}
|
|
15832
15827
|
}
|
|
@@ -3,7 +3,6 @@ import { ESLintUtils, TSESTree } from "@typescript-eslint/utils";
|
|
|
3
3
|
import { strict as assert } from "node:assert";
|
|
4
4
|
import debug from "debug";
|
|
5
5
|
import getDocumentationUrl from "../get-documentation-url.mjs";
|
|
6
|
-
import { getParent } from "../library/ts-tree.mjs";
|
|
7
6
|
var ruleId = "fix-function-call-arguments";
|
|
8
7
|
var createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
|
|
9
8
|
var log = debug("eslint-plugin:fix-function-call-arguments");
|
|
@@ -28,50 +27,73 @@ var rule = createRule({
|
|
|
28
27
|
const sourceCode = context.sourceCode;
|
|
29
28
|
return {
|
|
30
29
|
CallExpression(callExpression) {
|
|
31
|
-
if (
|
|
30
|
+
if (callExpression.callee.type === TSESTree.AST_NODE_TYPES.MemberExpression) {
|
|
32
31
|
return;
|
|
33
32
|
}
|
|
34
|
-
log("
|
|
33
|
+
log("===== file name:", context.filename);
|
|
35
34
|
log("callExpression:", sourceCode.getText(callExpression));
|
|
36
35
|
try {
|
|
37
36
|
const calleeTsNode = parserServices.esTreeNodeToTSNodeMap.get(callExpression.callee);
|
|
38
37
|
const calleeType = typeChecker.getTypeAtLocation(calleeTsNode);
|
|
39
|
-
const
|
|
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];
|
|
40
46
|
if (!signature || // ignore complex signatures
|
|
41
47
|
signature.typeParameters !== void 0 && signature.typeParameters.length > 0) {
|
|
42
48
|
return;
|
|
43
49
|
}
|
|
44
50
|
const signatureParameters = signature.getParameters();
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
if (
|
|
51
|
+
const expectedParametersCount = signatureParameters.length;
|
|
52
|
+
const actualParameters = callExpression.arguments;
|
|
53
|
+
const actualParametersCount = actualParameters.length;
|
|
54
|
+
if (actualParametersCount === 0 || actualParametersCount === expectedParametersCount) {
|
|
49
55
|
return;
|
|
50
56
|
}
|
|
51
|
-
const
|
|
52
|
-
if (
|
|
53
|
-
let
|
|
54
|
-
for (const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
+
);
|
|
61
83
|
if (typeChecker.isTypeAssignableTo(actualType, expectedType) === true) {
|
|
62
|
-
|
|
63
|
-
|
|
84
|
+
parametersToKeep.push(actualParameter);
|
|
85
|
+
expectedParameterIndex++;
|
|
64
86
|
log("matched");
|
|
65
87
|
} else {
|
|
66
88
|
log("not matched");
|
|
67
89
|
}
|
|
68
90
|
}
|
|
69
91
|
}
|
|
70
|
-
if (
|
|
92
|
+
if (parametersToKeep.length === actualParametersCount) {
|
|
71
93
|
return;
|
|
72
94
|
}
|
|
73
|
-
const firstParameter =
|
|
74
|
-
const lastParameter =
|
|
95
|
+
const firstParameter = actualParameters[0];
|
|
96
|
+
const lastParameter = actualParameters.at(-1);
|
|
75
97
|
assert.ok(firstParameter !== void 0 && lastParameter !== void 0);
|
|
76
98
|
const tokenAfterParameters = sourceCode.getTokenAfter(lastParameter);
|
|
77
99
|
context.report({
|
|
@@ -83,7 +105,7 @@ var rule = createRule({
|
|
|
83
105
|
firstParameter.range[0],
|
|
84
106
|
tokenAfterParameters?.value === "," ? tokenAfterParameters.range[1] : lastParameter.range[1]
|
|
85
107
|
],
|
|
86
|
-
|
|
108
|
+
parametersToKeep.map((arg) => sourceCode.getText(arg)).join(", ")
|
|
87
109
|
);
|
|
88
110
|
}
|
|
89
111
|
});
|
|
@@ -107,4 +129,4 @@ export {
|
|
|
107
129
|
fix_function_call_arguments_default as default,
|
|
108
130
|
ruleId
|
|
109
131
|
};
|
|
110
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
132
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vLi4vc3JjL2FnZW50L2ZpeC1mdW5jdGlvbi1jYWxsLWFyZ3VtZW50cy50cyJdLAogICJtYXBwaW5ncyI6ICI7QUFRQSxTQUFTLGFBQWEsZ0JBQWdCO0FBQ3RDLFNBQVMsVUFBVSxjQUFjO0FBQ2pDLE9BQU8sV0FBVztBQUNsQixPQUFPLHlCQUF5QjtBQUV6QixJQUFNLFNBQVM7QUFFdEIsSUFBTSxhQUFhLFlBQVksWUFBWSxDQUFDLFNBQVMsb0JBQW9CLElBQUksQ0FBQztBQUM5RSxJQUFNLE1BQU0sTUFBTSwyQ0FBMkM7QUFFN0QsSUFBTSxPQUFPLFdBQVc7QUFBQSxFQUN0QixNQUFNO0FBQUEsRUFDTixNQUFNO0FBQUEsSUFDSixNQUFNO0FBQUEsSUFDTixNQUFNO0FBQUEsTUFDSixhQUFhO0FBQUEsSUFDZjtBQUFBLElBQ0EsVUFBVTtBQUFBLE1BQ1IscUNBQXFDO0FBQUEsTUFDckMsY0FBYztBQUFBLElBQ2hCO0FBQUEsSUFDQSxTQUFTO0FBQU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"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"}}
|
|
@@ -10,7 +10,6 @@ import { ESLintUtils, TSESTree } from '@typescript-eslint/utils';
|
|
|
10
10
|
import { strict as assert } from 'node:assert';
|
|
11
11
|
import debug from 'debug';
|
|
12
12
|
import getDocumentationUrl from '../get-documentation-url';
|
|
13
|
-
import { getParent } from '../library/ts-tree';
|
|
14
13
|
|
|
15
14
|
export const ruleId = 'fix-function-call-arguments';
|
|
16
15
|
|
|
@@ -41,16 +40,25 @@ const rule = createRule({
|
|
|
41
40
|
CallExpression(callExpression) {
|
|
42
41
|
// ignore calls like `foo.bar()` which are likely to be 3rd party module calls
|
|
43
42
|
// we only focus on calls against local functions or functions imported from the same module
|
|
44
|
-
if (
|
|
43
|
+
if (callExpression.callee.type === TSESTree.AST_NODE_TYPES.MemberExpression) {
|
|
45
44
|
return;
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
log('
|
|
47
|
+
log('===== file name:', context.filename);
|
|
49
48
|
log('callExpression:', sourceCode.getText(callExpression));
|
|
50
49
|
try {
|
|
51
50
|
const calleeTsNode = parserServices.esTreeNodeToTSNodeMap.get(callExpression.callee);
|
|
52
51
|
const calleeType = typeChecker.getTypeAtLocation(calleeTsNode);
|
|
53
|
-
|
|
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];
|
|
54
62
|
if (
|
|
55
63
|
!signature ||
|
|
56
64
|
// ignore complex signatures
|
|
@@ -60,32 +68,49 @@ const rule = createRule({
|
|
|
60
68
|
}
|
|
61
69
|
|
|
62
70
|
const signatureParameters = signature.getParameters();
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
if (
|
|
71
|
+
const expectedParametersCount = signatureParameters.length;
|
|
72
|
+
const actualParameters = callExpression.arguments;
|
|
73
|
+
const actualParametersCount = actualParameters.length;
|
|
74
|
+
if (actualParametersCount === 0 || actualParametersCount === expectedParametersCount) {
|
|
67
75
|
return;
|
|
68
76
|
}
|
|
69
|
-
const
|
|
77
|
+
const parametersToKeep: TSESTree.CallExpressionArgument[] = [];
|
|
70
78
|
|
|
71
|
-
if (
|
|
72
|
-
let
|
|
73
|
-
for (const
|
|
74
|
-
|
|
75
|
-
|
|
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.');
|
|
76
89
|
|
|
77
|
-
const expectedType = typeChecker.getTypeOfSymbol(
|
|
78
|
-
const actualType = typeChecker.getTypeAtLocation(
|
|
90
|
+
const expectedType = typeChecker.getTypeOfSymbol(expectedParameter);
|
|
91
|
+
const actualType = typeChecker.getTypeAtLocation(
|
|
92
|
+
parserServices.esTreeNodeToTSNodeMap.get(actualParameter),
|
|
93
|
+
);
|
|
79
94
|
|
|
80
95
|
// eslint-disable-next-line no-console
|
|
81
|
-
log(
|
|
96
|
+
log(
|
|
97
|
+
'expected type: #',
|
|
98
|
+
expectedParameterIndex,
|
|
99
|
+
expectedParameter.escapedName,
|
|
100
|
+
typeChecker.typeToString(expectedType),
|
|
101
|
+
);
|
|
82
102
|
// eslint-disable-next-line no-console
|
|
83
|
-
log(
|
|
103
|
+
log(
|
|
104
|
+
'actual type: #',
|
|
105
|
+
actualParameterIndex,
|
|
106
|
+
sourceCode.getText(actualParameter),
|
|
107
|
+
typeChecker.typeToString(actualType),
|
|
108
|
+
);
|
|
84
109
|
// @ts-expect-error: internal API
|
|
85
110
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
86
111
|
if (typeChecker.isTypeAssignableTo(actualType, expectedType) === true) {
|
|
87
|
-
|
|
88
|
-
|
|
112
|
+
parametersToKeep.push(actualParameter);
|
|
113
|
+
expectedParameterIndex++;
|
|
89
114
|
log('matched');
|
|
90
115
|
} else {
|
|
91
116
|
log('not matched');
|
|
@@ -93,12 +118,12 @@ const rule = createRule({
|
|
|
93
118
|
}
|
|
94
119
|
}
|
|
95
120
|
|
|
96
|
-
if (
|
|
121
|
+
if (parametersToKeep.length === actualParametersCount) {
|
|
97
122
|
return;
|
|
98
123
|
}
|
|
99
124
|
|
|
100
|
-
const firstParameter =
|
|
101
|
-
const lastParameter =
|
|
125
|
+
const firstParameter = actualParameters[0];
|
|
126
|
+
const lastParameter = actualParameters.at(-1);
|
|
102
127
|
assert.ok(firstParameter !== undefined && lastParameter !== undefined);
|
|
103
128
|
const tokenAfterParameters = sourceCode.getTokenAfter(lastParameter);
|
|
104
129
|
|
|
@@ -111,7 +136,7 @@ const rule = createRule({
|
|
|
111
136
|
firstParameter.range[0],
|
|
112
137
|
tokenAfterParameters?.value === ',' ? tokenAfterParameters.range[1] : lastParameter.range[1],
|
|
113
138
|
],
|
|
114
|
-
|
|
139
|
+
parametersToKeep.map((arg) => sourceCode.getText(arg)).join(', '),
|
|
115
140
|
);
|
|
116
141
|
},
|
|
117
142
|
});
|