@checkdigit/eslint-plugin 7.3.0-PR.75-f04b → 7.3.0-PR.89-2e8d

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.
Files changed (81) hide show
  1. package/README.md +2 -1
  2. package/dist-mjs/agent/no-full-response.mjs +35 -0
  3. package/dist-mjs/{no-serve-runtime.mjs → agent/no-serve-runtime.mjs} +3 -3
  4. package/dist-mjs/index.mjs +51 -172
  5. package/dist-mjs/library/tree.mjs +2 -2
  6. package/dist-mjs/no-random-v4-uuid.mjs +67 -0
  7. package/dist-mjs/require-resolve-full-response.mjs +15 -30
  8. package/dist-types/agent/no-full-response.d.ts +4 -0
  9. package/dist-types/index.d.ts +2 -4
  10. package/dist-types/no-random-v4-uuid.d.ts +5 -0
  11. package/package.json +1 -1
  12. package/src/agent/no-full-response.ts +41 -0
  13. package/src/{no-serve-runtime.ts → agent/no-serve-runtime.ts} +2 -2
  14. package/src/index.ts +50 -173
  15. package/src/library/tree.ts +0 -1
  16. package/src/no-random-v4-uuid.ts +92 -0
  17. package/src/require-resolve-full-response.ts +21 -38
  18. package/dist-mjs/agent/add-assert-import.mjs +0 -58
  19. package/dist-mjs/agent/add-base-path-const.mjs +0 -65
  20. package/dist-mjs/agent/add-base-path-import.mjs +0 -60
  21. package/dist-mjs/agent/add-url-domain.mjs +0 -61
  22. package/dist-mjs/agent/agent-test-wiring.mjs +0 -221
  23. package/dist-mjs/agent/fetch-response-body-json.mjs +0 -146
  24. package/dist-mjs/agent/fetch-response-header-getter.mjs +0 -117
  25. package/dist-mjs/agent/fetch-then.mjs +0 -269
  26. package/dist-mjs/agent/fetch.mjs +0 -38
  27. package/dist-mjs/agent/file.mjs +0 -43
  28. package/dist-mjs/agent/fix-function-call-arguments.mjs +0 -153
  29. package/dist-mjs/agent/no-fixture.mjs +0 -356
  30. package/dist-mjs/agent/no-mapped-response.mjs +0 -75
  31. package/dist-mjs/agent/no-service-wrapper.mjs +0 -185
  32. package/dist-mjs/agent/no-status-code.mjs +0 -59
  33. package/dist-mjs/agent/no-unused-function-argument.mjs +0 -79
  34. package/dist-mjs/agent/no-unused-imports.mjs +0 -81
  35. package/dist-mjs/agent/no-unused-service-variable.mjs +0 -74
  36. package/dist-mjs/agent/response-reference.mjs +0 -70
  37. package/dist-mjs/agent/url.mjs +0 -32
  38. package/dist-mjs/no-legacy-service-typing.mjs +0 -39
  39. package/dist-types/agent/add-assert-import.d.ts +0 -4
  40. package/dist-types/agent/add-base-path-const.d.ts +0 -4
  41. package/dist-types/agent/add-base-path-import.d.ts +0 -4
  42. package/dist-types/agent/add-url-domain.d.ts +0 -4
  43. package/dist-types/agent/agent-test-wiring.d.ts +0 -4
  44. package/dist-types/agent/fetch-response-body-json.d.ts +0 -4
  45. package/dist-types/agent/fetch-response-header-getter.d.ts +0 -4
  46. package/dist-types/agent/fetch-then.d.ts +0 -4
  47. package/dist-types/agent/fetch.d.ts +0 -5
  48. package/dist-types/agent/file.d.ts +0 -7
  49. package/dist-types/agent/fix-function-call-arguments.d.ts +0 -9
  50. package/dist-types/agent/no-fixture.d.ts +0 -4
  51. package/dist-types/agent/no-mapped-response.d.ts +0 -4
  52. package/dist-types/agent/no-service-wrapper.d.ts +0 -4
  53. package/dist-types/agent/no-status-code.d.ts +0 -4
  54. package/dist-types/agent/no-unused-function-argument.d.ts +0 -4
  55. package/dist-types/agent/no-unused-imports.d.ts +0 -4
  56. package/dist-types/agent/no-unused-service-variable.d.ts +0 -4
  57. package/dist-types/agent/response-reference.d.ts +0 -16
  58. package/dist-types/agent/url.d.ts +0 -4
  59. package/dist-types/no-legacy-service-typing.d.ts +0 -5
  60. package/src/agent/add-assert-import.ts +0 -74
  61. package/src/agent/add-base-path-const.ts +0 -81
  62. package/src/agent/add-base-path-import.ts +0 -69
  63. package/src/agent/add-url-domain.ts +0 -76
  64. package/src/agent/agent-test-wiring.ts +0 -273
  65. package/src/agent/fetch-response-body-json.ts +0 -197
  66. package/src/agent/fetch-response-header-getter.ts +0 -148
  67. package/src/agent/fetch-then.ts +0 -357
  68. package/src/agent/fetch.ts +0 -57
  69. package/src/agent/file.ts +0 -42
  70. package/src/agent/fix-function-call-arguments.ts +0 -200
  71. package/src/agent/no-fixture.ts +0 -512
  72. package/src/agent/no-mapped-response.ts +0 -84
  73. package/src/agent/no-service-wrapper.ts +0 -241
  74. package/src/agent/no-status-code.ts +0 -72
  75. package/src/agent/no-unused-function-argument.ts +0 -98
  76. package/src/agent/no-unused-imports.ts +0 -103
  77. package/src/agent/no-unused-service-variable.ts +0 -93
  78. package/src/agent/response-reference.ts +0 -129
  79. package/src/agent/url.ts +0 -32
  80. package/src/no-legacy-service-typing.ts +0 -49
  81. /package/dist-types/{no-serve-runtime.d.ts → agent/no-serve-runtime.d.ts} +0 -0
@@ -1,129 +0,0 @@
1
- // agent/response-reference.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 { strict as assert } from 'node:assert';
10
- import type { MemberExpression, ObjectPattern, VariableDeclaration } from 'estree';
11
- import { type Scope } from 'eslint';
12
- import debug from 'debug';
13
-
14
- import { getParent } from '../library/tree';
15
-
16
- const log = debug('eslint-plugin:response-reference');
17
-
18
- /**
19
- * analyze response related variables and their references
20
- * the implementation is for fixture API, but it can be used for fetch API as well since the tree structure is similar
21
- * @param variableDeclaration - variable declaration node
22
- */
23
- export function analyzeResponseReferences(
24
- variableDeclaration: VariableDeclaration | undefined,
25
- scopeManager: Scope.ScopeManager,
26
- ): {
27
- variable?: Scope.Variable;
28
- bodyReferences: MemberExpression[];
29
- headersReferences: MemberExpression[];
30
- statusReferences: MemberExpression[];
31
- destructuringBodyVariable?: Scope.Variable | ObjectPattern;
32
- destructuringHeadersVariable?: Scope.Variable | ObjectPattern;
33
- destructuringHeadersReferences?: MemberExpression[] | undefined;
34
- } {
35
- const results: {
36
- variable?: Scope.Variable;
37
- bodyReferences: MemberExpression[];
38
- headersReferences: MemberExpression[];
39
- statusReferences: MemberExpression[];
40
- destructuringBodyVariable?: Scope.Variable | ObjectPattern;
41
- destructuringHeadersVariable?: Scope.Variable | ObjectPattern;
42
- destructuringHeadersReferences?: MemberExpression[] | undefined;
43
- } = {
44
- bodyReferences: [],
45
- headersReferences: [],
46
- statusReferences: [],
47
- };
48
- if (!variableDeclaration) {
49
- return results;
50
- }
51
-
52
- const responseVariables = scopeManager.getDeclaredVariables(variableDeclaration);
53
- for (const responseVariable of responseVariables) {
54
- const identifier = responseVariable.identifiers[0];
55
- assert.ok(identifier);
56
- const identifierParent = getParent(identifier);
57
- assert.ok(identifierParent);
58
- if (identifierParent.type === 'VariableDeclarator') {
59
- // e.g. const response = ...
60
- results.variable = responseVariable;
61
- const responseReferences = responseVariable.references.map((responseReference) =>
62
- getParent(responseReference.identifier),
63
- );
64
- // e.g. response.body
65
- results.bodyReferences = responseReferences.filter(
66
- (node): node is MemberExpression =>
67
- node?.type === 'MemberExpression' && node.property.type === 'Identifier' && node.property.name === 'body',
68
- );
69
- // e.g. response.headers / response.header / response.get()
70
- results.headersReferences = responseReferences.filter(
71
- (node): node is MemberExpression =>
72
- node?.type === 'MemberExpression' &&
73
- node.property.type === 'Identifier' &&
74
- (node.property.name === 'header' || node.property.name === 'headers' || node.property.name === 'get'),
75
- );
76
- // e.g. response.status / response.statusCode
77
- results.statusReferences = responseReferences.filter(
78
- (node): node is MemberExpression =>
79
- node?.type === 'MemberExpression' &&
80
- node.property.type === 'Identifier' &&
81
- (node.property.name === 'status' || node.property.name === 'statusCode'),
82
- );
83
- } else if (
84
- // body reference through destruction/renaming, e.g. "const { body } = ..."
85
- identifierParent.type === 'Property' &&
86
- identifierParent.key.type === 'Identifier' &&
87
- identifierParent.key.name === 'body'
88
- ) {
89
- results.destructuringBodyVariable = responseVariable;
90
- } else if (
91
- // header reference through destruction/renaming, e.g. "const { headers } = ..."
92
- identifierParent.type === 'Property' &&
93
- identifierParent.key.type === 'Identifier' &&
94
- identifierParent.key.name === 'headers'
95
- ) {
96
- results.destructuringHeadersVariable = responseVariable;
97
- results.destructuringHeadersReferences = responseVariable.references
98
- .map((reference) => reference.identifier)
99
- .map(getParent)
100
- .filter(
101
- (parent): parent is MemberExpression =>
102
- parent?.type === 'MemberExpression' &&
103
- parent.property.type === 'Identifier' &&
104
- parent.property.name !== 'get' &&
105
- getParent(parent)?.type !== 'CallExpression',
106
- );
107
- } else if (identifierParent.type === 'Property') {
108
- const parent = getParent(identifierParent);
109
- if (parent?.type === 'ObjectPattern') {
110
- // body reference through nested destruction, e.g. "const { body: {bodyPropertyName: renamedBodyPropertyName}, headers: {headerPropertyName: renamedHeaderPropertyName} } = ..."
111
- const parent2 = getParent(parent);
112
- if (parent2?.type === 'Property' && parent2.key.type === 'Identifier' && parent2.key.name === 'body') {
113
- results.destructuringBodyVariable = parent;
114
- }
115
- if (
116
- parent2?.type === 'Property' &&
117
- parent2.key.type === 'Identifier' &&
118
- (parent2.key.name === 'header' || parent2.key.name === 'headers')
119
- ) {
120
- results.destructuringHeadersVariable = parent;
121
- }
122
- }
123
- } else {
124
- log('+++++++ can not handle identifierParent', identifierParent);
125
- throw new Error(`Unknown response variable reference: ${responseVariable.name}`);
126
- }
127
- }
128
- return results;
129
- }
package/src/agent/url.ts DELETED
@@ -1,32 +0,0 @@
1
- // agent/url.ts
2
-
3
- // eslint-disable-next-line @typescript-eslint/no-inferrable-types
4
- const PLAIN_URL_REGEXP: RegExp = /^[`']\/\w+(?<serviceNamePart>-\w+)*\/v\d+\/(?<any>.|\r|\n)+[`']$/u;
5
- // eslint-disable-next-line @typescript-eslint/no-inferrable-types
6
- const TOKENIZED_URL_REGEXP: RegExp = /^`\$\{(?<serviceNamePart>[A-Z]+_)*BASE_PATH\}\/(?<any>.|\r|\n)+`$/u;
7
-
8
- export function isServiceApiCallUrl(url: string): boolean {
9
- return PLAIN_URL_REGEXP.test(url) || TOKENIZED_URL_REGEXP.test(url);
10
- }
11
-
12
- export function replaceEndpointUrlPrefixWithBasePath(url: string): string {
13
- return url.replace(
14
- /^(?<quotStart>[`'])\/(?<servicename>\w+(?<parts>-\w+)*)(?<path>\/v\d+\/)(?<endpoint>(?<any>.|\r|\n)+)(?<quotEnd>[`'])$/u,
15
- // eslint-disable-next-line no-template-curly-in-string
16
- '`${BASE_PATH}/$5`',
17
- );
18
- }
19
-
20
- export function replaceEndpointUrlPrefixWithDomain(url: string): string {
21
- return url.replace(
22
- /^(?<quotStart>[`'])\/(?<servicename>\w+(?<parts>-\w+)*)(?<path>\/v\d+\/(?<any>.|\r|\n)+(?<quotEnd>[`'])$)/u,
23
- '$1https://$2.checkdigit/$2$4',
24
- );
25
- }
26
-
27
- export function addBasePathUrlDomain(url: string): string {
28
- return url.replace(
29
- /^(?<quotStart>[`'])\/(?<servicename>\w+(?<parts>-\w+)*)(?<path>\/v\d+(?<quotEnd>[`'])$)/u,
30
- '$1https://$2.checkdigit/$2$4',
31
- );
32
- }
@@ -1,49 +0,0 @@
1
- // no-legacy-service-typing.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 = 'no-legacy-service-typing';
13
-
14
- const createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
15
-
16
- const DISALLOWED_SERVICE_TYPINGS: string[] | undefined = ['FullResponse', 'Endpoint'];
17
-
18
- const rule: ESLintUtils.RuleModule<'noLegacyServiceTyping', [typeof DISALLOWED_SERVICE_TYPINGS]> = createRule({
19
- name: ruleId,
20
- meta: {
21
- type: 'problem',
22
- docs: {
23
- description: 'Legacy service typings should not be used.',
24
- },
25
- messages: {
26
- noLegacyServiceTyping: 'Please remove the usage of legacy service typings.',
27
- },
28
- schema: [{ type: 'array', items: { type: 'string' } }],
29
- },
30
- defaultOptions: [DISALLOWED_SERVICE_TYPINGS],
31
- create(context) {
32
- return {
33
- TSTypeReference: (typeReference: TSESTree.TSTypeReference) => {
34
- if (
35
- typeReference.typeName.type === AST_NODE_TYPES.Identifier &&
36
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
37
- (context.options[0] ?? DISALLOWED_SERVICE_TYPINGS).includes(typeReference.typeName.name)
38
- ) {
39
- context.report({
40
- messageId: 'noLegacyServiceTyping',
41
- node: typeReference,
42
- });
43
- }
44
- },
45
- };
46
- },
47
- });
48
-
49
- export default rule;