@checkdigit/eslint-plugin 7.3.0-PR.75-1f63 → 7.3.0-PR.93-561f

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 (65) hide show
  1. package/dist-mjs/index.mjs +3 -122
  2. package/dist-mjs/require-resolve-full-response.mjs +1 -1
  3. package/package.json +1 -1
  4. package/src/index.ts +0 -119
  5. package/src/require-resolve-full-response.ts +1 -3
  6. package/dist-mjs/agent/add-assert-import.mjs +0 -58
  7. package/dist-mjs/agent/add-base-path-const.mjs +0 -65
  8. package/dist-mjs/agent/add-base-path-import.mjs +0 -60
  9. package/dist-mjs/agent/add-url-domain.mjs +0 -61
  10. package/dist-mjs/agent/agent-test-wiring.mjs +0 -196
  11. package/dist-mjs/agent/fetch-response-body-json.mjs +0 -134
  12. package/dist-mjs/agent/fetch-response-header-getter.mjs +0 -117
  13. package/dist-mjs/agent/fetch-then.mjs +0 -267
  14. package/dist-mjs/agent/fetch.mjs +0 -34
  15. package/dist-mjs/agent/file.mjs +0 -43
  16. package/dist-mjs/agent/fix-function-call-arguments.mjs +0 -150
  17. package/dist-mjs/agent/no-fixture.mjs +0 -336
  18. package/dist-mjs/agent/no-mapped-response.mjs +0 -75
  19. package/dist-mjs/agent/no-service-wrapper.mjs +0 -185
  20. package/dist-mjs/agent/no-status-code.mjs +0 -59
  21. package/dist-mjs/agent/no-unused-function-argument.mjs +0 -79
  22. package/dist-mjs/agent/no-unused-imports.mjs +0 -81
  23. package/dist-mjs/agent/no-unused-service-variable.mjs +0 -74
  24. package/dist-mjs/agent/response-reference.mjs +0 -67
  25. package/dist-mjs/agent/url.mjs +0 -32
  26. package/dist-types/agent/add-assert-import.d.ts +0 -4
  27. package/dist-types/agent/add-base-path-const.d.ts +0 -4
  28. package/dist-types/agent/add-base-path-import.d.ts +0 -4
  29. package/dist-types/agent/add-url-domain.d.ts +0 -4
  30. package/dist-types/agent/agent-test-wiring.d.ts +0 -4
  31. package/dist-types/agent/fetch-response-body-json.d.ts +0 -4
  32. package/dist-types/agent/fetch-response-header-getter.d.ts +0 -4
  33. package/dist-types/agent/fetch-then.d.ts +0 -4
  34. package/dist-types/agent/fetch.d.ts +0 -4
  35. package/dist-types/agent/file.d.ts +0 -7
  36. package/dist-types/agent/fix-function-call-arguments.d.ts +0 -9
  37. package/dist-types/agent/no-fixture.d.ts +0 -4
  38. package/dist-types/agent/no-mapped-response.d.ts +0 -4
  39. package/dist-types/agent/no-service-wrapper.d.ts +0 -4
  40. package/dist-types/agent/no-status-code.d.ts +0 -4
  41. package/dist-types/agent/no-unused-function-argument.d.ts +0 -4
  42. package/dist-types/agent/no-unused-imports.d.ts +0 -4
  43. package/dist-types/agent/no-unused-service-variable.d.ts +0 -4
  44. package/dist-types/agent/response-reference.d.ts +0 -16
  45. package/dist-types/agent/url.d.ts +0 -4
  46. package/src/agent/add-assert-import.ts +0 -74
  47. package/src/agent/add-base-path-const.ts +0 -81
  48. package/src/agent/add-base-path-import.ts +0 -69
  49. package/src/agent/add-url-domain.ts +0 -76
  50. package/src/agent/agent-test-wiring.ts +0 -246
  51. package/src/agent/fetch-response-body-json.ts +0 -178
  52. package/src/agent/fetch-response-header-getter.ts +0 -148
  53. package/src/agent/fetch-then.ts +0 -355
  54. package/src/agent/fetch.ts +0 -53
  55. package/src/agent/file.ts +0 -42
  56. package/src/agent/fix-function-call-arguments.ts +0 -188
  57. package/src/agent/no-fixture.ts +0 -480
  58. package/src/agent/no-mapped-response.ts +0 -84
  59. package/src/agent/no-service-wrapper.ts +0 -241
  60. package/src/agent/no-status-code.ts +0 -72
  61. package/src/agent/no-unused-function-argument.ts +0 -98
  62. package/src/agent/no-unused-imports.ts +0 -103
  63. package/src/agent/no-unused-service-variable.ts +0 -93
  64. package/src/agent/response-reference.ts +0 -122
  65. package/src/agent/url.ts +0 -32
@@ -1,122 +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;
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;
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
- // body reference through nested destruction, e.g. "const { body: {bodyPropertyName: renamedBodyPropertyName}, headers: {headerPropertyName: renamedHeaderPropertyName} } = ..."
109
- const parent = getParent(identifierParent);
110
- if (parent?.type === 'ObjectPattern') {
111
- const parent2 = getParent(parent);
112
- if (parent2?.type === 'Property' && parent2.key.type === 'Identifier' && parent2.key.name === 'body') {
113
- results.destructuringBodyVariable = parent;
114
- }
115
- }
116
- } else {
117
- log('+++++++ can not handle identifierParent', identifierParent);
118
- throw new Error(`Unknown response variable reference: ${responseVariable.name}`);
119
- }
120
- }
121
- return results;
122
- }
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
- }