Skip to content

Commit

Permalink
fix(eslint-rules): repair ban-imports-file-pattern rule
Browse files Browse the repository at this point in the history
  • Loading branch information
dhhyi authored and shauke committed Sep 22, 2022
1 parent 634f087 commit 0c65e3d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion eslint-rules/src/rules/ban-imports-file-pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const banImportsFilePatternRule: TSESLint.RuleModule<keyof typeof messages, [Rul
rules.forEach(rule => {
if (
new RegExp(rule.filePattern).test(normalizePath(context.getFilename())) &&
node.source.value === rule.name &&
new RegExp(rule.name).test(node.source.value) &&
checkValidityOfSpecifiers(node.specifiers, rule.importNamePattern, rule.starImport)
) {
context.report({
Expand Down
28 changes: 27 additions & 1 deletion eslint-rules/tests/ban-imports-file-pattern.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,33 @@ testRule(banImportsFilePatternRule, {
],
},
{
name: 'should report when detecting disallowed start pattern',
name: 'should report on file included in file pattern',
filename: 'test.component.spec.ts',
options: [
[
{
importNamePattern: 'environment',
name: '.*environments\\/environment',
filePattern: '^.*\\.ts$',
message: 'Test Message',
},
],
],
code: `
import { environment } from '../environments/environment';
`,
errors: [
{
messageId: 'banImportsFilePatternError',
data: {
message: 'Test Message',
},
type: AST_NODE_TYPES.ImportDeclaration,
},
],
},
{
name: 'should report when detecting disallowed star pattern',
filename: 'test.component.ts',
options: [
[
Expand Down

0 comments on commit 0c65e3d

Please sign in to comment.