@checkdigit/eslint-plugin 6.6.0-PR.75-0fc6 → 6.6.0-PR.77-885a
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/index.cjs +779 -2464
- package/dist-cjs/metafile.json +203 -795
- package/dist-mjs/index.mjs +3 -77
- package/dist-mjs/require-resolve-full-response.mjs +5 -2
- package/dist-types/index.d.ts +1 -51
- package/dist-types/require-resolve-full-response.d.ts +3 -1
- package/package.json +1 -1
- package/src/index.ts +0 -74
- package/src/library/format.ts +1 -1
- package/src/library/tree.ts +1 -1
- package/src/library/ts-tree.ts +1 -1
- package/src/library/variable.ts +1 -1
- package/src/require-resolve-full-response.ts +2 -1
- package/dist-mjs/agent/add-url-domain.mjs +0 -61
- package/dist-mjs/agent/fetch-response-body-json.mjs +0 -63
- package/dist-mjs/agent/fetch-response-header-getter.mjs +0 -117
- package/dist-mjs/agent/fetch-then.mjs +0 -269
- package/dist-mjs/agent/fetch.mjs +0 -34
- package/dist-mjs/agent/no-fixture.mjs +0 -328
- package/dist-mjs/agent/no-full-response.mjs +0 -67
- package/dist-mjs/agent/no-mapped-response.mjs +0 -75
- package/dist-mjs/agent/no-service-wrapper.mjs +0 -184
- package/dist-mjs/agent/no-status-code.mjs +0 -59
- package/dist-mjs/agent/no-unused-function-argument.mjs +0 -79
- package/dist-mjs/agent/no-unused-service-variable.mjs +0 -75
- package/dist-mjs/agent/response-reference.mjs +0 -56
- package/dist-mjs/agent/url.mjs +0 -26
- package/dist-mjs/no-duplicated-imports.mjs +0 -87
- package/dist-mjs/require-fixed-services-import.mjs +0 -46
- package/dist-mjs/require-type-out-of-type-only-imports.mjs +0 -48
- package/dist-types/agent/add-url-domain.d.ts +0 -4
- package/dist-types/agent/fetch-response-body-json.d.ts +0 -4
- package/dist-types/agent/fetch-response-header-getter.d.ts +0 -4
- package/dist-types/agent/fetch-then.d.ts +0 -4
- package/dist-types/agent/fetch.d.ts +0 -4
- package/dist-types/agent/no-fixture.d.ts +0 -4
- package/dist-types/agent/no-full-response.d.ts +0 -4
- package/dist-types/agent/no-mapped-response.d.ts +0 -4
- package/dist-types/agent/no-service-wrapper.d.ts +0 -4
- package/dist-types/agent/no-status-code.d.ts +0 -4
- package/dist-types/agent/no-unused-function-argument.d.ts +0 -4
- package/dist-types/agent/no-unused-service-variable.d.ts +0 -4
- package/dist-types/agent/response-reference.d.ts +0 -16
- package/dist-types/agent/url.d.ts +0 -5
- package/dist-types/no-duplicated-imports.d.ts +0 -4
- package/dist-types/require-fixed-services-import.d.ts +0 -4
- package/dist-types/require-type-out-of-type-only-imports.d.ts +0 -4
- package/src/agent/add-url-domain.ts +0 -75
- package/src/agent/fetch-response-body-json.ts +0 -76
- package/src/agent/fetch-response-header-getter.ts +0 -148
- package/src/agent/fetch-then.ts +0 -354
- package/src/agent/fetch.ts +0 -52
- package/src/agent/no-fixture.ts +0 -453
- package/src/agent/no-full-response.ts +0 -75
- package/src/agent/no-mapped-response.ts +0 -84
- package/src/agent/no-service-wrapper.ts +0 -238
- package/src/agent/no-status-code.ts +0 -71
- package/src/agent/no-unused-function-argument.ts +0 -96
- package/src/agent/no-unused-service-variable.ts +0 -92
- package/src/agent/response-reference.ts +0 -100
- package/src/agent/url.ts +0 -23
- package/src/no-duplicated-imports.ts +0 -116
- package/src/require-fixed-services-import.ts +0 -52
- package/src/require-type-out-of-type-only-imports.ts +0 -63
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
// src/require-type-out-of-type-only-imports.ts
|
|
2
|
-
import { ESLintUtils, TSESTree } from "@typescript-eslint/utils";
|
|
3
|
-
import getDocumentationUrl from "./get-documentation-url.mjs";
|
|
4
|
-
var ruleId = "require-type-out-of-type-only-imports";
|
|
5
|
-
var createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
|
|
6
|
-
var rule = createRule({
|
|
7
|
-
name: ruleId,
|
|
8
|
-
meta: {
|
|
9
|
-
type: "suggestion",
|
|
10
|
-
docs: {
|
|
11
|
-
description: 'Require "type" to be out side of type-only imports.'
|
|
12
|
-
},
|
|
13
|
-
messages: {
|
|
14
|
-
moveTypeOutside: 'Update the type-only imports to use "tpe" outside of the curly braces.'
|
|
15
|
-
},
|
|
16
|
-
fixable: "code",
|
|
17
|
-
schema: []
|
|
18
|
-
},
|
|
19
|
-
defaultOptions: [],
|
|
20
|
-
create(context) {
|
|
21
|
-
const sourceCode = context.sourceCode;
|
|
22
|
-
return {
|
|
23
|
-
ImportDeclaration(declaration) {
|
|
24
|
-
if (declaration.importKind === "type" || !declaration.specifiers.every(
|
|
25
|
-
(specifier) => specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier && specifier.importKind === "type"
|
|
26
|
-
)) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
context.report({
|
|
30
|
-
messageId: "moveTypeOutside",
|
|
31
|
-
node: declaration,
|
|
32
|
-
*fix(fixer) {
|
|
33
|
-
const moduleName = declaration.source.value;
|
|
34
|
-
const mergedSpecifiers = declaration.specifiers.filter((specifier) => specifier.type !== TSESTree.AST_NODE_TYPES.ImportDefaultSpecifier).map((specifier) => sourceCode.getText(specifier).replace("type ", ""));
|
|
35
|
-
const updatedImportDeclaration = `import type { ${mergedSpecifiers.join(", ")} } from '${moduleName}';`;
|
|
36
|
-
yield fixer.replaceText(declaration, updatedImportDeclaration);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
var require_type_out_of_type_only_imports_default = rule;
|
|
44
|
-
export {
|
|
45
|
-
require_type_out_of_type_only_imports_default as default,
|
|
46
|
-
ruleId
|
|
47
|
-
};
|
|
48
|
-
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc3JjL3JlcXVpcmUtdHlwZS1vdXQtb2YtdHlwZS1vbmx5LWltcG9ydHMudHMiXSwKICAibWFwcGluZ3MiOiAiO0FBUUEsU0FBUyxhQUFhLGdCQUFnQjtBQUN0QyxPQUFPLHlCQUF5QjtBQUV6QixJQUFNLFNBQVM7QUFFdEIsSUFBTSxhQUFhLFlBQVksWUFBWSxDQUFDLFNBQVMsb0JBQW9CLElBQUksQ0FBQztBQUU5RSxJQUFNLE9BQU8sV0FBVztBQUFBLEVBQ3RCLE1BQU07QUFBQSxFQUNOLE1BQU07QUFBQSxJQUNKLE1BQU07QUFBQSxJQUNOLE1BQU07QUFBQSxNQUNKLGFBQWE7QUFBQSxJQUNmO0FBQUEsSUFDQSxVQUFVO0FBQUEsTUFDUixpQkFBaUI7QUFBQSxJQUNuQjtBQUFBLElBQ0EsU0FBUztBQUFBLElBQ1QsUUFBUSxDQUFDO0FBQUEsRUFDWDtBQUFBLEVBQ0EsZ0JBQWdCLENBQUM7QUFBQSxFQUNqQixPQUFPLFNBQVM7QUFDZCxVQUFNLGFBQWEsUUFBUTtBQUUzQixXQUFPO0FBQUEsTUFDTCxrQkFBa0IsYUFBYTtBQUM3QixZQUNFLFlBQVksZUFBZSxVQUMzQixDQUFDLFlBQVksV0FBVztBQUFBLFVBQ3RCLENBQUMsY0FDQyxVQUFVLFNBQVMsU0FBUyxlQUFlLG1CQUFtQixVQUFVLGVBQWU7QUFBQSxRQUMzRixHQUNBO0FBQ0E7QUFBQSxRQUNGO0FBRUEsZ0JBQVEsT0FBTztBQUFBLFVBQ2IsV0FBVztBQUFBLFVBQ1gsTUFBTTtBQUFBLFVBQ04sQ0FBQyxJQUFJLE9BQU87QUFDVixrQkFBTSxhQUFhLFlBQVksT0FBTztBQUN0QyxrQkFBTSxtQkFBbUIsWUFBWSxXQUNsQyxPQUFPLENBQUMsY0FBYyxVQUFVLFNBQVMsU0FBUyxlQUFlLHNCQUFzQixFQUN2RixJQUFJLENBQUMsY0FBYyxXQUFXLFFBQVEsU0FBUyxFQUFFLFFBQVEsU0FBUyxFQUFFLENBQUM7QUFDeEUsa0JBQU0sMkJBQTJCLGlCQUFpQixpQkFBaUIsS0FBSyxJQUFJLENBQUMsWUFBWSxVQUFVO0FBRW5HLGtCQUFNLE1BQU0sWUFBWSxhQUFhLHdCQUF3QjtBQUFBLFVBQy9EO0FBQUEsUUFDRixDQUFDO0FBQUEsTUFDSDtBQUFBLElBQ0Y7QUFBQSxFQUNGO0FBQ0YsQ0FBQztBQUVELElBQU8sZ0RBQVE7IiwKICAibmFtZXMiOiBbXQp9Cg==
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { Node } from 'estree';
|
|
2
|
-
export declare function getResponseBodyRetrievalText(responseVariableName: string): string;
|
|
3
|
-
export declare function isInvalidResponseHeadersAccess(responseHeadersAccess: Node): boolean;
|
|
4
|
-
export declare function hasAssertions(fixtureCall: Node): boolean;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { MemberExpression, VariableDeclaration } from 'estree';
|
|
2
|
-
import { type Scope } from 'eslint';
|
|
3
|
-
/**
|
|
4
|
-
* analyze response related variables and their references
|
|
5
|
-
* the implementation is for fixture API, but it can be used for fetch API as well since the tree structure is similar
|
|
6
|
-
* @param variableDeclaration - variable declaration node
|
|
7
|
-
*/
|
|
8
|
-
export declare function analyzeResponseReferences(variableDeclaration: VariableDeclaration | undefined, scopeManager: Scope.ScopeManager): {
|
|
9
|
-
variable?: Scope.Variable;
|
|
10
|
-
bodyReferences: MemberExpression[];
|
|
11
|
-
headersReferences: MemberExpression[];
|
|
12
|
-
statusReferences: MemberExpression[];
|
|
13
|
-
destructuringBodyVariable?: Scope.Variable;
|
|
14
|
-
destructuringHeadersVariable?: Scope.Variable;
|
|
15
|
-
destructuringHeadersReferences?: MemberExpression[] | undefined;
|
|
16
|
-
};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export declare const PLAIN_URL_REGEXP: RegExp;
|
|
2
|
-
export declare const TOKENIZED_URL_REGEXP: RegExp;
|
|
3
|
-
export declare function replaceEndpointUrlPrefixWithBasePath(url: string): string;
|
|
4
|
-
export declare function replaceEndpointUrlPrefixWithDomain(url: string): string;
|
|
5
|
-
export declare function addBasePathUrlDomain(url: string): string;
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
// agent/add-url-domain.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, ESLintUtils, TSESTree } from '@typescript-eslint/utils';
|
|
10
|
-
import { addBasePathUrlDomain } from './url';
|
|
11
|
-
import getDocumentationUrl from '../get-documentation-url';
|
|
12
|
-
|
|
13
|
-
export const ruleId = 'add-url-domain';
|
|
14
|
-
|
|
15
|
-
const createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
|
|
16
|
-
|
|
17
|
-
const rule = createRule({
|
|
18
|
-
name: ruleId,
|
|
19
|
-
meta: {
|
|
20
|
-
type: 'suggestion',
|
|
21
|
-
docs: {
|
|
22
|
-
description: 'Add HTTP domain to the BASE_PATH like url constant variable.',
|
|
23
|
-
},
|
|
24
|
-
messages: {
|
|
25
|
-
addDomain: 'Add HTTP domain to the BASE_PATH like url constant variable.',
|
|
26
|
-
unknownError: 'Unknown error occurred in file "{{fileName}}": {{ error }}.',
|
|
27
|
-
},
|
|
28
|
-
fixable: 'code',
|
|
29
|
-
schema: [],
|
|
30
|
-
},
|
|
31
|
-
defaultOptions: [],
|
|
32
|
-
create(context) {
|
|
33
|
-
const sourceCode = context.sourceCode;
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
'VariableDeclarator[id.name=/^([A-Z]+_)*BASE_PATH$/]': (basePathDeclarator: TSESTree.VariableDeclarator) => {
|
|
37
|
-
try {
|
|
38
|
-
if (
|
|
39
|
-
basePathDeclarator.init === null ||
|
|
40
|
-
(basePathDeclarator.init.type !== AST_NODE_TYPES.Literal &&
|
|
41
|
-
basePathDeclarator.init.type !== AST_NODE_TYPES.TemplateLiteral)
|
|
42
|
-
) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const urlText = sourceCode.getText(basePathDeclarator.init);
|
|
47
|
-
const replacement = addBasePathUrlDomain(urlText);
|
|
48
|
-
|
|
49
|
-
if (replacement !== urlText) {
|
|
50
|
-
context.report({
|
|
51
|
-
messageId: 'addDomain',
|
|
52
|
-
node: basePathDeclarator.init,
|
|
53
|
-
fix(fixer) {
|
|
54
|
-
return fixer.replaceText(basePathDeclarator.init as TSESTree.Node, replacement);
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
} catch (error) {
|
|
59
|
-
// eslint-disable-next-line no-console
|
|
60
|
-
console.error(`Failed to apply ${ruleId} rule for file "${context.filename}":`, error);
|
|
61
|
-
context.report({
|
|
62
|
-
node: basePathDeclarator,
|
|
63
|
-
messageId: 'unknownError',
|
|
64
|
-
data: {
|
|
65
|
-
fileName: context.filename,
|
|
66
|
-
error: error instanceof Error ? error.toString() : JSON.stringify(error),
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
export default rule;
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
// agent/fetch-response-body-json.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, ESLintUtils, TSESTree } from '@typescript-eslint/utils';
|
|
10
|
-
import getDocumentationUrl from '../get-documentation-url';
|
|
11
|
-
|
|
12
|
-
export const ruleId = 'fetch-response-body-json';
|
|
13
|
-
|
|
14
|
-
const createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
|
|
15
|
-
|
|
16
|
-
const rule = createRule({
|
|
17
|
-
name: ruleId,
|
|
18
|
-
meta: {
|
|
19
|
-
type: 'suggestion',
|
|
20
|
-
docs: {
|
|
21
|
-
description: 'Replace "response.body" with "await response.json()".',
|
|
22
|
-
},
|
|
23
|
-
messages: {
|
|
24
|
-
replaceBodyWithJson: 'Replace "response.body" with "await response.json()".',
|
|
25
|
-
unknownError: 'Unknown error occurred in file "{{fileName}}": {{ error }}.',
|
|
26
|
-
},
|
|
27
|
-
fixable: 'code',
|
|
28
|
-
schema: [],
|
|
29
|
-
},
|
|
30
|
-
defaultOptions: [],
|
|
31
|
-
create(context) {
|
|
32
|
-
const parserServices = ESLintUtils.getParserServices(context);
|
|
33
|
-
const typeChecker = parserServices.program.getTypeChecker();
|
|
34
|
-
const sourceCode = context.sourceCode;
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
'MemberExpression[property.name="body"]': (responseBody: TSESTree.MemberExpression) => {
|
|
38
|
-
try {
|
|
39
|
-
const responseNode = parserServices.esTreeNodeToTSNodeMap.get(responseBody.object);
|
|
40
|
-
const responseType = typeChecker.getTypeAtLocation(responseNode);
|
|
41
|
-
|
|
42
|
-
const shouldReplace =
|
|
43
|
-
responseType.getProperties().some((symbol) => symbol.name === 'body') &&
|
|
44
|
-
responseType.getProperties().some((symbol) => symbol.name === 'json');
|
|
45
|
-
|
|
46
|
-
if (shouldReplace) {
|
|
47
|
-
const responseText = sourceCode.getText(responseBody.object);
|
|
48
|
-
const needAwait = responseBody.parent.type !== AST_NODE_TYPES.ReturnStatement;
|
|
49
|
-
const replacementText = needAwait ? `(await ${responseText}.json())` : `${responseText}.json()`;
|
|
50
|
-
|
|
51
|
-
context.report({
|
|
52
|
-
messageId: 'replaceBodyWithJson',
|
|
53
|
-
node: responseBody,
|
|
54
|
-
fix(fixer) {
|
|
55
|
-
return fixer.replaceText(responseBody, replacementText);
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
} catch (error) {
|
|
60
|
-
// eslint-disable-next-line no-console
|
|
61
|
-
console.error(`Failed to apply ${ruleId} rule for file "${context.filename}":`, error);
|
|
62
|
-
context.report({
|
|
63
|
-
node: responseBody,
|
|
64
|
-
messageId: 'unknownError',
|
|
65
|
-
data: {
|
|
66
|
-
fileName: context.filename,
|
|
67
|
-
error: error instanceof Error ? error.toString() : JSON.stringify(error),
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
export default rule;
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
// agent/fetch-response-header-getter-ts.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, ESLintUtils, TSESTree } from '@typescript-eslint/utils';
|
|
10
|
-
import getDocumentationUrl from '../get-documentation-url';
|
|
11
|
-
|
|
12
|
-
export const ruleId = 'fetch-response-header-getter-ts';
|
|
13
|
-
const HEADER_BUILTIN_FUNCTIONS = Object.keys(Headers.prototype);
|
|
14
|
-
|
|
15
|
-
const createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
|
|
16
|
-
|
|
17
|
-
const rule = createRule({
|
|
18
|
-
name: ruleId,
|
|
19
|
-
meta: {
|
|
20
|
-
type: 'suggestion',
|
|
21
|
-
docs: {
|
|
22
|
-
description: 'Use "get()" method to get header value from the headers object of the fetch response.',
|
|
23
|
-
},
|
|
24
|
-
messages: {
|
|
25
|
-
useGetter: 'Use "get()" method to get header value from the headers object of the fetch response.',
|
|
26
|
-
unknownError: 'Unknown error occurred in file "{{fileName}}": {{ error }}.',
|
|
27
|
-
},
|
|
28
|
-
fixable: 'code',
|
|
29
|
-
schema: [],
|
|
30
|
-
},
|
|
31
|
-
defaultOptions: [],
|
|
32
|
-
create(context) {
|
|
33
|
-
const parserServices = ESLintUtils.getParserServices(context);
|
|
34
|
-
const typeChecker = parserServices.program.getTypeChecker();
|
|
35
|
-
const sourceCode = context.sourceCode;
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
MemberExpression: (responseHeadersAccess: TSESTree.MemberExpression) => {
|
|
39
|
-
try {
|
|
40
|
-
if (
|
|
41
|
-
responseHeadersAccess.property.type === AST_NODE_TYPES.Identifier &&
|
|
42
|
-
HEADER_BUILTIN_FUNCTIONS.includes(responseHeadersAccess.property.name)
|
|
43
|
-
) {
|
|
44
|
-
// skip Headers's built-in function calls
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const responseHeadersTsNode = parserServices.esTreeNodeToTSNodeMap.get(responseHeadersAccess.object);
|
|
49
|
-
let responseHeadersType = typeChecker.getTypeAtLocation(responseHeadersTsNode);
|
|
50
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
51
|
-
responseHeadersType = responseHeadersType.isUnion() ? responseHeadersType.types[0]! : responseHeadersType;
|
|
52
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
53
|
-
const responseHeadersTypeName = // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
54
|
-
(responseHeadersType.symbol ?? responseHeadersType.aliasSymbol)?.escapedName;
|
|
55
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|
|
56
|
-
if (responseHeadersTypeName !== 'Headers' && responseHeadersTypeName !== 'HeaderGetter') {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
let replacementText: string;
|
|
61
|
-
if (!responseHeadersAccess.computed) {
|
|
62
|
-
// e.g. headers.etag
|
|
63
|
-
replacementText = `${sourceCode.getText(responseHeadersAccess.object)}.get('${sourceCode.getText(responseHeadersAccess.property)}')`;
|
|
64
|
-
} else if (
|
|
65
|
-
responseHeadersAccess.property.type === AST_NODE_TYPES.Identifier ||
|
|
66
|
-
responseHeadersAccess.property.type === AST_NODE_TYPES.Literal ||
|
|
67
|
-
responseHeadersAccess.property.type === AST_NODE_TYPES.TemplateLiteral
|
|
68
|
-
) {
|
|
69
|
-
replacementText = `${sourceCode.getText(responseHeadersAccess.object)}.get(${sourceCode.getText(responseHeadersAccess.property)})`;
|
|
70
|
-
} else {
|
|
71
|
-
throw new Error(`Unexpected property type: ${responseHeadersAccess.property.type}`);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
context.report({
|
|
75
|
-
messageId: 'useGetter',
|
|
76
|
-
node: responseHeadersAccess.property,
|
|
77
|
-
fix(fixer) {
|
|
78
|
-
return fixer.replaceText(responseHeadersAccess, replacementText);
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
} catch (error) {
|
|
82
|
-
// eslint-disable-next-line no-console
|
|
83
|
-
console.error(`Failed to apply ${ruleId} rule for file "${context.filename}":`, error);
|
|
84
|
-
context.report({
|
|
85
|
-
node: responseHeadersAccess,
|
|
86
|
-
messageId: 'unknownError',
|
|
87
|
-
data: {
|
|
88
|
-
fileName: context.filename,
|
|
89
|
-
error: error instanceof Error ? error.toString() : JSON.stringify(error),
|
|
90
|
-
},
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
|
|
95
|
-
// convert response.get() to response.headers.get()
|
|
96
|
-
'CallExpression[callee.property.name="get"]': (responseHeadersAccess: TSESTree.CallExpression) => {
|
|
97
|
-
try {
|
|
98
|
-
if (responseHeadersAccess.callee.type !== AST_NODE_TYPES.MemberExpression) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// skip request-like calls
|
|
103
|
-
if (
|
|
104
|
-
responseHeadersAccess.callee.object.type !== AST_NODE_TYPES.Identifier ||
|
|
105
|
-
responseHeadersAccess.callee.object.name === 'request'
|
|
106
|
-
) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
const responseNode = responseHeadersAccess.callee.object;
|
|
110
|
-
const responseHeadersTsNode = parserServices.esTreeNodeToTSNodeMap.get(responseNode);
|
|
111
|
-
const responseType = typeChecker.getTypeAtLocation(responseHeadersTsNode);
|
|
112
|
-
const typeName = typeChecker.typeToString(responseType);
|
|
113
|
-
if (typeName === 'InboundContext' || typeName.endsWith('RequestType')) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// make sure the response type has "headers" property
|
|
118
|
-
const hasHeadersProperty = responseType.getProperties().some((symbol) => symbol.name === 'headers');
|
|
119
|
-
if (!hasHeadersProperty) {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const replacementText = `${sourceCode.getText(responseNode)}.headers`;
|
|
124
|
-
context.report({
|
|
125
|
-
messageId: 'useGetter',
|
|
126
|
-
node: responseHeadersAccess,
|
|
127
|
-
fix(fixer) {
|
|
128
|
-
return fixer.replaceText(responseNode, replacementText);
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
} catch (error) {
|
|
132
|
-
// eslint-disable-next-line no-console
|
|
133
|
-
console.error(`Failed to apply ${ruleId} rule for file "${context.filename}":`, error);
|
|
134
|
-
context.report({
|
|
135
|
-
node: responseHeadersAccess,
|
|
136
|
-
messageId: 'unknownError',
|
|
137
|
-
data: {
|
|
138
|
-
fileName: context.filename,
|
|
139
|
-
error: error instanceof Error ? error.toString() : JSON.stringify(error),
|
|
140
|
-
},
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
};
|
|
145
|
-
},
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
export default rule;
|