From 8b5167a559b11cd731f780e507ae296f6e8076f4 Mon Sep 17 00:00:00 2001 From: Elizabeth Craig Date: Wed, 12 Jan 2022 18:53:45 -0600 Subject: [PATCH] reverse if condition --- packages/eslint-plugin/src/rules/ban-imports.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/eslint-plugin/src/rules/ban-imports.js b/packages/eslint-plugin/src/rules/ban-imports.js index c4f32ac50a046..3c2b152fce9d7 100644 --- a/packages/eslint-plugin/src/rules/ban-imports.js +++ b/packages/eslint-plugin/src/rules/ban-imports.js @@ -124,14 +124,7 @@ module.exports = createRule({ verb: importOrExport.type === AST_NODE_TYPES.ImportDeclaration ? 'Importing' : 'Exporting', }; - if (!names) { - // All imports from this path are banned - context.report({ - node: importOrExport, - messageId: 'pathNotAllowed', - data: errorData, - }); - } else { + if (names) { // Only certain imports from this path are banned for (const identifier of identifiers) { if (names.some(name => isMatch(identifier.name, name))) { @@ -142,6 +135,13 @@ module.exports = createRule({ }); } } + } else { + // All imports from this path are banned + context.report({ + node: importOrExport, + messageId: 'pathNotAllowed', + data: errorData, + }); } } }