@checkdigit/eslint-plugin 7.5.1-PR.101-bf22 → 7.5.1-PR.101-6eb0

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.
@@ -15,10 +15,24 @@ function isCallExpressionCalleeMemberExpression(statement, excludedIdentifiers)
15
15
  function isVariableDeclarationAwaitExpression(node) {
16
16
  return node.type === TSESTree.AST_NODE_TYPES.VariableDeclaration && node.declarations.length > 0 && node.declarations[0]?.init?.type === TSESTree.AST_NODE_TYPES.AwaitExpression;
17
17
  }
18
+ function isIdentifierCallee(node, excludedIdentifiers) {
19
+ return node.callee.type === TSESTree.AST_NODE_TYPES.Identifier && !excludedIdentifiers.includes(node.callee.name);
20
+ }
21
+ function isMemberExpressionCallee(node, excludedIdentifiers) {
22
+ return node.callee.type === TSESTree.AST_NODE_TYPES.MemberExpression && node.callee.object.type === TSESTree.AST_NODE_TYPES.Identifier && node.callee.property.type === TSESTree.AST_NODE_TYPES.Identifier && !excludedIdentifiers.includes(`${node.callee.object.name}.${node.callee.property.name}`);
23
+ }
24
+ function isNonIdentifierObjectMemberExpressionCallee(node) {
25
+ return node.callee.type === TSESTree.AST_NODE_TYPES.MemberExpression && node.callee.object.type !== TSESTree.AST_NODE_TYPES.Identifier;
26
+ }
18
27
  function isVariableDeclarationCallExpression(node, excludedIdentifiers) {
19
- return node.type === TSESTree.AST_NODE_TYPES.VariableDeclaration && node.declarations.length > 0 && node.declarations[0]?.init?.type === TSESTree.AST_NODE_TYPES.CallExpression && (node.declarations[0].init.callee.type === TSESTree.AST_NODE_TYPES.Identifier && !excludedIdentifiers.includes(node.declarations[0].init.callee.name) || node.declarations[0].init.callee.type === TSESTree.AST_NODE_TYPES.MemberExpression && node.declarations[0].init.callee.object.type !== TSESTree.AST_NODE_TYPES.Identifier || node.declarations[0].init.callee.type === TSESTree.AST_NODE_TYPES.MemberExpression && node.declarations[0].init.callee.object.type === TSESTree.AST_NODE_TYPES.Identifier && node.declarations[0].init.callee.property.type === TSESTree.AST_NODE_TYPES.Identifier && !excludedIdentifiers.includes(
20
- `${node.declarations[0].init.callee.object.name}.${node.declarations[0].init.callee.property.name}`
21
- ));
28
+ if (node.type !== TSESTree.AST_NODE_TYPES.VariableDeclaration || node.declarations.length === 0) {
29
+ return false;
30
+ }
31
+ const init = node.declarations[0]?.init;
32
+ if (init?.type !== TSESTree.AST_NODE_TYPES.CallExpression) {
33
+ return false;
34
+ }
35
+ return isIdentifierCallee(init, excludedIdentifiers) || isMemberExpressionCallee(init, excludedIdentifiers) || isNonIdentifierObjectMemberExpressionCallee(init);
22
36
  }
23
37
  var createRule = ESLintUtils.RuleCreator((name) => name);
24
38
  var rule = createRule({
@@ -67,4 +81,4 @@ export {
67
81
  no_side_effects_default as default,
68
82
  ruleId
69
83
  };
70
- //# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL25vLXNpZGUtZWZmZWN0cy50cyJdLAogICJtYXBwaW5ncyI6ICI7QUFRQSxTQUFTLG1CQUFtQjtBQUM1QixTQUFTLGdCQUFnQjtBQU1sQixJQUFNLFNBQVM7QUFDdEIsSUFBTSxrQkFBa0I7QUFHeEIsU0FBUyxzQkFBc0IsTUFBMkQ7QUFDeEYsU0FBTyxLQUFLLFNBQVMsU0FBUyxlQUFlO0FBQy9DO0FBR0EsU0FBUyxrQkFBa0IsV0FBbUM7QUFDNUQsU0FBTyxzQkFBc0IsU0FBUyxLQUFLLFVBQVUsV0FBVyxTQUFTLFNBQVMsZUFBZTtBQUNuRztBQUdBLFNBQVMsdUNBQXVDLFdBQTBCLHFCQUF3QztBQUNoSCxTQUNFLHNCQUFzQixTQUFTLEtBQy9CLFVBQVUsV0FBVyxTQUFTLFNBQVMsZUFBZSxrQkFDdEQsVUFBVSxXQUFXLE9BQU8sU0FBUyxTQUFTLGVBQWUsb0JBQzdELFVBQVUsV0FBVyxPQUFPLE9BQU8sU0FBUyxTQUFTL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JQUNGO0FBQUEsRUFDRjtBQUNGLENBQUM7QUFFRCxJQUFPLDBCQUFROyIsCiAgIm5hbWVzIjogW10KfQo=
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@checkdigit/eslint-plugin","version":"7.5.1-PR.101-bf22","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","import":"./dist-mjs/index.mjs","default":"./dist-mjs/index.mjs"}},"files":["src","dist-types","dist-mjs","!src/**/test/**","!src/**/*.test.ts","!src/**/*.spec.ts","!dist-types/**/test/**","!dist-types/**/*.test.d.ts","!dist-types/**/*.spec.d.ts","!dist-mjs/**/test/**","!dist-mjs/**/*.test.mjs","!dist-mjs/**/*.spec.mjs","SECURITY.md"],"scripts":{"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 .","lint:fix":"eslint --max-warnings 0 --fix .","prepare":"","prepublishOnly":"npm run build:dist-types && 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":"^8.15.0","@typescript-eslint/utils":"^8.15.0","ts-api-utils":"^1.4.0"},"devDependencies":{"@checkdigit/jest-config":"^6.0.2","@checkdigit/prettier-config":"^5.5.1","@checkdigit/typescript-config":"^8.0.0","@eslint/js":"^9.15.0","@types/eslint":"^9.6.1","@types/eslint-config-prettier":"^6.11.3","@typescript-eslint/parser":"^8.15.0","@typescript-eslint/rule-tester":"^8.15.0","eslint":"^9.15.0","eslint-config-prettier":"^9.1.0","eslint-import-resolver-typescript":"^3.6.3","eslint-plugin-eslint-plugin":"^6.3.2","eslint-plugin-import":"^2.31.0","eslint-plugin-no-only-tests":"^3.3.0","eslint-plugin-no-secrets":"^1.1.2","eslint-plugin-node":"^11.1.0","eslint-plugin-sonarjs":"1.0.4","http-status-codes":"^2.3.0","rimraf":"^6.0.1","typescript-eslint":"^8.15.0"},"peerDependencies":{"eslint":">=9 <10"},"engines":{"node":">=20.17"}}
1
+ {"name":"@checkdigit/eslint-plugin","version":"7.5.1-PR.101-6eb0","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","import":"./dist-mjs/index.mjs","default":"./dist-mjs/index.mjs"}},"files":["src","dist-types","dist-mjs","!src/**/test/**","!src/**/*.test.ts","!src/**/*.spec.ts","!dist-types/**/test/**","!dist-types/**/*.test.d.ts","!dist-types/**/*.spec.d.ts","!dist-mjs/**/test/**","!dist-mjs/**/*.test.mjs","!dist-mjs/**/*.spec.mjs","SECURITY.md"],"scripts":{"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 .","lint:fix":"eslint --max-warnings 0 --fix .","prepare":"","prepublishOnly":"npm run build:dist-types && 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":"^8.15.0","@typescript-eslint/utils":"^8.15.0","ts-api-utils":"^1.4.0"},"devDependencies":{"@checkdigit/jest-config":"^6.0.2","@checkdigit/prettier-config":"^5.5.1","@checkdigit/typescript-config":"^8.0.0","@eslint/js":"^9.15.0","@types/eslint":"^9.6.1","@types/eslint-config-prettier":"^6.11.3","@typescript-eslint/parser":"^8.15.0","@typescript-eslint/rule-tester":"^8.15.0","eslint":"^9.15.0","eslint-config-prettier":"^9.1.0","eslint-import-resolver-typescript":"^3.6.3","eslint-plugin-eslint-plugin":"^6.3.2","eslint-plugin-import":"^2.31.0","eslint-plugin-no-only-tests":"^3.3.0","eslint-plugin-no-secrets":"^1.1.2","eslint-plugin-node":"^11.1.0","eslint-plugin-sonarjs":"1.0.4","http-status-codes":"^2.3.0","rimraf":"^6.0.1","typescript-eslint":"^8.15.0"},"peerDependencies":{"eslint":">=9 <10"},"engines":{"node":">=20.17"}}
@@ -46,22 +46,44 @@ function isVariableDeclarationAwaitExpression(node: TSESTree.Node): boolean {
46
46
  );
47
47
  }
48
48
 
49
+ // Helper function to check if the callee is an identifier and not excluded
50
+ function isIdentifierCallee(node: TSESTree.CallExpression, excludedIdentifiers: string[]): boolean {
51
+ return node.callee.type === TSESTree.AST_NODE_TYPES.Identifier && !excludedIdentifiers.includes(node.callee.name);
52
+ }
53
+
54
+ // Helper function to check if the callee is a member expression and not excluded
55
+ function isMemberExpressionCallee(node: TSESTree.CallExpression, excludedIdentifiers: string[]): boolean {
56
+ return (
57
+ node.callee.type === TSESTree.AST_NODE_TYPES.MemberExpression &&
58
+ node.callee.object.type === TSESTree.AST_NODE_TYPES.Identifier &&
59
+ node.callee.property.type === TSESTree.AST_NODE_TYPES.Identifier &&
60
+ !excludedIdentifiers.includes(`${node.callee.object.name}.${node.callee.property.name}`)
61
+ );
62
+ }
63
+
64
+ // Helper function to check if the callee is a member expression with a non-identifier object
65
+ function isNonIdentifierObjectMemberExpressionCallee(node: TSESTree.CallExpression): boolean {
66
+ return (
67
+ node.callee.type === TSESTree.AST_NODE_TYPES.MemberExpression &&
68
+ node.callee.object.type !== TSESTree.AST_NODE_TYPES.Identifier
69
+ );
70
+ }
71
+
49
72
  // To check if it is a variable declaration with a call expression i.e const configuration = new Class(); or Member Expressions i.e const server = http.createServer();
50
73
  function isVariableDeclarationCallExpression(node: TSESTree.Node, excludedIdentifiers: string[]): boolean {
74
+ if (node.type !== TSESTree.AST_NODE_TYPES.VariableDeclaration || node.declarations.length === 0) {
75
+ return false;
76
+ }
77
+
78
+ const init = node.declarations[0]?.init;
79
+ if (init?.type !== TSESTree.AST_NODE_TYPES.CallExpression) {
80
+ return false;
81
+ }
82
+
51
83
  return (
52
- node.type === TSESTree.AST_NODE_TYPES.VariableDeclaration &&
53
- node.declarations.length > 0 &&
54
- node.declarations[0]?.init?.type === TSESTree.AST_NODE_TYPES.CallExpression &&
55
- ((node.declarations[0].init.callee.type === TSESTree.AST_NODE_TYPES.Identifier &&
56
- !excludedIdentifiers.includes(node.declarations[0].init.callee.name)) ||
57
- (node.declarations[0].init.callee.type === TSESTree.AST_NODE_TYPES.MemberExpression &&
58
- node.declarations[0].init.callee.object.type !== TSESTree.AST_NODE_TYPES.Identifier) ||
59
- (node.declarations[0].init.callee.type === TSESTree.AST_NODE_TYPES.MemberExpression &&
60
- node.declarations[0].init.callee.object.type === TSESTree.AST_NODE_TYPES.Identifier &&
61
- node.declarations[0].init.callee.property.type === TSESTree.AST_NODE_TYPES.Identifier &&
62
- !excludedIdentifiers.includes(
63
- `${node.declarations[0].init.callee.object.name}.${node.declarations[0].init.callee.property.name}`,
64
- )))
84
+ isIdentifierCallee(init, excludedIdentifiers) ||
85
+ isMemberExpressionCallee(init, excludedIdentifiers) ||
86
+ isNonIdentifierObjectMemberExpressionCallee(init)
65
87
  );
66
88
  }
67
89