Skip to content

Commit cb84da2

Browse files
maisanoBelco90
andauthored
fix: handle multiple imports with no-manual-cleanup (#835)
Co-authored-by: Mario Beltrán <[email protected]>
1 parent 80843f7 commit cb84da2

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

lib/rules/no-manual-cleanup.ts

+4-7
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

+17
Original file line numberDiff line numberDiff line change
@@ -235,5 +235,22 @@ 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+
messageId: 'noManualCleanup',
251+
},
252+
],
253+
} as const)
254+
),
238255
],
239256
});

0 commit comments

Comments
 (0)