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

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,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;
@@ -1,69 +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
- import { getApiIndexPathByFilename } from './file';
15
-
16
- export const ruleId = 'add-base-path-import';
17
-
18
- const createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
19
-
20
- const rule: ESLintUtils.RuleModule<'addBasePathImport'> = createRule({
21
- name: ruleId,
22
- meta: {
23
- type: 'suggestion',
24
- docs: {
25
- description: 'Add import of BASE_PATH if it is used but not imported.',
26
- },
27
- messages: {
28
- addBasePathImport: 'Add import of BASE_PATH.',
29
- },
30
- fixable: 'code',
31
- schema: [],
32
- },
33
- defaultOptions: [],
34
- create(context) {
35
- const sourceCode = context.sourceCode;
36
-
37
- return {
38
- Program: (program) => {
39
- const isBasePathUsed = sourceCode.text.includes(`$\{BASE_PATH}`);
40
- if (isBasePathUsed) {
41
- const topScope = sourceCode.getScope(program).childScopes[0];
42
- assert(topScope);
43
- if (topScope.variables.some((variable) => variable.name === 'BASE_PATH')) {
44
- return;
45
- }
46
-
47
- const apiIndexPath = getApiIndexPathByFilename(context.filename);
48
- if (apiIndexPath !== undefined) {
49
- const lastImportStatement = program.body.findLast(
50
- (statement) => statement.type === AST_NODE_TYPES.ImportDeclaration,
51
- );
52
- assert(lastImportStatement);
53
-
54
- const basePathImportStatement = `\nimport { BASE_PATH } from '${apiIndexPath}';\n`;
55
- context.report({
56
- node: program,
57
- messageId: 'addBasePathImport',
58
- fix(fixer) {
59
- return fixer.insertTextAfter(lastImportStatement, basePathImportStatement);
60
- },
61
- });
62
- }
63
- }
64
- },
65
- };
66
- },
67
- });
68
-
69
- export default rule;
@@ -1,76 +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
-
11
- import getDocumentationUrl from '../get-documentation-url';
12
- import { addBasePathUrlDomain } from './url';
13
-
14
- export const ruleId = 'add-url-domain';
15
-
16
- const createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
17
-
18
- const rule: ESLintUtils.RuleModule<'addDomain' | 'unknownError'> = createRule({
19
- name: ruleId,
20
- meta: {
21
- type: 'suggestion',
22
- docs: {
23
- description: 'Add HTTP domain to the BASE_PATH like url constant variable.',
24
- },
25
- messages: {
26
- addDomain: 'Add HTTP domain to the BASE_PATH like url constant variable.',
27
- unknownError: 'Unknown error occurred in file "{{fileName}}": {{ error }}.',
28
- },
29
- fixable: 'code',
30
- schema: [],
31
- },
32
- defaultOptions: [],
33
- create(context) {
34
- const sourceCode = context.sourceCode;
35
-
36
- return {
37
- 'VariableDeclarator[id.name=/^([A-Z]+_)*BASE_PATH$/]': (basePathDeclarator: TSESTree.VariableDeclarator) => {
38
- try {
39
- if (
40
- basePathDeclarator.init === null ||
41
- (basePathDeclarator.init.type !== AST_NODE_TYPES.Literal &&
42
- basePathDeclarator.init.type !== AST_NODE_TYPES.TemplateLiteral)
43
- ) {
44
- return;
45
- }
46
-
47
- const urlText = sourceCode.getText(basePathDeclarator.init);
48
- const replacement = addBasePathUrlDomain(urlText);
49
-
50
- if (replacement !== urlText) {
51
- context.report({
52
- messageId: 'addDomain',
53
- node: basePathDeclarator.init,
54
- fix(fixer) {
55
- return fixer.replaceText(basePathDeclarator.init as TSESTree.Node, replacement);
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: basePathDeclarator,
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,273 +0,0 @@
1
- // agent/agent-test-wiring.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_TOKEN_TYPES, ESLintUtils, TSESTree } from '@typescript-eslint/utils';
12
- import type { RuleFix, RuleFixer } from '@typescript-eslint/utils/ts-eslint';
13
- import debug from 'debug';
14
-
15
- import getDocumentationUrl from '../get-documentation-url';
16
-
17
- export const ruleId = 'agent-test-wiring';
18
- const createRule = ESLintUtils.RuleCreator((name) => getDocumentationUrl(name));
19
- const log = debug('eslint-plugin:agent:agent-test-wiring');
20
-
21
- const STATEMENT_FIXTURE_RESET = 'fixture.reset()';
22
- const STATEMENT_FIXTURE_RESET_AWAITED = `await ${STATEMENT_FIXTURE_RESET};`;
23
- const STATEMENT_AGENT_DECLARATION = 'let agent: Agent;';
24
- const STATEMENT_AGENT_CREATION = 'agent = await createAgent();';
25
- const STATEMENT_AGENT_REGISTER = 'agent.register(await fixturePlugin(fixture));';
26
- const STATEMENT_AGENT_ENABLE = 'agent.enable();';
27
- const STATEMENT_AGENT_DISPOSE = 'await agent[Symbol.asyncDispose]();';
28
-
29
- const rule: ESLintUtils.RuleModule<'updateTestWiring' | 'unknownError'> = createRule({
30
- name: ruleId,
31
- meta: {
32
- type: 'suggestion',
33
- docs: {
34
- description: 'Update test wiring.',
35
- },
36
- messages: {
37
- updateTestWiring: 'Updating test wiring.',
38
- unknownError: 'Unknown error occurred in file "{{fileName}}": {{ error }}.',
39
- },
40
- fixable: 'code',
41
- schema: [],
42
- },
43
- defaultOptions: [],
44
- // eslint-disable-next-line max-lines-per-function
45
- create(context) {
46
- log('Processing file:', context.filename);
47
- const sourceCode = context.sourceCode;
48
- const importDeclarations = new Map<string, TSESTree.ImportDeclaration>();
49
- let isFixtureUsed = false;
50
- let beforeAll: TSESTree.CallExpression | undefined;
51
- let beforeEach: TSESTree.CallExpression | undefined;
52
- let afterAll: TSESTree.CallExpression | undefined;
53
-
54
- return {
55
- ImportDeclaration(importDeclaration) {
56
- const moduleName = importDeclaration.source.value;
57
- importDeclarations.set(moduleName, importDeclaration);
58
- if (
59
- moduleName === '@checkdigit/fixture' &&
60
- importDeclaration.specifiers.some(
61
- (specifier) =>
62
- specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier &&
63
- specifier.imported.type === TSESTree.AST_NODE_TYPES.Identifier &&
64
- specifier.imported.name === 'createFixture',
65
- )
66
- ) {
67
- isFixtureUsed = true;
68
- }
69
- },
70
- 'CallExpression[callee.name="beforeAll"]': (callExpression: TSESTree.CallExpression) => {
71
- beforeAll = callExpression;
72
- },
73
- 'CallExpression[callee.name="beforeEach"]': (callExpression: TSESTree.CallExpression) => {
74
- beforeEach = callExpression;
75
- },
76
- 'CallExpression[callee.name="afterAll"]': (callExpression: TSESTree.CallExpression) => {
77
- afterAll = callExpression;
78
- },
79
- // eslint-disable-next-line sonarjs/cognitive-complexity
80
- 'Program:exit'(program) {
81
- if (!isFixtureUsed || (beforeAll === undefined && beforeEach === undefined)) {
82
- // only update test wiring if fixture is used
83
- return;
84
- }
85
-
86
- try {
87
- let jestImportFixer: ((fixer: RuleFixer) => RuleFix) | undefined;
88
- let agentImportFixer: ((fixer: RuleFixer) => RuleFix) | undefined;
89
- let fixturePluginImportFixer: ((fixer: RuleFixer) => RuleFix) | undefined;
90
- let agentDeclarationFixer: ((fixer: RuleFixer) => RuleFix) | undefined;
91
- let beforeAllOrEachFixer: ((fixer: RuleFixer) => RuleFix) | undefined;
92
- let afterAllFixer: ((fixer: RuleFixer) => RuleFix) | undefined;
93
-
94
- const lastImportDeclaration = [...importDeclarations.values()].at(-1);
95
- assert.ok(lastImportDeclaration);
96
-
97
- // make sure that afterAll is imported from jest
98
- const jestImportDeclaration = importDeclarations.get('@jest/globals');
99
- assert.ok(jestImportDeclaration);
100
- const importsToAdd = ['afterAll', 'beforeAll'].filter(
101
- (jestHook) =>
102
- !jestImportDeclaration.specifiers.some(
103
- (specifier) =>
104
- specifier.type === TSESTree.AST_NODE_TYPES.ImportSpecifier &&
105
- specifier.imported.type === TSESTree.AST_NODE_TYPES.Identifier &&
106
- specifier.imported.name === jestHook,
107
- ),
108
- );
109
- if (importsToAdd.length > 0) {
110
- const firstImportSpecifier = jestImportDeclaration.specifiers[0];
111
- assert.ok(firstImportSpecifier);
112
- jestImportFixer = (fixer: RuleFixer) =>
113
- fixer.insertTextBefore(firstImportSpecifier, `${importsToAdd.join(', ')}, `);
114
- }
115
-
116
- // make sure that agent is imported
117
- const agentImportDeclaration = importDeclarations.get('@checkdigit/agent');
118
- if (!agentImportDeclaration) {
119
- agentImportFixer = (fixer: RuleFixer) =>
120
- fixer.insertTextAfter(
121
- lastImportDeclaration,
122
- `\nimport createAgent, { type Agent } from '@checkdigit/agent';`,
123
- );
124
- }
125
-
126
- // make sure that fixture plugin is imported
127
- const pathLets = context.filename.split('/');
128
- const currentFileIndex = pathLets.length - 1;
129
- const pluginFolderIndex = pathLets.lastIndexOf('src') + 1;
130
- // it should be safe to assume that the test code is always at least one level deeper than the plugin folder
131
- const fixturePluginImportPath = `${'../'.repeat(currentFileIndex - pluginFolderIndex)}plugin/fixture.test`;
132
- if (!importDeclarations.get(fixturePluginImportPath)) {
133
- fixturePluginImportFixer = (fixer: RuleFixer) =>
134
- fixer.insertTextAfter(lastImportDeclaration, `\nimport fixturePlugin from '${fixturePluginImportPath}';`);
135
- }
136
-
137
- // inject agent declaration and initialization
138
- if (beforeAll === undefined) {
139
- // create `beforeAll` block if it doesn't exist
140
- beforeAllOrEachFixer = (fixer: RuleFixer) =>
141
- fixer.insertTextBefore(
142
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
143
- beforeEach!,
144
- [
145
- STATEMENT_AGENT_DECLARATION,
146
- `beforeAll(async () => {`,
147
- [STATEMENT_AGENT_CREATION, STATEMENT_AGENT_REGISTER, STATEMENT_AGENT_ENABLE].join('\n'),
148
- `});\n`,
149
- ].join('\n'),
150
- );
151
- } else {
152
- const beforeAllArgument = beforeAll.arguments[0];
153
- assert.ok(beforeAllArgument !== undefined);
154
- if (!sourceCode.getText(beforeAllArgument).includes(STATEMENT_AGENT_CREATION)) {
155
- if (
156
- beforeAllArgument.type === TSESTree.AST_NODE_TYPES.ArrowFunctionExpression &&
157
- beforeAllArgument.body.type === TSESTree.AST_NODE_TYPES.BlockStatement
158
- ) {
159
- const fixtureResetStatement = beforeAllArgument.body.body.find(
160
- (statement) => sourceCode.getText(statement) === STATEMENT_FIXTURE_RESET_AWAITED,
161
- );
162
- assert.ok(fixtureResetStatement !== undefined);
163
- beforeAllOrEachFixer = (fixer: RuleFixer) =>
164
- fixer.replaceText(
165
- fixtureResetStatement,
166
- [
167
- STATEMENT_AGENT_CREATION,
168
- STATEMENT_AGENT_REGISTER,
169
- STATEMENT_AGENT_ENABLE,
170
- STATEMENT_FIXTURE_RESET_AWAITED,
171
- ].join('\n'),
172
- );
173
- } else {
174
- beforeAllOrEachFixer = (fixer: RuleFixer) =>
175
- fixer.replaceText(
176
- beforeAllArgument,
177
- [
178
- `async () => {`,
179
- STATEMENT_AGENT_CREATION,
180
- STATEMENT_AGENT_REGISTER,
181
- STATEMENT_AGENT_ENABLE,
182
- STATEMENT_FIXTURE_RESET_AWAITED,
183
- `}`,
184
- ].join('\n'),
185
- );
186
- }
187
- agentDeclarationFixer = (fixer: RuleFixer) =>
188
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
189
- fixer.insertTextBefore(beforeAll!, `${STATEMENT_AGENT_DECLARATION}\n`);
190
- }
191
- }
192
-
193
- // inject agent disposal to `afterAll` block
194
- if (afterAll !== undefined) {
195
- const afterAllArrowFunctionExpression = afterAll.arguments[0];
196
- assert.ok(
197
- afterAllArrowFunctionExpression !== undefined &&
198
- afterAllArrowFunctionExpression.type === TSESTree.AST_NODE_TYPES.ArrowFunctionExpression,
199
- );
200
- const arrowFunctionBody = afterAllArrowFunctionExpression.body;
201
- assert.ok(arrowFunctionBody.type === TSESTree.AST_NODE_TYPES.BlockStatement);
202
-
203
- const afterAllBodyText = sourceCode.getText(arrowFunctionBody);
204
- if (!afterAllBodyText.includes(STATEMENT_AGENT_DISPOSE)) {
205
- const lastStatement = arrowFunctionBody.body.at(-1);
206
- assert.ok(lastStatement);
207
- afterAllFixer = (fixer: RuleFixer) => fixer.insertTextAfter(lastStatement, STATEMENT_AGENT_DISPOSE);
208
- }
209
- } else {
210
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
211
- const nextToken = sourceCode.getTokenAfter(beforeAll ?? beforeEach!);
212
- afterAllFixer = (fixer: RuleFixer) =>
213
- fixer.insertTextAfter(
214
- nextToken !== null && nextToken.type === AST_TOKEN_TYPES.Punctuator
215
- ? nextToken
216
- : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
217
- beforeAll!,
218
- ['', `afterAll(async () => {`, STATEMENT_AGENT_DISPOSE, `});`].join('\n'),
219
- );
220
- }
221
-
222
- if (
223
- jestImportFixer !== undefined ||
224
- agentImportFixer !== undefined ||
225
- fixturePluginImportFixer !== undefined ||
226
- agentDeclarationFixer !== undefined ||
227
- beforeAllOrEachFixer !== undefined ||
228
- afterAllFixer !== undefined
229
- ) {
230
- context.report({
231
- messageId: 'updateTestWiring',
232
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
233
- node: beforeAll ?? beforeEach!,
234
- *fix(fixer) {
235
- if (jestImportFixer !== undefined) {
236
- yield jestImportFixer(fixer);
237
- }
238
- if (agentImportFixer !== undefined) {
239
- yield agentImportFixer(fixer);
240
- }
241
- if (fixturePluginImportFixer !== undefined) {
242
- yield fixturePluginImportFixer(fixer);
243
- }
244
- if (agentDeclarationFixer !== undefined) {
245
- yield agentDeclarationFixer(fixer);
246
- }
247
- if (beforeAllOrEachFixer !== undefined) {
248
- yield beforeAllOrEachFixer(fixer);
249
- }
250
- if (afterAllFixer !== undefined) {
251
- yield afterAllFixer(fixer);
252
- }
253
- },
254
- });
255
- }
256
- } catch (error) {
257
- // eslint-disable-next-line no-console
258
- console.error(`Failed to apply ${ruleId} rule for file "${context.filename}":`, error);
259
- context.report({
260
- node: program,
261
- messageId: 'unknownError',
262
- data: {
263
- fileName: context.filename,
264
- error: error instanceof Error ? error.toString() : JSON.stringify(error),
265
- },
266
- });
267
- }
268
- },
269
- };
270
- },
271
- });
272
-
273
- export default rule;