Skip to content

Commit e6ce349

Browse files
committed
fix: handle multiple imports with no-manual-cleanup
1 parent e11cde6 commit e6ce349

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

lib/rules/no-manual-cleanup.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,12 @@ export default createTestingLibraryRule<Options, MessageIds>({
111111
return {
112112
'Program:exit'() {
113113
const testingLibraryImportName = helpers.getTestingLibraryImportName();
114-
const testingLibraryImportNode = helpers.getTestingLibraryImportNode();
115114
const customModuleImportNode = helpers.getCustomModuleImportNode();
116115

117-
if (
118-
testingLibraryImportName &&
119-
testingLibraryImportNode &&
120-
testingLibraryImportName.match(CLEANUP_LIBRARY_REGEXP)
121-
) {
122-
reportCandidateModule(testingLibraryImportNode);
116+
if (testingLibraryImportName?.match(CLEANUP_LIBRARY_REGEXP)) {
117+
for (const importNode of helpers.getAllTestingLibraryImportNodes()) {
118+
reportCandidateModule(importNode);
119+
}
123120
}
124121

125122
if (customModuleImportNode) {

tests/lib/rules/no-manual-cleanup.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,5 +235,21 @@ ruleTester.run(RULE_NAME, rule, {
235235
],
236236
} as const)
237237
),
238+
...ALL_TESTING_LIBRARIES_WITH_CLEANUP.map(
239+
(lib) =>
240+
({
241+
code: `
242+
import { render } from "${lib}";
243+
import { cleanup } from "${lib}";
244+
afterEach(cleanup);
245+
`,
246+
errors: [
247+
{
248+
line: 3,
249+
column: 18,
250+
},
251+
],
252+
} as const)
253+
),
238254
],
239255
});

0 commit comments

Comments
 (0)