From cb84da25f60f1fbfae018e7dd803a353252292fc Mon Sep 17 00:00:00 2001 From: Richard Maisano Date: Thu, 9 Nov 2023 03:32:48 -0500 Subject: [PATCH] fix: handle multiple imports with `no-manual-cleanup` (#835) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mario Beltrán --- lib/rules/no-manual-cleanup.ts | 11 ++++------- tests/lib/rules/no-manual-cleanup.test.ts | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/rules/no-manual-cleanup.ts b/lib/rules/no-manual-cleanup.ts index 833fa147..3313c420 100644 --- a/lib/rules/no-manual-cleanup.ts +++ b/lib/rules/no-manual-cleanup.ts @@ -111,15 +111,12 @@ export default createTestingLibraryRule({ 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) { diff --git a/tests/lib/rules/no-manual-cleanup.test.ts b/tests/lib/rules/no-manual-cleanup.test.ts index 0b22ce6a..61208801 100644 --- a/tests/lib/rules/no-manual-cleanup.test.ts +++ b/tests/lib/rules/no-manual-cleanup.test.ts @@ -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) + ), ], });