@checkdigit/eslint-plugin 6.6.0-PR.79-7a20 → 6.7.0-PR.79-33df

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.
@@ -0,0 +1,159 @@
1
+ // src/require-resolve-full-response.ts
2
+ import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
3
+ import { DefinitionType } from "@typescript-eslint/scope-manager";
4
+ import { strict as assert } from "node:assert";
5
+ import getDocumentationUrl from "./get-documentation-url.mjs";
6
+ import { getEnclosingScopeNode } from "./library/ts-tree.mjs";
7
+ var ruleId = "require-resolve-full-response";
8
+ var PLAIN_URL_REGEXP = /^[`']\/\w+(?<serviceNamePart>-\w+)*\/v\d+\/(?<any>.|\r|\n)+[`']$/u;
9
+ var TOKENIZED_URL_REGEXP = /^`\$\{(?<serviceNamePart>[A-Z]+_)*BASE_PATH\}\/(?<any>.|\r|\n)+`$/u;
10
+ var createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
11
+ var rule = createRule({
12
+ name: ruleId,
13
+ meta: {
14
+ type: "suggestion",
15
+ docs: {
16
+ description: "Prefer native fetch over customized service wrapper."
17
+ },
18
+ messages: {
19
+ invalidOptions: '"options" argument should be provided with "resolveWithFullResponse" property set as "true". Otherwise, it indicates that the response body will be obtained without status code assertion which could result in unexpected issue.',
20
+ unknownError: 'Unknown error occurred in file "{{fileName}}": {{ error }}.'
21
+ },
22
+ schema: []
23
+ },
24
+ defaultOptions: [],
25
+ create(context) {
26
+ const sourceCode = context.sourceCode;
27
+ const scopeManager = sourceCode.scopeManager;
28
+ const parserService = ESLintUtils.getParserServices(context);
29
+ const typeChecker = parserService.program.getTypeChecker();
30
+ function isUrlArgumentValid(urlArgument, scope) {
31
+ if (urlArgument?.type === AST_NODE_TYPES.Literal && typeof urlArgument.value === "string" || urlArgument?.type === AST_NODE_TYPES.TemplateLiteral) {
32
+ const urlText = sourceCode.getText(urlArgument);
33
+ return PLAIN_URL_REGEXP.test(urlText) || TOKENIZED_URL_REGEXP.test(urlText);
34
+ }
35
+ if (urlArgument?.type === AST_NODE_TYPES.Identifier) {
36
+ const foundVariable = scope.variables.find((variable) => variable.name === urlArgument.name);
37
+ if (foundVariable) {
38
+ const variableDefinition = foundVariable.defs.find((def) => def.type === DefinitionType.Variable);
39
+ assert.ok(variableDefinition, `Variable "${urlArgument.name}" not defined in scope`);
40
+ const variableDefinitionNode = variableDefinition.node;
41
+ assert.ok(variableDefinitionNode.type === AST_NODE_TYPES.VariableDeclarator);
42
+ assert.ok(variableDefinitionNode.init, "Variable definition node has no init property");
43
+ return isUrlArgumentValid(variableDefinitionNode.init, scope);
44
+ }
45
+ }
46
+ return false;
47
+ }
48
+ function getType(identifier) {
49
+ const variable = parserService.esTreeNodeToTSNodeMap.get(identifier);
50
+ const variableType = typeChecker.getTypeAtLocation(variable);
51
+ return typeChecker.typeToString(variableType);
52
+ }
53
+ function isServiceLikeName(name) {
54
+ return /.*[Ss]ervice$/u.test(name);
55
+ }
56
+ function isCalleeServiceWrapper(serviceCall) {
57
+ const callee = serviceCall.callee;
58
+ if (callee.type !== AST_NODE_TYPES.MemberExpression) {
59
+ return false;
60
+ }
61
+ const endpoint = callee.object;
62
+ if (endpoint.type === AST_NODE_TYPES.Identifier) {
63
+ return getType(endpoint) === "Endpoint" || isServiceLikeName(endpoint.name);
64
+ }
65
+ if (endpoint.type !== AST_NODE_TYPES.CallExpression) {
66
+ return false;
67
+ }
68
+ const [contextArgument] = endpoint.arguments;
69
+ if (contextArgument?.type !== AST_NODE_TYPES.Identifier) {
70
+ return false;
71
+ }
72
+ if (contextArgument.name !== "EMPTY_CONTEXT" && getType(contextArgument) !== "InboundContext") {
73
+ return false;
74
+ }
75
+ const service = endpoint.callee;
76
+ if (service.type === AST_NODE_TYPES.Identifier) {
77
+ return getType(service) === "ResolvedService";
78
+ }
79
+ if (service.type !== AST_NODE_TYPES.MemberExpression) {
80
+ return false;
81
+ }
82
+ const services = service.object;
83
+ if (services.type === AST_NODE_TYPES.Identifier) {
84
+ return getType(services) === "ResolvedServices";
85
+ }
86
+ if (services.type !== AST_NODE_TYPES.MemberExpression) {
87
+ return false;
88
+ }
89
+ const configuration = services.object;
90
+ if (configuration.type === AST_NODE_TYPES.Identifier) {
91
+ return ["Configuration", "Configuration<ResolvedServices>"].includes(getType(configuration));
92
+ }
93
+ if (configuration.type !== AST_NODE_TYPES.MemberExpression) {
94
+ return false;
95
+ }
96
+ const fixture = configuration.object;
97
+ if (fixture.type === AST_NODE_TYPES.Identifier) {
98
+ return fixture.name === "fixture" || getType(fixture) === "Fixture";
99
+ }
100
+ return false;
101
+ }
102
+ return {
103
+ "CallExpression[callee.property.name=/^(head|get|put|post|del|patch)$/]": (serviceCall) => {
104
+ try {
105
+ if (!isCalleeServiceWrapper(serviceCall)) {
106
+ return;
107
+ }
108
+ const enclosingScopeNode = getEnclosingScopeNode(serviceCall);
109
+ assert.ok(enclosingScopeNode, "enclosingScopeNode is undefined");
110
+ const scope = scopeManager?.acquire(enclosingScopeNode);
111
+ assert.ok(scope, "scope is undefined");
112
+ const urlArgument = serviceCall.arguments[0];
113
+ if (!isUrlArgumentValid(urlArgument, scope)) {
114
+ return;
115
+ }
116
+ assert.ok(serviceCall.callee.type === AST_NODE_TYPES.MemberExpression);
117
+ assert.ok(serviceCall.callee.property.type === AST_NODE_TYPES.Identifier);
118
+ const method = serviceCall.callee.property.name;
119
+ const optionsArgument = ["get", "head", "del"].includes(method) ? serviceCall.arguments[1] : serviceCall.arguments[2];
120
+ if (optionsArgument === void 0 || optionsArgument.type !== AST_NODE_TYPES.ObjectExpression) {
121
+ context.report({
122
+ node: serviceCall,
123
+ messageId: "invalidOptions"
124
+ });
125
+ return;
126
+ }
127
+ const resolveWithFullResponseProperty = optionsArgument.properties.find(
128
+ (property) => property.type === AST_NODE_TYPES.Property && property.key.type === AST_NODE_TYPES.Identifier && property.key.name === "resolveWithFullResponse"
129
+ );
130
+ if (resolveWithFullResponseProperty?.type !== AST_NODE_TYPES.Property || resolveWithFullResponseProperty.value.type !== AST_NODE_TYPES.Literal || resolveWithFullResponseProperty.value.value !== true) {
131
+ context.report({
132
+ node: optionsArgument,
133
+ messageId: "invalidOptions"
134
+ });
135
+ return;
136
+ }
137
+ } catch (error) {
138
+ console.error(`Failed to apply ${ruleId} rule for file "${context.filename}":`, error);
139
+ context.report({
140
+ node: serviceCall,
141
+ messageId: "unknownError",
142
+ data: {
143
+ fileName: context.filename,
144
+ error: error instanceof Error ? error.toString() : JSON.stringify(error)
145
+ }
146
+ });
147
+ }
148
+ }
149
+ };
150
+ }
151
+ });
152
+ var require_resolve_full_response_default = rule;
153
+ export {
154
+ PLAIN_URL_REGEXP,
155
+ TOKENIZED_URL_REGEXP,
156
+ require_resolve_full_response_default as default,
157
+ ruleId
158
+ };
159
+ //# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL3JlcXVpcmUtcmVzb2x2ZS1mdWxsLXJlc3BvbnNlLnRzIl0sCiAgIm1hcHBpbmdzIjogIjtBQVFBLFNBQVMsZ0JBQWdCLG1CQUE2QjtBQUN0RCxTQUFTLHNCQUFrQztBQUMzQyxTQUFTLFVBQVUsY0FBYztBQUNqQyxPQUFPLHlCQUF5QjtBQUNoQyxTQUFTLDZCQUE2QjtBQUUvQixJQUFNLFNBQVM7QUFDZixJQUFNLG1CQUFtQjtBQUN6QixJQUFNLHVCQUF1QjtBQUVwQyxJQUFNLGFBQWEsWUFBWSxZQUFZLENBQUMsU0FBUyxvQkFBb0IsSUFBSSxDQUFDO0FBRTlFLElBQU0sT0FBTyxXQUFXO0FBQUEsRUFDdEIsTUFBTTtBQUFBLEVBQ04sTUFBTTtBQUFBLElBQ0osTUFBTTtBQUFBLElBQ04sTUFBTTtBQUFBLE1BQ0osYUFBYTtBQUFBLElBQ2Y7QUFBQSxJQUNBLFVBQVU7QUFBQSxNQUNSLGdCQUNFO0FBQUEsTU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TQUFTLElBQUksS0FBSyxVQUFVLEtBQUs7QUFBQSxZQUN6RTtBQUFBLFVBQ0YsQ0FBQztBQUFBLFFBQ0g7QUFBQSxNQUNGO0FBQUEsSUFDRjtBQUFBLEVBQ0Y7QUFDRixDQUFDO0FBRUQsSUFBTyx3Q0FBUTsiLAogICJuYW1lcyI6IFtdCn0K
@@ -12,6 +12,7 @@ declare const _default: {
12
12
  'object-literal-response': import("eslint").Rule.RuleModule;
13
13
  "invalid-json-stringify": import("eslint").Rule.RuleModule;
14
14
  "no-promise-instance-method": import("eslint").Rule.RuleModule;
15
+ "require-resolve-full-response": import("@typescript-eslint/utils/ts-eslint").RuleModule<"invalidOptions" | "unknownError", never[], import("@typescript-eslint/utils/ts-eslint").RuleListener>;
15
16
  };
16
17
  configs: {
17
18
  all: {
@@ -28,6 +29,7 @@ declare const _default: {
28
29
  '@checkdigit/no-test-import': string;
29
30
  "@checkdigit/invalid-json-stringify": string;
30
31
  "@checkdigit/no-promise-instance-method": string;
32
+ "@checkdigit/require-resolve-full-response": string;
31
33
  };
32
34
  };
33
35
  recommended: {
@@ -0,0 +1,4 @@
1
+ import { TSESLint, TSESTree } from '@typescript-eslint/utils';
2
+ import type { Node } from 'estree';
3
+ import type { SourceCode } from 'eslint';
4
+ export declare function getIndentation(node: Node | TSESTree.Node, sourceCode: SourceCode | TSESLint.SourceCode): string;
@@ -0,0 +1,8 @@
1
+ import type { Node } from 'estree';
2
+ export declare function getParent(node: Node): Node | undefined | null;
3
+ export declare function getAncestor(node: Node, matcher: string | ((testNode: Node) => boolean), exitMatcher?: string | ((testNode: Node) => boolean)): Node | undefined;
4
+ export declare function isBlockStatement(node: Node): boolean;
5
+ export declare function getEnclosingStatement(node: Node): Node | undefined;
6
+ export declare function getEnclosingScopeNode(node: Node): Node | undefined;
7
+ export declare function isUsedInArrayOrAsArgument(node: Node): boolean;
8
+ export declare function getEnclosingFunction(node: Node): import("estree").ArrowFunctionExpression | import("estree").FunctionExpression | import("estree").FunctionDeclaration | undefined;
@@ -0,0 +1,9 @@
1
+ import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
2
+ export declare function getParent(node: TSESTree.Node): TSESTree.Node | undefined | null;
3
+ export declare function getAncestor(node: TSESTree.Node, matcher: AST_NODE_TYPES | ((testNode: TSESTree.Node) => boolean), exitMatcher?: AST_NODE_TYPES | ((testNode: TSESTree.Node) => boolean)): TSESTree.Node | undefined;
4
+ export declare function isBlockStatement(node: TSESTree.Node): boolean;
5
+ export declare function getEnclosingStatement(node: TSESTree.Node): TSESTree.Node | undefined;
6
+ export declare function getEnclosingScopeNode(node: TSESTree.Node): TSESTree.Node | undefined;
7
+ export declare function isUsedInArrayOrAsArgument(node: TSESTree.Node): boolean;
8
+ export declare function getEnclosingFunction(node: TSESTree.Node): TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression | undefined;
9
+ export declare function getTypeParentNode(node: TSESTree.Node | undefined): TSESTree.TSTypeAnnotation | TSESTree.TSAsExpression | undefined;
@@ -0,0 +1 @@
1
+ export declare function isValidPropertyName(name: unknown): boolean;
@@ -0,0 +1,6 @@
1
+ import { ESLintUtils } from '@typescript-eslint/utils';
2
+ export declare const ruleId = "require-resolve-full-response";
3
+ export declare const PLAIN_URL_REGEXP: RegExp;
4
+ export declare const TOKENIZED_URL_REGEXP: RegExp;
5
+ declare const rule: ESLintUtils.RuleModule<"invalidOptions" | "unknownError", never[], ESLintUtils.RuleListener>;
6
+ export default rule;
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@checkdigit/eslint-plugin","version":"6.6.0-PR.79-7a20","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 && node 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"},"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","@typescript-eslint/utils":"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.7.0-PR.79-33df","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 && node 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"}}
package/src/index.ts CHANGED
@@ -8,6 +8,9 @@
8
8
 
9
9
  import invalidJsonStringify, { ruleId as invalidJsonStringifyRuleId } from './invalid-json-stringify';
10
10
  import noPromiseInstanceMethod, { ruleId as noPromiseInstanceMethodRuleId } from './no-promise-instance-method';
11
+ import requireResolveFullResponse, {
12
+ ruleId as requireResolveFullResponseRuleId,
13
+ } from './require-resolve-full-response';
11
14
  import filePathComment from './file-path-comment';
12
15
  import noCardNumbers from './no-card-numbers';
13
16
  import noEnum from './no-enum';
@@ -33,6 +36,7 @@ export default {
33
36
  'object-literal-response': objectLiteralResponse,
34
37
  [invalidJsonStringifyRuleId]: invalidJsonStringify,
35
38
  [noPromiseInstanceMethodRuleId]: noPromiseInstanceMethod,
39
+ [requireResolveFullResponseRuleId]: requireResolveFullResponse,
36
40
  },
37
41
  configs: {
38
42
  all: {
@@ -49,6 +53,7 @@ export default {
49
53
  '@checkdigit/no-test-import': 'error',
50
54
  [`@checkdigit/${invalidJsonStringifyRuleId}`]: 'error',
51
55
  [`@checkdigit/${noPromiseInstanceMethodRuleId}`]: 'error',
56
+ [`@checkdigit/${requireResolveFullResponseRuleId}`]: 'error',
52
57
  },
53
58
  },
54
59
  recommended: {
@@ -0,0 +1,20 @@
1
+ // format.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 { TSESLint, TSESTree } from '@typescript-eslint/utils';
10
+ import type { Node } from 'estree';
11
+ import type { SourceCode } from 'eslint';
12
+ import { strict as assert } from 'node:assert';
13
+
14
+ export function getIndentation(node: Node | TSESTree.Node, sourceCode: SourceCode | TSESLint.SourceCode) {
15
+ assert.ok(node.loc);
16
+ const line = sourceCode.lines[node.loc.start.line - 1];
17
+ assert.ok(line !== undefined);
18
+ const indentMatch = line.match(/^\s*/u);
19
+ return indentMatch ? indentMatch[0] : '';
20
+ }
@@ -0,0 +1,90 @@
1
+ // tree.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 type { Expression, Node } from 'estree';
10
+
11
+ type NodeParent = Node | undefined | null;
12
+
13
+ interface NodeParentExtension {
14
+ parent: NodeParent;
15
+ }
16
+
17
+ export function getParent(node: Node): Node | undefined | null {
18
+ return (node as unknown as NodeParentExtension).parent;
19
+ }
20
+
21
+ export function getAncestor(
22
+ node: Node,
23
+ matcher: string | ((testNode: Node) => boolean),
24
+ exitMatcher?: string | ((testNode: Node) => boolean),
25
+ ): Node | undefined {
26
+ const parent = getParent(node);
27
+ if (!parent) {
28
+ return undefined;
29
+ } else if (typeof matcher === 'string' && parent.type === matcher) {
30
+ return parent;
31
+ } else if (typeof matcher === 'function' && matcher(parent)) {
32
+ return parent;
33
+ } else if (typeof exitMatcher === 'string' && parent.type === exitMatcher) {
34
+ return undefined;
35
+ } else if (typeof exitMatcher === 'function' && exitMatcher(parent)) {
36
+ return undefined;
37
+ }
38
+ return getAncestor(parent, matcher, exitMatcher);
39
+ }
40
+
41
+ export function isBlockStatement(node: Node) {
42
+ return node.type.endsWith('Statement') || node.type.endsWith('Declaration');
43
+ }
44
+
45
+ export function getEnclosingStatement(node: Node) {
46
+ return getAncestor(node, isBlockStatement);
47
+ }
48
+
49
+ export function getEnclosingScopeNode(node: Node) {
50
+ return getAncestor(node, (parentNode) =>
51
+ ['FunctionExpression', 'FunctionDeclaration', 'ArrowFunctionExpression', 'Program'].includes(parentNode.type),
52
+ );
53
+ }
54
+
55
+ export function isUsedInArrayOrAsArgument(node: Node) {
56
+ if (isBlockStatement(node)) {
57
+ return false;
58
+ }
59
+
60
+ const parent = getParent(node);
61
+ if (!parent) {
62
+ return false;
63
+ }
64
+
65
+ if (
66
+ parent.type === 'ArrayExpression' ||
67
+ (parent.type === 'CallExpression' && parent.arguments.includes(node as Expression))
68
+ ) {
69
+ return true;
70
+ }
71
+
72
+ // recurse up the tree until hitting a block statement
73
+ return isUsedInArrayOrAsArgument(parent);
74
+ }
75
+
76
+ export function getEnclosingFunction(node: Node) {
77
+ if (
78
+ node.type === 'FunctionDeclaration' ||
79
+ node.type === 'FunctionExpression' ||
80
+ node.type === 'ArrowFunctionExpression'
81
+ ) {
82
+ return node;
83
+ }
84
+
85
+ const parent = getParent(node);
86
+ if (!parent) {
87
+ return;
88
+ }
89
+ return getEnclosingFunction(parent);
90
+ }
@@ -0,0 +1,101 @@
1
+ // tree.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 { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
10
+
11
+ type NodeParent = TSESTree.Node | undefined | null;
12
+
13
+ interface NodeParentExtension {
14
+ parent: NodeParent;
15
+ }
16
+
17
+ export function getParent(node: TSESTree.Node): TSESTree.Node | undefined | null {
18
+ return (node as unknown as NodeParentExtension).parent;
19
+ }
20
+
21
+ export function getAncestor(
22
+ node: TSESTree.Node,
23
+ matcher: AST_NODE_TYPES | ((testNode: TSESTree.Node) => boolean),
24
+ exitMatcher?: AST_NODE_TYPES | ((testNode: TSESTree.Node) => boolean),
25
+ ): TSESTree.Node | undefined {
26
+ const parent = getParent(node);
27
+ if (!parent) {
28
+ return undefined;
29
+ } else if (typeof matcher === 'string' && parent.type === matcher) {
30
+ return parent;
31
+ } else if (typeof matcher === 'function' && matcher(parent)) {
32
+ return parent;
33
+ } else if (typeof exitMatcher === 'string' && parent.type === exitMatcher) {
34
+ return undefined;
35
+ } else if (typeof exitMatcher === 'function' && exitMatcher(parent)) {
36
+ return undefined;
37
+ }
38
+ return getAncestor(parent, matcher, exitMatcher);
39
+ }
40
+
41
+ export function isBlockStatement(node: TSESTree.Node) {
42
+ return node.type.endsWith('Statement') || node.type.endsWith('Declaration');
43
+ }
44
+
45
+ export function getEnclosingStatement(node: TSESTree.Node) {
46
+ return getAncestor(node, isBlockStatement);
47
+ }
48
+
49
+ export function getEnclosingScopeNode(node: TSESTree.Node) {
50
+ return getAncestor(node, (parentNode) =>
51
+ ['FunctionExpression', 'FunctionDeclaration', 'ArrowFunctionExpression', 'Program'].includes(parentNode.type),
52
+ );
53
+ }
54
+
55
+ export function isUsedInArrayOrAsArgument(node: TSESTree.Node) {
56
+ if (isBlockStatement(node)) {
57
+ return false;
58
+ }
59
+
60
+ const parent = getParent(node);
61
+ if (!parent) {
62
+ return false;
63
+ }
64
+
65
+ if (
66
+ parent.type === AST_NODE_TYPES.ArrayExpression ||
67
+ (parent.type === AST_NODE_TYPES.CallExpression && parent.arguments.includes(node as TSESTree.Expression))
68
+ ) {
69
+ return true;
70
+ }
71
+
72
+ // recurse up the tree until hitting a block statement
73
+ return isUsedInArrayOrAsArgument(parent);
74
+ }
75
+
76
+ export function getEnclosingFunction(node: TSESTree.Node) {
77
+ if (
78
+ node.type === AST_NODE_TYPES.FunctionDeclaration ||
79
+ node.type === AST_NODE_TYPES.FunctionExpression ||
80
+ node.type === AST_NODE_TYPES.ArrowFunctionExpression
81
+ ) {
82
+ return node;
83
+ }
84
+
85
+ const parent = getParent(node);
86
+ if (!parent) {
87
+ return;
88
+ }
89
+ return getEnclosingFunction(parent);
90
+ }
91
+
92
+ export function getTypeParentNode(
93
+ node: TSESTree.Node | undefined,
94
+ ): TSESTree.TSTypeAnnotation | TSESTree.TSAsExpression | undefined {
95
+ if (!node) {
96
+ return undefined;
97
+ }
98
+ return node.type === AST_NODE_TYPES.TSTypeAnnotation || node.type === AST_NODE_TYPES.TSAsExpression
99
+ ? node
100
+ : getTypeParentNode(node.parent);
101
+ }
@@ -0,0 +1,5 @@
1
+ // fixture/variable.ts
2
+
3
+ export function isValidPropertyName(name: unknown) {
4
+ return typeof name === 'string' && /^[a-zA-Z_$][a-zA-Z_$0-9]*$/u.test(name);
5
+ }
package/src/no-enum.ts CHANGED
@@ -1,18 +1,32 @@
1
1
  // no-enum.ts
2
2
 
3
- import { ESLintUtils, TSESTree } from '@typescript-eslint/utils';
4
-
5
3
  /*
6
4
  * Copyright (c) 2021-2024 Check Digit, LLC
7
5
  *
8
6
  * This code is licensed under the MIT license (see LICENSE.txt for details).
9
7
  */
10
8
 
9
+ import { ESLintUtils, TSESTree } from '@typescript-eslint/utils';
10
+
11
11
  export const ruleId = 'no-enum';
12
12
  const NO_ENUM = 'NO_ENUM';
13
13
 
14
14
  const createRule = ESLintUtils.RuleCreator((name) => name);
15
15
 
16
+ function isJsonSchemaProperty(node?: TSESTree.Node): boolean {
17
+ if (!node) {
18
+ return false;
19
+ }
20
+ if (
21
+ node.type === TSESTree.AST_NODE_TYPES.Property &&
22
+ node.key.type === TSESTree.AST_NODE_TYPES.Identifier &&
23
+ node.key.name === 'properties'
24
+ ) {
25
+ return true;
26
+ }
27
+ return isJsonSchemaProperty(node.parent);
28
+ }
29
+
16
30
  const rule = createRule({
17
31
  name: ruleId,
18
32
  meta: {
@@ -38,7 +52,8 @@ const rule = createRule({
38
52
  if (
39
53
  node.key.type === TSESTree.AST_NODE_TYPES.Identifier &&
40
54
  node.key.name === 'enum' &&
41
- node.value.type === TSESTree.AST_NODE_TYPES.ArrayExpression
55
+ node.value.type === TSESTree.AST_NODE_TYPES.ArrayExpression &&
56
+ !isJsonSchemaProperty(node.parent)
42
57
  ) {
43
58
  context.report({
44
59
  node,