@checkdigit/eslint-plugin 7.5.0-PR.75-0252 → 7.5.0-PR.93-b62d

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 (71) hide show
  1. package/dist-mjs/index.mjs +4 -146
  2. package/dist-mjs/require-fixed-services-import.mjs +1 -1
  3. package/dist-mjs/require-resolve-full-response.mjs +1 -1
  4. package/dist-types/index.d.ts +1 -1
  5. package/package.json +1 -1
  6. package/src/index.ts +2 -144
  7. package/src/require-fixed-services-import.ts +1 -1
  8. package/src/require-resolve-full-response.ts +0 -2
  9. package/dist-mjs/agent/add-assert-import.mjs +0 -58
  10. package/dist-mjs/agent/add-base-path-const.mjs +0 -65
  11. package/dist-mjs/agent/add-base-path-import.mjs +0 -60
  12. package/dist-mjs/agent/add-url-domain.mjs +0 -61
  13. package/dist-mjs/agent/agent-test-wiring.mjs +0 -221
  14. package/dist-mjs/agent/fetch-response-body-json.mjs +0 -146
  15. package/dist-mjs/agent/fetch-response-header-getter.mjs +0 -117
  16. package/dist-mjs/agent/fetch-response-status.mjs +0 -66
  17. package/dist-mjs/agent/fetch-then.mjs +0 -269
  18. package/dist-mjs/agent/fetch.mjs +0 -38
  19. package/dist-mjs/agent/file.mjs +0 -43
  20. package/dist-mjs/agent/fix-function-call-arguments.mjs +0 -153
  21. package/dist-mjs/agent/no-fixture.mjs +0 -361
  22. package/dist-mjs/agent/no-mapped-response.mjs +0 -75
  23. package/dist-mjs/agent/no-service-wrapper.mjs +0 -185
  24. package/dist-mjs/agent/no-status-code.mjs +0 -59
  25. package/dist-mjs/agent/no-unused-function-argument.mjs +0 -79
  26. package/dist-mjs/agent/no-unused-imports.mjs +0 -81
  27. package/dist-mjs/agent/no-unused-service-variable.mjs +0 -74
  28. package/dist-mjs/agent/response-reference.mjs +0 -70
  29. package/dist-mjs/agent/url.mjs +0 -32
  30. package/dist-types/agent/add-assert-import.d.ts +0 -4
  31. package/dist-types/agent/add-base-path-const.d.ts +0 -4
  32. package/dist-types/agent/add-base-path-import.d.ts +0 -4
  33. package/dist-types/agent/add-url-domain.d.ts +0 -4
  34. package/dist-types/agent/agent-test-wiring.d.ts +0 -4
  35. package/dist-types/agent/fetch-response-body-json.d.ts +0 -4
  36. package/dist-types/agent/fetch-response-header-getter.d.ts +0 -4
  37. package/dist-types/agent/fetch-response-status.d.ts +0 -4
  38. package/dist-types/agent/fetch-then.d.ts +0 -4
  39. package/dist-types/agent/fetch.d.ts +0 -5
  40. package/dist-types/agent/file.d.ts +0 -7
  41. package/dist-types/agent/fix-function-call-arguments.d.ts +0 -9
  42. package/dist-types/agent/no-fixture.d.ts +0 -4
  43. package/dist-types/agent/no-mapped-response.d.ts +0 -4
  44. package/dist-types/agent/no-service-wrapper.d.ts +0 -4
  45. package/dist-types/agent/no-status-code.d.ts +0 -4
  46. package/dist-types/agent/no-unused-function-argument.d.ts +0 -4
  47. package/dist-types/agent/no-unused-imports.d.ts +0 -4
  48. package/dist-types/agent/no-unused-service-variable.d.ts +0 -4
  49. package/dist-types/agent/response-reference.d.ts +0 -16
  50. package/dist-types/agent/url.d.ts +0 -4
  51. package/src/agent/add-assert-import.ts +0 -74
  52. package/src/agent/add-base-path-const.ts +0 -81
  53. package/src/agent/add-base-path-import.ts +0 -69
  54. package/src/agent/add-url-domain.ts +0 -76
  55. package/src/agent/agent-test-wiring.ts +0 -273
  56. package/src/agent/fetch-response-body-json.ts +0 -197
  57. package/src/agent/fetch-response-header-getter.ts +0 -148
  58. package/src/agent/fetch-response-status.ts +0 -87
  59. package/src/agent/fetch-then.ts +0 -357
  60. package/src/agent/fetch.ts +0 -57
  61. package/src/agent/file.ts +0 -42
  62. package/src/agent/fix-function-call-arguments.ts +0 -200
  63. package/src/agent/no-fixture.ts +0 -521
  64. package/src/agent/no-mapped-response.ts +0 -84
  65. package/src/agent/no-service-wrapper.ts +0 -241
  66. package/src/agent/no-status-code.ts +0 -72
  67. package/src/agent/no-unused-function-argument.ts +0 -98
  68. package/src/agent/no-unused-imports.ts +0 -103
  69. package/src/agent/no-unused-service-variable.ts +0 -93
  70. package/src/agent/response-reference.ts +0 -129
  71. package/src/agent/url.ts +0 -32
@@ -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
- }