From b151d0492a8c372a55831323f48a99efe3276df0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fermann?= Date: Mon, 15 Apr 2019 23:42:04 +0200 Subject: [PATCH] [fix] `no-unused-modules`: avoid crash when using `ignoreExports`-option Fixes #1323. --- src/rules/no-unused-modules.js | 4 ++++ tests/src/rules/no-unused-modules.js | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/rules/no-unused-modules.js b/src/rules/no-unused-modules.js index 91d1679bb..552004b6d 100644 --- a/src/rules/no-unused-modules.js +++ b/src/rules/no-unused-modules.js @@ -274,6 +274,10 @@ module.exports = { return } + if (ignoredFiles.has(file)) { + return + } + const exportCount = exportList.get(file) const exportAll = exportCount.get(EXPORT_ALL_DECLARATION) const namespaceImports = exportCount.get(IMPORT_NAMESPACE_SPECIFIER) diff --git a/tests/src/rules/no-unused-modules.js b/tests/src/rules/no-unused-modules.js index 9918b85f4..7b11ee6d0 100644 --- a/tests/src/rules/no-unused-modules.js +++ b/tests/src/rules/no-unused-modules.js @@ -549,3 +549,18 @@ describe('test behaviour for new file', () => { } }) }) + +describe('do not report missing export for ignored file', () => { + ruleTester.run('no-unused-modules', rule, { + valid: [ + test({ options: [{ + src: [testFilePath('./no-unused-modules/**/*.js')], + ignoreExports: [testFilePath('./no-unused-modules/*ignored*.js')], + missingExports: true + }], + code: 'export const test = true', + filename: testFilePath('./no-unused-modules/file-ignored-a.js')}), + ], + invalid: [], + }) +})