@checkdigit/eslint-plugin 6.6.0-PR.75-2a52 → 6.6.0-PR.75-9c39

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.
@@ -12549,7 +12549,7 @@
12549
12549
  "format": "esm"
12550
12550
  },
12551
12551
  "src/agent/no-unused-function-argument.ts": {
12552
- "bytes": 2862,
12552
+ "bytes": 3290,
12553
12553
  "imports": [
12554
12554
  {
12555
12555
  "path": "node_modules/@typescript-eslint/utils/dist/index.js",
@@ -15680,7 +15680,7 @@
15680
15680
  "bytesInOutput": 2042
15681
15681
  },
15682
15682
  "src/agent/no-unused-function-argument.ts": {
15683
- "bytesInOutput": 2475
15683
+ "bytesInOutput": 2865
15684
15684
  },
15685
15685
  "src/require-fixed-services-import.ts": {
15686
15686
  "bytesInOutput": 1262
@@ -15719,7 +15719,7 @@
15719
15719
  "bytesInOutput": 3362
15720
15720
  }
15721
15721
  },
15722
- "bytes": 4349859
15722
+ "bytes": 4350469
15723
15723
  }
15724
15724
  }
15725
15725
  }
@@ -21,12 +21,8 @@ var rule = createRule({
21
21
  defaultOptions: [],
22
22
  create(context) {
23
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);
24
+ function isParameterUsed(parameter, scope) {
25
+ return scope.references.some((ref) => ref.identifier.name === parameter.name) || scope.childScopes.some((childScope) => isParameterUsed(parameter, childScope));
30
26
  }
31
27
  return {
32
28
  FunctionDeclaration(functionDeclaration) {
@@ -35,8 +31,13 @@ var rule = createRule({
35
31
  if (parameters.length === 0) {
36
32
  return;
37
33
  }
38
- const body = functionDeclaration.body;
39
- const parametersToKeep = parameters.filter((parameter) => isParameterUsed(parameter, body));
34
+ const functionScope = sourceCode.getScope(functionDeclaration);
35
+ const parametersToKeep = parameters.filter(
36
+ (parameter) => parameter.type !== TSESTree.AST_NODE_TYPES.Identifier || isParameterUsed(parameter, functionScope)
37
+ );
38
+ if (parametersToKeep.length === parameters.length) {
39
+ return;
40
+ }
40
41
  const updatedParameters = parametersToKeep.map((parameter) => sourceCode.getText(parameter)).join(", ");
41
42
  context.report({
42
43
  node: functionDeclaration,
@@ -45,7 +46,14 @@ var rule = createRule({
45
46
  const firstParameter = parameters[0];
46
47
  const lastParameter = parameters.at(-1);
47
48
  assert.ok(firstParameter !== void 0 && lastParameter !== void 0);
48
- return fixer.replaceTextRange([firstParameter.range[0], lastParameter.range[1]], updatedParameters);
49
+ const tokenAfterParameters = sourceCode.getTokenAfter(lastParameter);
50
+ return fixer.replaceTextRange(
51
+ [
52
+ firstParameter.range[0],
53
+ tokenAfterParameters?.value === "," ? tokenAfterParameters.range[1] : lastParameter.range[1]
54
+ ],
55
+ updatedParameters
56
+ );
49
57
  }
50
58
  });
51
59
  } catch (error) {
@@ -68,4 +76,4 @@ export {
68
76
  no_unused_function_argument_default as default,
69
77
  ruleId
70
78
  };
71
- //# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vLi4vc3JjL2FnZW50L25vLXVudXNlZC1mdW5jdGlvbi1hcmd1bWVudC50cyJdLAogICJtYXBwaW5ncyI6ICI7QUFRQSxTQUFTLGFBQWEsZ0JBQWdCO0FBQ3RDLFNBQVMsVUFBVSxjQUFjO0FBQ2pDLE9BQU8seUJBQXlCO0FBRXpCLElBQU0sU0FBUztBQUV0QixJQUFNLGFBQWEsWUFBWSxZQUFZLENBQUMsU0FBUyxvQkFBb0IsSUFBSSxDQUFDO0FBRTlFLElBQU0sT0FBTyxXQUFXO0FBQUEsRUFDdEIsTUFBTTtBQUFBLEVBQ04sTUFBTTtBQUFBLElBQ0osTUFBTTtBQUFBLElBQ04sTUFBTTtBQUFBLE1BQ0osYUFBYTtBQUFBLElBQ2Y7QUFBQSxJQ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UFNLGlCQUFpQixXQUFXLENBQUM7QUFDbkMsb0JBQU0sZ0JBQWdCLFdBQVcsR0FBRyxFQUFFO0FBQ3RDLHFCQUFPLEdBQUcsbUJBQW1CLFVBQWEsa0JBQWtCLE1BQVM7QUFDckUsb0JBQU0sdUJBQXVCLFdBQVcsY0FBYyxhQUFhO0FBRW5FLHFCQUFPLE1BQU07QUFBQSxnQkFDWDtBQUFBLGtCQUNFLGVBQWUsTUFBTSxDQUFDO0FBQUEsa0JBQ3RCLHNCQUFzQixVQUFVLE1BQU0scUJBQXFCLE1BQU0sQ0FBQyxJQUFJLGNBQWMsTUFBTSxDQUFDO0FBQUEsZ0JBQzdGO0FBQUEsZ0JBQ0E7QUFBQSxjQUNGO0FBQUEsWUFDRjtBQUFBLFVBQ0YsQ0FBQztBQUFBLFFBQ0gsU0FBUyxPQUFPO0FBRWQsa0JBQVEsTUFBTSxtQkFBbUIsTUFBTSxtQkFBbUIsUUFBUSxRQUFRLE1BQU0sS0FBSztBQUNyRixrQkFBUSxPQUFPO0FBQUEsWUFDYixNQUFNO0FBQUEsWUFDTixXQUFXO0FBQUEsWUFDWCxNQUFNO0FBQUEsY0FDSixVQUFVLFFBQVE7QUFBQSxjQUNsQixPQUFPLGlCQUFpQixRQUFRLE1BQU0sU0FBUyxJQUFJLEtBQUssVUFBVSxLQUFLO0FBQUEsWUFDekU7QUFBQSxVQUNGLENBQUM7QUFBQSxRQUNIO0FBQUEsTUFDRjtBQUFBLElBQ0Y7QUFBQSxFQUNGO0FBQ0YsQ0FBQztBQUVELElBQU8sc0NBQVE7IiwKICAibmFtZXMiOiBbXQp9Cg==
package/package.json CHANGED
@@ -1 +1 @@
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"}}
1
+ {"name":"@checkdigit/eslint-plugin","version":"6.6.0-PR.75-9c39","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"}}
@@ -7,6 +7,7 @@
7
7
  */
8
8
 
9
9
  import { ESLintUtils, TSESTree } from '@typescript-eslint/utils';
10
+ import type { Scope } from '@typescript-eslint/utils/ts-eslint';
10
11
  import { strict as assert } from 'node:assert';
11
12
  import getDocumentationUrl from '../get-documentation-url';
12
13
 
@@ -32,13 +33,11 @@ const rule = createRule({
32
33
  create(context) {
33
34
  const sourceCode = context.sourceCode;
34
35
 
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);
36
+ function isParameterUsed(parameter: TSESTree.Identifier, scope: Scope.Scope): boolean {
37
+ return (
38
+ scope.references.some((ref) => ref.identifier.name === parameter.name) ||
39
+ scope.childScopes.some((childScope) => isParameterUsed(parameter, childScope))
40
+ );
42
41
  }
43
42
 
44
43
  return {
@@ -49,8 +48,14 @@ const rule = createRule({
49
48
  return;
50
49
  }
51
50
 
52
- const body = functionDeclaration.body;
53
- const parametersToKeep = parameters.filter((parameter) => isParameterUsed(parameter, body));
51
+ const functionScope = sourceCode.getScope(functionDeclaration);
52
+ const parametersToKeep = parameters.filter(
53
+ (parameter) =>
54
+ parameter.type !== TSESTree.AST_NODE_TYPES.Identifier || isParameterUsed(parameter, functionScope),
55
+ );
56
+ if (parametersToKeep.length === parameters.length) {
57
+ return;
58
+ }
54
59
 
55
60
  const updatedParameters = parametersToKeep.map((parameter) => sourceCode.getText(parameter)).join(', ');
56
61
  context.report({
@@ -60,7 +65,15 @@ const rule = createRule({
60
65
  const firstParameter = parameters[0];
61
66
  const lastParameter = parameters.at(-1);
62
67
  assert.ok(firstParameter !== undefined && lastParameter !== undefined);
63
- return fixer.replaceTextRange([firstParameter.range[0], lastParameter.range[1]], updatedParameters);
68
+ const tokenAfterParameters = sourceCode.getTokenAfter(lastParameter);
69
+
70
+ return fixer.replaceTextRange(
71
+ [
72
+ firstParameter.range[0],
73
+ tokenAfterParameters?.value === ',' ? tokenAfterParameters.range[1] : lastParameter.range[1],
74
+ ],
75
+ updatedParameters,
76
+ );
64
77
  },
65
78
  });
66
79
  } catch (error) {