Skip to content

Commit 7e191f5

Browse files
author
Arkadii Berezkin
committed
use globs instead of regexp
1 parent 0c4e324 commit 7e191f5

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

Diff for: src/rules/no-namespace.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* @author Radek Benkel
44
*/
55

6+
import minimatch from 'minimatch';
67
import docsUrl from '../docsUrl';
78

89
//------------------------------------------------------------------------------
@@ -20,23 +21,27 @@ module.exports = {
2021
schema: [{
2122
type: 'object',
2223
properties: {
23-
ignoreFromPattern: {
24-
type: 'string',
24+
ignoreFromPatterns: {
25+
type: 'array',
26+
items: {
27+
type: 'string',
28+
},
2529
},
2630
},
2731
}],
2832
},
2933

3034
create: function (context) {
3135
const firstOption = context.options[0] || {};
32-
const ignoreFromPatternExpression =
33-
firstOption.ignoreFromPattern &&
34-
new RegExp(firstOption.ignoreFromPattern);
36+
const ignoreFromPatterns = firstOption.ignoreFromPatterns;
3537

3638
return {
3739
'ImportNamespaceSpecifier': function (node) {
3840
if (
39-
ignoreFromPatternExpression && ignoreFromPatternExpression.test(node.parent.source.value)
41+
ignoreFromPatterns
42+
&& ignoreFromPatterns.find(
43+
glob => minimatch(node.parent.source.value, glob, { matchBase: true })
44+
)
4045
) {
4146
return;
4247
}

Diff for: tests/src/rules/no-namespace.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ ruleTester.run('no-namespace', require('rules/no-namespace'), {
7979
{ code: 'import bar from \'bar\';', parserOptions: { ecmaVersion: 2015, sourceType: 'module' } },
8080
{ code: 'import bar from \'./bar\';', parserOptions: { ecmaVersion: 2015, sourceType: 'module' } },
8181
{ code: 'import * as bar from \'./ignored-module.ext\';', parserOptions: { ecmaVersion: 2015, sourceType: 'module' }, options: [{
82-
ignoreFromPattern: '\\S+\\.ext',
82+
ignoreFromPatterns: ['*.ext'],
8383
}] },
8484
],
8585

0 commit comments

Comments
 (0)