@checkdigit/eslint-plugin 7.6.0-PR.75-4751 → 7.6.0-PR.97-b19c

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 (77) hide show
  1. package/dist-mjs/index.mjs +8 -156
  2. package/dist-mjs/no-status-code-assert.mjs +63 -0
  3. package/dist-mjs/require-resolve-full-response.mjs +5 -5
  4. package/dist-types/no-status-code-assert.d.ts +5 -0
  5. package/package.json +1 -1
  6. package/src/index.ts +4 -152
  7. package/src/no-status-code-assert.ts +85 -0
  8. package/src/require-resolve-full-response.ts +4 -4
  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 -76
  17. package/dist-mjs/agent/fetch-then.mjs +0 -205
  18. package/dist-mjs/agent/fetch.mjs +0 -48
  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 -383
  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-supertest.mjs +0 -332
  26. package/dist-mjs/agent/no-unused-function-argument.mjs +0 -79
  27. package/dist-mjs/agent/no-unused-imports.mjs +0 -81
  28. package/dist-mjs/agent/no-unused-service-variable.mjs +0 -74
  29. package/dist-mjs/agent/response-reference.mjs +0 -75
  30. package/dist-mjs/agent/supertest-then.mjs +0 -170
  31. package/dist-mjs/agent/url.mjs +0 -32
  32. package/dist-types/agent/add-assert-import.d.ts +0 -4
  33. package/dist-types/agent/add-base-path-const.d.ts +0 -4
  34. package/dist-types/agent/add-base-path-import.d.ts +0 -4
  35. package/dist-types/agent/add-url-domain.d.ts +0 -4
  36. package/dist-types/agent/agent-test-wiring.d.ts +0 -4
  37. package/dist-types/agent/fetch-response-body-json.d.ts +0 -4
  38. package/dist-types/agent/fetch-response-header-getter.d.ts +0 -4
  39. package/dist-types/agent/fetch-response-status.d.ts +0 -4
  40. package/dist-types/agent/fetch-then.d.ts +0 -4
  41. package/dist-types/agent/fetch.d.ts +0 -8
  42. package/dist-types/agent/file.d.ts +0 -7
  43. package/dist-types/agent/fix-function-call-arguments.d.ts +0 -9
  44. package/dist-types/agent/no-fixture.d.ts +0 -4
  45. package/dist-types/agent/no-mapped-response.d.ts +0 -4
  46. package/dist-types/agent/no-service-wrapper.d.ts +0 -4
  47. package/dist-types/agent/no-status-code.d.ts +0 -4
  48. package/dist-types/agent/no-supertest.d.ts +0 -4
  49. package/dist-types/agent/no-unused-function-argument.d.ts +0 -4
  50. package/dist-types/agent/no-unused-imports.d.ts +0 -4
  51. package/dist-types/agent/no-unused-service-variable.d.ts +0 -4
  52. package/dist-types/agent/response-reference.d.ts +0 -16
  53. package/dist-types/agent/supertest-then.d.ts +0 -4
  54. package/dist-types/agent/url.d.ts +0 -4
  55. package/src/agent/add-assert-import.ts +0 -74
  56. package/src/agent/add-base-path-const.ts +0 -81
  57. package/src/agent/add-base-path-import.ts +0 -69
  58. package/src/agent/add-url-domain.ts +0 -76
  59. package/src/agent/agent-test-wiring.ts +0 -273
  60. package/src/agent/fetch-response-body-json.ts +0 -194
  61. package/src/agent/fetch-response-header-getter.ts +0 -148
  62. package/src/agent/fetch-response-status.ts +0 -100
  63. package/src/agent/fetch-then.ts +0 -358
  64. package/src/agent/fetch.ts +0 -69
  65. package/src/agent/file.ts +0 -42
  66. package/src/agent/fix-function-call-arguments.ts +0 -200
  67. package/src/agent/no-fixture.ts +0 -581
  68. package/src/agent/no-mapped-response.ts +0 -84
  69. package/src/agent/no-service-wrapper.ts +0 -241
  70. package/src/agent/no-status-code.ts +0 -69
  71. package/src/agent/no-supertest.ts +0 -517
  72. package/src/agent/no-unused-function-argument.ts +0 -98
  73. package/src/agent/no-unused-imports.ts +0 -103
  74. package/src/agent/no-unused-service-variable.ts +0 -93
  75. package/src/agent/response-reference.ts +0 -153
  76. package/src/agent/supertest-then.ts +0 -230
  77. package/src/agent/url.ts +0 -32
@@ -1,75 +0,0 @@
1
- // src/agent/response-reference.ts
2
- import { strict as assert } from "node:assert";
3
- import debug from "debug";
4
- import { AST_NODE_TYPES } from "@typescript-eslint/utils";
5
- import { getParent } from "../library/ts-tree.mjs";
6
- var log = debug("eslint-plugin:response-reference");
7
- function analyzeResponseReferences(variableDeclaration, scopeManager) {
8
- const results = {
9
- bodyReferences: [],
10
- // headersReferences: [],
11
- statusReferences: []
12
- };
13
- if (!variableDeclaration) {
14
- return results;
15
- }
16
- const responseVariables = scopeManager.getDeclaredVariables(variableDeclaration);
17
- for (const responseVariable of responseVariables) {
18
- const identifier = responseVariable.identifiers[0];
19
- assert.ok(identifier);
20
- const identifierParent = getParent(identifier);
21
- assert.ok(identifierParent);
22
- if (identifierParent.type === AST_NODE_TYPES.VariableDeclarator) {
23
- results.variable = responseVariable;
24
- const responseReferences = responseVariable.references.map(
25
- (responseReference) => getParent(responseReference.identifier)
26
- );
27
- results.bodyReferences = responseReferences.filter(
28
- (node) => node?.type === AST_NODE_TYPES.MemberExpression && node.property.type === AST_NODE_TYPES.Identifier && node.property.name === "body"
29
- );
30
- results.statusReferences = responseReferences.filter(
31
- (node) => node?.type === AST_NODE_TYPES.MemberExpression && node.property.type === AST_NODE_TYPES.Identifier && (node.property.name === "status" || node.property.name === "statusCode")
32
- );
33
- } else if (
34
- // body reference through destruction/renaming, e.g. "const { body } = ..."
35
- identifierParent.type === AST_NODE_TYPES.Property && identifierParent.key.type === AST_NODE_TYPES.Identifier && identifierParent.key.name === "body"
36
- ) {
37
- results.destructuringBodyVariable = responseVariable;
38
- } else if (
39
- // body reference through destruction/renaming, e.g. "const { body } = ..."
40
- identifierParent.type === AST_NODE_TYPES.Property && identifierParent.key.type === AST_NODE_TYPES.Identifier && (identifierParent.key.name === "status" || identifierParent.key.name === "statusCode")
41
- ) {
42
- results.destructuringStatusVariable = responseVariable;
43
- } else if (
44
- // header reference through destruction/renaming, e.g. "const { headers } = ..."
45
- identifierParent.type === AST_NODE_TYPES.Property && identifierParent.key.type === AST_NODE_TYPES.Identifier && identifierParent.key.name === "headers"
46
- ) {
47
- results.destructuringHeadersVariable = responseVariable;
48
- results.destructuringHeadersReferences = responseVariable.references.map((reference) => reference.identifier).map(getParent).filter(
49
- (parent) => parent?.type === AST_NODE_TYPES.MemberExpression && parent.property.type === AST_NODE_TYPES.Identifier && parent.property.name !== "get" && getParent(parent)?.type !== AST_NODE_TYPES.CallExpression
50
- );
51
- } else if (identifierParent.type === AST_NODE_TYPES.Property) {
52
- const parent = getParent(identifierParent);
53
- if (parent?.type === AST_NODE_TYPES.ObjectPattern) {
54
- const parent2 = getParent(parent);
55
- if (parent2?.type === AST_NODE_TYPES.Property && parent2.key.type === AST_NODE_TYPES.Identifier && parent2.key.name === "body") {
56
- results.destructuringBodyVariable = parent;
57
- }
58
- if (parent2?.type === AST_NODE_TYPES.Property && parent2.key.type === AST_NODE_TYPES.Identifier && (parent2.key.name === "status" || parent2.key.name === "statusCode")) {
59
- results.destructuringStatusVariable = parent;
60
- }
61
- if (parent2?.type === AST_NODE_TYPES.Property && parent2.key.type === AST_NODE_TYPES.Identifier && (parent2.key.name === "header" || parent2.key.name === "headers")) {
62
- results.destructuringHeadersVariable = parent;
63
- }
64
- }
65
- } else {
66
- log("+++++++ can not handle identifierParent", identifierParent);
67
- throw new Error(`Unknown response variable reference: ${responseVariable.name}`);
68
- }
69
- }
70
- return results;
71
- }
72
- export {
73
- analyzeResponseReferences
74
- };
75
- //# s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FVBQUksUUFBUSxTQUFTLGVBQWUsZUFBZTtBQUVqRCxjQUFNLFVBQVUsVUFBVSxNQUFNO0FBQ2hDLFlBQ0UsU0FBUyxTQUFTLGVBQWUsWUFDakMsUUFBUSxJQUFJLFNBQVMsZUFBZSxjQUNwQyxRQUFRLElBQUksU0FBUyxRQUNyQjtBQUNBLGtCQUFRLDRCQUE0QjtBQUFBLFFBQ3RDO0FBQ0EsWUFDRSxTQUFTLFNBQVMsZUFBZSxZQUNqQyxRQUFRLElBQUksU0FBUyxlQUFlLGVBQ25DLFFBQVEsSUFBSSxTQUFTLFlBQVksUUFBUSxJQUFJLFNBQVMsZUFDdkQ7QUFDQSxrQkFBUSw4QkFBOEI7QUFBQSxRQUN4QztBQUNBLFlBQ0UsU0FBUyxTQUFTLGVBQWUsWUFDakMsUUFBUSxJQUFJLFNBQVMsZUFBZSxlQUNuQyxRQUFRLElBQUksU0FBUyxZQUFZLFFBQVEsSUFBSSxTQUFTLFlBQ3ZEO0FBQ0Esa0JBQVEsK0JBQStCO0FBQUEsUUFDekM7QUFBQSxNQUNGO0FBQUEsSUFDRixPQUFPO0FBQ0wsVUFBSSwyQ0FBMkMsZ0JBQWdCO0FBQy9ELFlBQU0sSUFBSSxNQUFNLHdDQUF3QyxpQkFBaUIsSUFBSSxFQUFFO0FBQUEsSUFDakY7QUFBQSxFQUNGO0FBQ0EsU0FBTztBQUNUOyIsCiAgIm5hbWVzIjogW10KfQo=
@@ -1,170 +0,0 @@
1
- // src/agent/supertest-then.ts
2
- import { strict as assert } from "node:assert";
3
- import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
4
- import { getEnclosingFunction, getParent, isUsedInArrayOrAsArgument } from "../library/ts-tree.mjs";
5
- import getDocumentationUrl from "../get-documentation-url.mjs";
6
- import { getIndentation } from "../library/format.mjs";
7
- var ruleId = "supertest-then";
8
- function analyzeFixtureCall(call, results, sourceCode) {
9
- const parent = getParent(call);
10
- if (!parent) {
11
- return;
12
- }
13
- let nextCall;
14
- if (parent.type !== AST_NODE_TYPES.MemberExpression) {
15
- results.fixtureNode = call;
16
- return;
17
- }
18
- if (parent.property.type === AST_NODE_TYPES.Identifier) {
19
- if (parent.property.name === "expect") {
20
- const assertionCall = getParent(parent);
21
- assert.ok(assertionCall && assertionCall.type === AST_NODE_TYPES.CallExpression);
22
- results.assertions = [...results.assertions ?? [], assertionCall.arguments];
23
- nextCall = assertionCall;
24
- }
25
- } else {
26
- throw new Error(`Unexpected TSESTree.Expression in fixture/supertest call ${sourceCode.getText(parent)}.`);
27
- }
28
- if (nextCall) {
29
- analyzeFixtureCall(nextCall, results, sourceCode);
30
- }
31
- }
32
- function createResponseAssertions(fixtureCallInformation, sourceCode, responseVariableName) {
33
- let statusAssertion;
34
- const nonStatusAssertions = [];
35
- for (const expectArguments of fixtureCallInformation.assertions ?? []) {
36
- if (expectArguments.length === 1) {
37
- const [assertionArgument] = expectArguments;
38
- assert.ok(assertionArgument);
39
- if (assertionArgument.type === AST_NODE_TYPES.MemberExpression && assertionArgument.object.type === AST_NODE_TYPES.Identifier && assertionArgument.object.name === "StatusCodes" || assertionArgument.type === AST_NODE_TYPES.Literal || sourceCode.getText(assertionArgument).includes("StatusCodes.")) {
40
- statusAssertion = `assert.equal(${responseVariableName}.status, ${sourceCode.getText(assertionArgument)})`;
41
- } else if (assertionArgument.type === AST_NODE_TYPES.ArrowFunctionExpression) {
42
- let functionBody = sourceCode.getText(assertionArgument.body);
43
- const [originalResponseArgument] = assertionArgument.params;
44
- assert.ok(originalResponseArgument?.type === AST_NODE_TYPES.Identifier);
45
- const originalResponseArgumentName = originalResponseArgument.name;
46
- if (originalResponseArgumentName !== responseVariableName) {
47
- functionBody = functionBody.replace(
48
- new RegExp(`\\b${originalResponseArgumentName}\\b`, "ug"),
49
- responseVariableName
50
- );
51
- }
52
- nonStatusAssertions.push(`assert.doesNotThrow(()=>${functionBody})`);
53
- } else if (assertionArgument.type === AST_NODE_TYPES.Identifier) {
54
- nonStatusAssertions.push(
55
- `assert.doesNotThrow(()=>${sourceCode.getText(assertionArgument)}(${responseVariableName}))`
56
- );
57
- } else if (assertionArgument.type === AST_NODE_TYPES.ObjectExpression || assertionArgument.type === AST_NODE_TYPES.CallExpression) {
58
- nonStatusAssertions.push(
59
- `assert.deepEqual(await ${responseVariableName}.json(), ${sourceCode.getText(assertionArgument)})`
60
- );
61
- } else {
62
- throw new Error(`Unexpected Supertest assertion argument: ".expect(${sourceCode.getText(assertionArgument)})`);
63
- }
64
- } else if (expectArguments.length === 2) {
65
- const [headerName, headerValue] = expectArguments;
66
- assert.ok(headerName && headerValue);
67
- const headersReference = `${responseVariableName}.headers`;
68
- if (headerValue.type === AST_NODE_TYPES.Literal && headerValue.value instanceof RegExp) {
69
- nonStatusAssertions.push(
70
- `assert.ok(${headersReference}.get(${sourceCode.getText(headerName)}).match(${sourceCode.getText(headerValue)}))`
71
- );
72
- } else {
73
- nonStatusAssertions.push(
74
- `assert.equal(${headersReference}.get(${sourceCode.getText(headerName)}), ${sourceCode.getText(headerValue)})`
75
- );
76
- }
77
- }
78
- }
79
- return {
80
- statusAssertion,
81
- nonStatusAssertions
82
- };
83
- }
84
- var createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
85
- var rule = createRule({
86
- name: ruleId,
87
- meta: {
88
- type: "suggestion",
89
- docs: {
90
- description: "Prefer native fetch API over customized fixture API.",
91
- url: getDocumentationUrl(ruleId)
92
- },
93
- messages: {
94
- preferNativeFetch: "Prefer native fetch API over customized fixture API.",
95
- // shouldUseHeaderGetter: 'Getter should be used to access response headers.',
96
- unknownError: 'Unknown error occurred in file "{{fileName}}": {{ error }}.'
97
- },
98
- fixable: "code",
99
- schema: []
100
- },
101
- defaultOptions: [],
102
- create(context) {
103
- const sourceCode = context.sourceCode;
104
- const scopeManager = sourceCode.scopeManager;
105
- assert.ok(scopeManager);
106
- return {
107
- 'CallExpression[callee.property.name="expect"]': (supertestCall) => {
108
- try {
109
- assert.ok(supertestCall.callee.type === AST_NODE_TYPES.MemberExpression);
110
- if (supertestCall.callee.object.type !== AST_NODE_TYPES.CallExpression || supertestCall.callee.object.callee.type === AST_NODE_TYPES.MemberExpression && supertestCall.callee.object.callee.property.type === AST_NODE_TYPES.Identifier && supertestCall.callee.object.callee.property.name === "expect") {
111
- return;
112
- }
113
- if (!(isUsedInArrayOrAsArgument(supertestCall) || getEnclosingFunction(supertestCall)?.async === false)) {
114
- return;
115
- }
116
- const fixtureFunction = supertestCall.callee.object;
117
- const indentation = getIndentation(supertestCall, sourceCode);
118
- const [urlArgumentNode] = supertestCall.arguments;
119
- assert.ok(urlArgumentNode !== void 0);
120
- const fixtureCallInformation = {};
121
- analyzeFixtureCall(fixtureFunction, fixtureCallInformation, sourceCode);
122
- const responseVariableNameToUse = "res";
123
- const { statusAssertion, nonStatusAssertions } = createResponseAssertions(
124
- fixtureCallInformation,
125
- sourceCode,
126
- responseVariableNameToUse
127
- );
128
- const disableLintComment = "// eslint-disable-next-line @checkdigit/no-promise-instance-method";
129
- const fetchCallText = sourceCode.getText(fixtureFunction);
130
- const appendingAssignmentAndAssertionText = [
131
- ...statusAssertion !== void 0 ? [statusAssertion] : [],
132
- ...nonStatusAssertions
133
- ].join(`;
134
- ${indentation}`);
135
- const replacementText = fixtureCallInformation.assertions ? [
136
- disableLintComment,
137
- `${fetchCallText}.then((${responseVariableNameToUse}) => {`,
138
- appendingAssignmentAndAssertionText === "" ? "" : ` ${appendingAssignmentAndAssertionText};`,
139
- ` return ${responseVariableNameToUse};`,
140
- `})`
141
- ].join(`
142
- ${indentation}`) : fetchCallText;
143
- context.report({
144
- node: supertestCall,
145
- messageId: "preferNativeFetch",
146
- fix(fixer) {
147
- return fixer.replaceText(fixtureCallInformation.fixtureNode, replacementText);
148
- }
149
- });
150
- } catch (error) {
151
- console.error(`Failed to apply ${ruleId} rule for file "${context.filename}":`, error);
152
- context.report({
153
- node: supertestCall,
154
- messageId: "unknownError",
155
- data: {
156
- fileName: context.filename,
157
- error: error instanceof Error ? error.toString() : JSON.stringify(error)
158
- }
159
- });
160
- }
161
- }
162
- };
163
- }
164
- });
165
- var supertest_then_default = rule;
166
- export {
167
- supertest_then_default as default,
168
- ruleId
169
- };
170
- //# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vLi4vc3JjL2FnZW50L3N1cGVydGVzdC10aGVuLnRzIl0sCiAgIm1hcHBpbmdzIjogIjtBQVFBLFNBQVMsVUFBVSxjQUFjO0FBRWpDLFNBQVMsZ0JBQWdCLG1CQUE2QjtBQUd0RCxTQUFTLHNCQUFzQixXQUFXLGlDQUFpQztBQUMzRSxPQUFPLHlCQUF5QjtBQUNoQyxTQUFTLHNCQUFzQjtBQUV4QixJQUFNLFNBQVM7QUFVdEIsU0FBUyxtQkFBbUIsTUFBK0IsU0FBaUMsWUFBd0I7QUFDbEgsUUFBTSxTQUFTLFVBQVUsSUFBSTtBQUM3QixNQUFJLENBQUMsUUFBUTtBQUNYO0FBQUEsRUFDRjtBQUVBLE1BQUk7QUFDSixNQUFJLE9BQU8sU0FBUyxlQUFlLGtCQUFrQjtBQUNuRCxZQUFRLGNBQWM7QUFDdEI7QUFBQSxFQUNGO0FBRUEsTUFBSSxPQUFPLFNBQVMsU0FBUyxlQUFlLFlBQVk7QUFDdEQsUUFBSSxPQUFPLFNBQVMsU0FBUyxVQUFVO0FBRXJDLFlBQU0sZ0JBQWdCLFVBQVUsTUFBTTtBQUN0QyxhQUFPLEdBQUcsaUJBQWlCLGNBQWMsU0FBUyxlQUFlLGNBQWM7QUFDL0UsY0FBUSxhQUFhLENBQUMsR0FBSSxRQUFRLGNBQWMsQ0FBQyxHQUFJLGNBQWMsU0FBa0M7QUFDckcsaUJBQVc7QUFBQSxJQUNiO0FBQUEsRUFDRixPQUFPO0FBQ0wsVUFBTSxJQUFJLE1BQU0sNERBQTRELFdBQVcsUUFBUSxNQUFNLENBQUMsR0FBRztBQUFBLEVBQzNHO0FBQ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UFtQixNQUFNLG1CQUFtQixRQUFRLFFBQVEsTUFBTSxLQUFLO0FBQ3JGLGtCQUFRLE9BQU87QUFBQSxZQUNiLE1BQU07QUFBQSxZQUNOLFdBQVc7QUFBQSxZQUNYLE1BQU07QUFBQSxjQUNKLFVBQVUsUUFBUTtBQUFBLGNBQ2xCLE9BQU8saUJBQWlCLFFBQVEsTUFBTSxTQUFTLElBQUksS0FBSyxVQUFVLEtBQUs7QUFBQSxZQUN6RTtBQUFBLFVBQ0YsQ0FBQztBQUFBLFFBQ0g7QUFBQSxNQUNGO0FBQUEsSUFDRjtBQUFBLEVBQ0Y7QUFDRixDQUFDO0FBRUQsSUFBTyx5QkFBUTsiLAogICJuYW1lcyI6IFtdCn0K
@@ -1,32 +0,0 @@
1
- // src/agent/url.ts
2
- var PLAIN_URL_REGEXP = /^[`']\/\w+(?<serviceNamePart>-\w+)*\/v\d+\/(?<any>.|\r|\n)+[`']$/u;
3
- var TOKENIZED_URL_REGEXP = /^`\$\{(?<serviceNamePart>[A-Z]+_)*BASE_PATH\}\/(?<any>.|\r|\n)+`$/u;
4
- function isServiceApiCallUrl(url) {
5
- return PLAIN_URL_REGEXP.test(url) || TOKENIZED_URL_REGEXP.test(url);
6
- }
7
- function replaceEndpointUrlPrefixWithBasePath(url) {
8
- return url.replace(
9
- /^(?<quotStart>[`'])\/(?<servicename>\w+(?<parts>-\w+)*)(?<path>\/v\d+\/)(?<endpoint>(?<any>.|\r|\n)+)(?<quotEnd>[`'])$/u,
10
- // eslint-disable-next-line no-template-curly-in-string
11
- "`${BASE_PATH}/$5`"
12
- );
13
- }
14
- function replaceEndpointUrlPrefixWithDomain(url) {
15
- return url.replace(
16
- /^(?<quotStart>[`'])\/(?<servicename>\w+(?<parts>-\w+)*)(?<path>\/v\d+\/(?<any>.|\r|\n)+(?<quotEnd>[`'])$)/u,
17
- "$1https://$2.checkdigit/$2$4"
18
- );
19
- }
20
- function addBasePathUrlDomain(url) {
21
- return url.replace(
22
- /^(?<quotStart>[`'])\/(?<servicename>\w+(?<parts>-\w+)*)(?<path>\/v\d+(?<quotEnd>[`'])$)/u,
23
- "$1https://$2.checkdigit/$2$4"
24
- );
25
- }
26
- export {
27
- addBasePathUrlDomain,
28
- isServiceApiCallUrl,
29
- replaceEndpointUrlPrefixWithBasePath,
30
- replaceEndpointUrlPrefixWithDomain
31
- };
32
- //# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vLi4vc3JjL2FnZW50L3VybC50cyJdLAogICJtYXBwaW5ncyI6ICI7QUFHQSxJQUFNLG1CQUEyQjtBQUVqQyxJQUFNLHVCQUErQjtBQUU5QixTQUFTLG9CQUFvQixLQUFzQjtBQUN4RCxTQUFPLGlCQUFpQixLQUFLLEdBQUcsS0FBSyxxQkFBcUIsS0FBSyxHQUFHO0FBQ3BFO0FBRU8sU0FBUyxxQ0FBcUMsS0FBcUI7QUFDeEUsU0FBTyxJQUFJO0FBQUEsSUFDVDtBQUFBO0FBQUEsSUFFQTtBQUFBLEVBQ0Y7QUFDRjtBQUVPLFNBQVMsbUNBQW1DLEtBQXFCO0FBQ3RFLFNBQU8sSUFBSTtBQUFBLElBQ1Q7QUFBQSxJQUNBO0FBQUEsRUFDRjtBQUNGO0FBRU8sU0FBUyxxQkFBcUIsS0FBcUI7QUFDeEQsU0FBTyxJQUFJO0FBQUEsSUFDVDtBQUFBLElBQ0E7QUFBQSxFQUNGO0FBQ0Y7IiwKICAibmFtZXMiOiBbXQp9Cg==
@@ -1,4 +0,0 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- export declare const ruleId = "add-assert-import";
3
- declare const rule: ESLintUtils.RuleModule<'addAssertImport'>;
4
- export default rule;
@@ -1,4 +0,0 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- export declare const ruleId = "add-base-path-const";
3
- declare const rule: ESLintUtils.RuleModule<'addBasePathConst'>;
4
- export default rule;
@@ -1,4 +0,0 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- export declare const ruleId = "add-base-path-import";
3
- declare const rule: ESLintUtils.RuleModule<'addBasePathImport'>;
4
- export default rule;
@@ -1,4 +0,0 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- export declare const ruleId = "add-url-domain";
3
- declare const rule: ESLintUtils.RuleModule<'addDomain' | 'unknownError'>;
4
- export default rule;
@@ -1,4 +0,0 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- export declare const ruleId = "agent-test-wiring";
3
- declare const rule: ESLintUtils.RuleModule<'updateTestWiring' | 'unknownError'>;
4
- export default rule;
@@ -1,4 +0,0 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- export declare const ruleId = "fetch-response-body-json";
3
- declare const rule: ESLintUtils.RuleModule<'unknownError' | 'replaceBodyWithJson' | 'refactorNeeded'>;
4
- export default rule;
@@ -1,4 +0,0 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- export declare const ruleId = "fetch-response-header-getter-ts";
3
- declare const rule: ESLintUtils.RuleModule<'unknownError' | 'useGetter'>;
4
- export default rule;
@@ -1,4 +0,0 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- export declare const ruleId = "fetch-response-status";
3
- declare const rule: ESLintUtils.RuleModule<'unknownError' | 'renameStatusCodeProperty'>;
4
- export default rule;
@@ -1,4 +0,0 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- export declare const ruleId = "fetch-then";
3
- declare const rule: ESLintUtils.RuleModule<'unknownError' | 'preferNativeFetch'>;
4
- export default rule;
@@ -1,8 +0,0 @@
1
- import { TSESTree } from '@typescript-eslint/utils';
2
- import ts from 'typescript';
3
- export declare function getResponseBodyRetrievalText(responseVariableName: string): string;
4
- export declare function getResponseStatusRetrievalText(responseVariableName: string): string;
5
- export declare function getResponseHeadersRetrievalText(responseVariableName: string): string;
6
- export declare function isInvalidResponseHeadersAccess(responseHeadersAccess: TSESTree.Node): boolean;
7
- export declare function hasAssertions(fixtureCall: TSESTree.Node): boolean;
8
- export declare function isFetchResponse(type: ts.Type): boolean;
@@ -1,7 +0,0 @@
1
- export declare function isApiIndexFile(filename: string): boolean;
2
- export declare function getProjectRootFolder(indexFilename: string): string;
3
- export declare function getSwaggerPathByIndexFile(indexFilename: string): string;
4
- export declare function loadSwagger(filename: string): string;
5
- export declare function loadPackageJson(projectRoot: string): string;
6
- export declare function getApiFolder(folder: string): string | undefined;
7
- export declare function getApiIndexPathByFilename(filename: string): string | undefined;
@@ -1,9 +0,0 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- export declare const ruleId = "fix-function-call-arguments";
3
- export interface FixFunctionCallArgumentsRuleOptions {
4
- typesToCheck: string[];
5
- }
6
- declare const rule: ESLintUtils.RuleModule<'removeIncompatibleFunctionArguments' | 'unknownError', [
7
- FixFunctionCallArgumentsRuleOptions
8
- ]>;
9
- export default rule;
@@ -1,4 +0,0 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- export declare const ruleId = "no-fixture";
3
- declare const rule: ESLintUtils.RuleModule<'unknownError' | 'preferNativeFetch'>;
4
- export default rule;
@@ -1,4 +0,0 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- export declare const ruleId = "no-mapped-response";
3
- declare const rule: ESLintUtils.RuleModule<'unknownError' | 'replaceFullResponseWithFetchResponse'>;
4
- export default rule;
@@ -1,4 +0,0 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- export declare const ruleId = "no-service-wrapper";
3
- declare const rule: ESLintUtils.RuleModule<'unknownError' | 'preferNativeFetch' | 'invalidOptions'>;
4
- export default rule;
@@ -1,4 +0,0 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- export declare const ruleId = "no-status-code";
3
- declare const rule: ESLintUtils.RuleModule<'unknownError' | 'replaceStatusCode'>;
4
- export default rule;
@@ -1,4 +0,0 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- export declare const ruleId = "no-supertest";
3
- declare const rule: ESLintUtils.RuleModule<'unknownError' | 'preferNativeFetch'>;
4
- export default rule;
@@ -1,4 +0,0 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- export declare const ruleId = "no-unused-function-argument";
3
- declare const rule: ESLintUtils.RuleModule<'unknownError' | 'removeUnusedFunctionArguments'>;
4
- export default rule;
@@ -1,4 +0,0 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- export declare const ruleId = "no-unused-imports";
3
- declare const rule: ESLintUtils.RuleModule<'unknownError' | 'removeUnusedImports'>;
4
- export default rule;
@@ -1,4 +0,0 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- export declare const ruleId = "no-unused-service-variable";
3
- declare const rule: ESLintUtils.RuleModule<'unknownError' | 'removeUnusedServiceVariables'>;
4
- export default rule;
@@ -1,16 +0,0 @@
1
- import { TSESTree } from '@typescript-eslint/utils';
2
- import type { ScopeManager, Variable } from '@typescript-eslint/scope-manager';
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: TSESTree.VariableDeclaration | undefined, scopeManager: ScopeManager): {
9
- variable?: Variable;
10
- bodyReferences: TSESTree.MemberExpression[];
11
- statusReferences: TSESTree.MemberExpression[];
12
- destructuringBodyVariable?: Variable | TSESTree.ObjectPattern;
13
- destructuringHeadersVariable?: Variable | TSESTree.ObjectPattern;
14
- destructuringStatusVariable?: Variable | TSESTree.ObjectPattern;
15
- destructuringHeadersReferences?: TSESTree.MemberExpression[] | undefined;
16
- };
@@ -1,4 +0,0 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- export declare const ruleId = "supertest-then";
3
- declare const rule: ESLintUtils.RuleModule<'unknownError' | 'preferNativeFetch'>;
4
- export default rule;
@@ -1,4 +0,0 @@
1
- export declare function isServiceApiCallUrl(url: string): boolean;
2
- export declare function replaceEndpointUrlPrefixWithBasePath(url: string): string;
3
- export declare function replaceEndpointUrlPrefixWithDomain(url: string): string;
4
- export declare function addBasePathUrlDomain(url: string): string;
@@ -1,74 +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 { strict as assert } from 'node:assert';
10
-
11
- import { AST_NODE_TYPES, ESLintUtils } from '@typescript-eslint/utils';
12
-
13
- import getDocumentationUrl from '../get-documentation-url';
14
-
15
- export const ruleId = 'add-assert-import';
16
-
17
- const ASSERT_IMPORT_STATEMENT = "import { strict as assert } from 'node:assert';";
18
-
19
- const createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
20
-
21
- const rule: ESLintUtils.RuleModule<'addAssertImport'> = createRule({
22
- name: ruleId,
23
- meta: {
24
- type: 'suggestion',
25
- docs: {
26
- description: 'Add import of assert module of node.',
27
- },
28
- messages: {
29
- addAssertImport: 'Add import of assert module of node.',
30
- },
31
- fixable: 'code',
32
- schema: [],
33
- },
34
- defaultOptions: [],
35
- create(context) {
36
- let isAssertImported = false;
37
- let isAssertUsed = false;
38
-
39
- return {
40
- ImportDeclaration: (node) => {
41
- if (node.source.value === 'assert' || node.source.value === 'node:assert') {
42
- isAssertImported = true;
43
- }
44
- },
45
- CallExpression: (callExpression) => {
46
- // detect if assert is used
47
- if (
48
- (callExpression.callee.type === AST_NODE_TYPES.Identifier && callExpression.callee.name === 'assert') ||
49
- (callExpression.callee.type === AST_NODE_TYPES.MemberExpression &&
50
- callExpression.callee.object.type === AST_NODE_TYPES.Identifier &&
51
- callExpression.callee.object.name === 'assert')
52
- ) {
53
- isAssertUsed = true;
54
- }
55
- },
56
- 'Program:exit': (program) => {
57
- // add assert import if necessary
58
- if (isAssertUsed && !isAssertImported) {
59
- const firstStatement = program.body[0];
60
- assert(firstStatement);
61
- context.report({
62
- node: program,
63
- messageId: 'addAssertImport',
64
- fix(fixer) {
65
- return fixer.insertTextBefore(firstStatement, `${ASSERT_IMPORT_STATEMENT}\n`);
66
- },
67
- });
68
- }
69
- },
70
- };
71
- },
72
- });
73
-
74
- export default rule;
@@ -1,81 +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 { strict as assert } from 'node:assert';
10
-
11
- import { AST_NODE_TYPES, ESLintUtils, TSESTree } from '@typescript-eslint/utils';
12
-
13
- import getDocumentationUrl from '../get-documentation-url';
14
- import { getProjectRootFolder, getSwaggerPathByIndexFile, isApiIndexFile, loadPackageJson, loadSwagger } from './file';
15
-
16
- export const ruleId = 'add-base-path-const';
17
-
18
- const createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
19
-
20
- const rule: ESLintUtils.RuleModule<'addBasePathConst'> = createRule({
21
- name: ruleId,
22
- meta: {
23
- type: 'suggestion',
24
- docs: {
25
- description: 'Add BASE_PATH const variable.',
26
- },
27
- messages: {
28
- addBasePathConst: 'Add BASE_PATH const variable.',
29
- },
30
- fixable: 'code',
31
- schema: [],
32
- },
33
- defaultOptions: [],
34
- create(context) {
35
- const sourceCode = context.sourceCode;
36
-
37
- return {
38
- Program: (program: TSESTree.Program) => {
39
- if (!isApiIndexFile(context.filename)) {
40
- return;
41
- }
42
-
43
- const scope = sourceCode.getScope(program).childScopes[0];
44
- assert(scope);
45
-
46
- const foundBasePathConst = scope.variables.find((variable) => variable.name === 'BASE_PATH');
47
- if (foundBasePathConst) {
48
- return;
49
- }
50
-
51
- const swaggerPath = getSwaggerPathByIndexFile(context.filename);
52
- const swaggerFileContents = loadSwagger(swaggerPath);
53
- const baseUrlLine = swaggerFileContents
54
- .split('\n')
55
- .find((line) => /^\s*-\s*url:\s*\/.*$/u.test(line) || /^basePath:.*/u.test(line));
56
- const baseUrl = baseUrlLine?.split(':')[1]?.trim();
57
- assert(baseUrl !== undefined);
58
-
59
- const packageRoot = getProjectRootFolder(context.filename);
60
- const packageJson = JSON.parse(loadPackageJson(packageRoot)) as { name: string };
61
- const serviceName = packageJson.name.split('/')[1];
62
- assert(serviceName !== undefined);
63
-
64
- const domain = `https://${serviceName}.checkdigit${baseUrl}`;
65
-
66
- const lastImportStatement = program.body.findLast((node) => node.type === AST_NODE_TYPES.ImportDeclaration);
67
- assert(lastImportStatement);
68
-
69
- context.report({
70
- messageId: 'addBasePathConst',
71
- node: program,
72
- fix(fixer) {
73
- return fixer.insertTextAfter(lastImportStatement, `\nexport const BASE_PATH = '${domain}';\n`);
74
- },
75
- });
76
- },
77
- };
78
- },
79
- });
80
-
81
- export default rule;