Skip to content

Commit

Permalink
fix: handle multiple imports with no-manual-cleanup (#835)
Browse files Browse the repository at this point in the history
Co-authored-by: Mario Beltrán <belco90@gmail.com>
  • Loading branch information
maisano and Belco90 authored Nov 9, 2023
1 parent 80843f7 commit cb84da2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
11 changes: 4 additions & 7 deletions lib/rules/no-manual-cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,12 @@ export default createTestingLibraryRule<Options, MessageIds>({
return {
'Program:exit'() {
const testingLibraryImportName = helpers.getTestingLibraryImportName();
const testingLibraryImportNode = helpers.getTestingLibraryImportNode();
const customModuleImportNode = helpers.getCustomModuleImportNode();

if (
testingLibraryImportName &&
testingLibraryImportNode &&
testingLibraryImportName.match(CLEANUP_LIBRARY_REGEXP)
) {
reportCandidateModule(testingLibraryImportNode);
if (testingLibraryImportName?.match(CLEANUP_LIBRARY_REGEXP)) {
for (const importNode of helpers.getAllTestingLibraryImportNodes()) {
reportCandidateModule(importNode);
}
}

if (customModuleImportNode) {
Expand Down
17 changes: 17 additions & 0 deletions tests/lib/rules/no-manual-cleanup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,5 +235,22 @@ ruleTester.run(RULE_NAME, rule, {
],
} as const)
),
...ALL_TESTING_LIBRARIES_WITH_CLEANUP.map(
(lib) =>
({
code: `
import { render } from "${lib}";
import { cleanup } from "${lib}";
afterEach(cleanup);
`,
errors: [
{
line: 3,
column: 18,
messageId: 'noManualCleanup',
},
],
} as const)
),
],
});

0 comments on commit cb84da2

Please sign in to comment.