diff --git a/src/rules/no-namespace.js b/src/rules/no-namespace.js index d2edf1769e..3c3cc6cdfa 100644 --- a/src/rules/no-namespace.js +++ b/src/rules/no-namespace.js @@ -3,6 +3,7 @@ * @author Radek Benkel */ +import minimatch from 'minimatch'; import docsUrl from '../docsUrl'; //------------------------------------------------------------------------------ @@ -20,8 +21,11 @@ module.exports = { schema: [{ type: 'object', properties: { - ignoreFromPattern: { - type: 'string', + ignoreFromPatterns: { + type: 'array', + items: { + type: 'string', + }, }, }, }], @@ -29,14 +33,15 @@ module.exports = { create: function (context) { const firstOption = context.options[0] || {}; - const ignoreFromPatternExpression = - firstOption.ignoreFromPattern && - new RegExp(firstOption.ignoreFromPattern); + const ignoreFromPatterns = firstOption.ignoreFromPatterns; return { 'ImportNamespaceSpecifier': function (node) { if ( - ignoreFromPatternExpression && ignoreFromPatternExpression.test(node.parent.source.value) + ignoreFromPatterns + && ignoreFromPatterns.find( + glob => minimatch(node.parent.source.value, glob, { matchBase: true }) + ) ) { return; } diff --git a/tests/src/rules/no-namespace.js b/tests/src/rules/no-namespace.js index 8f8c64a045..e1f517621a 100644 --- a/tests/src/rules/no-namespace.js +++ b/tests/src/rules/no-namespace.js @@ -79,7 +79,7 @@ ruleTester.run('no-namespace', require('rules/no-namespace'), { { code: 'import bar from \'bar\';', parserOptions: { ecmaVersion: 2015, sourceType: 'module' } }, { code: 'import bar from \'./bar\';', parserOptions: { ecmaVersion: 2015, sourceType: 'module' } }, { code: 'import * as bar from \'./ignored-module.ext\';', parserOptions: { ecmaVersion: 2015, sourceType: 'module' }, options: [{ - ignoreFromPattern: '\\S+\\.ext', + ignoreFromPatterns: ['*.ext'], }] }, ],