Skip to content

Commit

Permalink
fix(nx): fix support for * in lint rules
Browse files Browse the repository at this point in the history
fix #2076
  • Loading branch information
aag5586 authored and vsavkin committed Dec 1, 2019
1 parent c4cba1c commit feca793
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,12 @@ describe('Enforce Module Boundaries', () => {

it('should not error about one level deep imports into library when exception is specified with a wildcard', () => {
const failures = runRule(
{ allow: ['@mycompany/other/*'] },
{ allow: ['@mycompany/other/*', '@mycompany/another/*'] },
`${process.cwd()}/proj/libs/mylib/src/main.ts`,
`
import "@mycompany/other/a/b";
import "@mycompany/other/a";
import "@mycompany/another/a/b";
`,
[
{
Expand All @@ -631,10 +632,23 @@ describe('Enforce Module Boundaries', () => {
'libs/other/a/index.ts': 1,
'libs/other/a/b.ts': 1
}
},
{
name: 'anotherName',
root: 'libs/another',
type: ProjectType.lib,
tags: [],
implicitDependencies: [],
architect: {},
files: [`libs/another/a/index.ts`, `libs/another/a/b.ts`],
fileMTimes: {
'libs/another/a/index.ts': 1,
'libs/another/a/b.ts': 1
}
}
]
);
expect(failures.length).toEqual(1);
expect(failures.length).toEqual(2);
});

it('should respect regexp in allow option', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/workspace/src/utils/runtime-lint-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function matchImportWithWildcard(
} else if (allowableImport.endsWith('/*')) {
const prefix = allowableImport.substring(0, allowableImport.length - 1);
if (!extractedImport.startsWith(prefix)) return false;
return extractedImport.substring(prefix.length).indexOf('/') > -1;
return extractedImport.substring(prefix.length).indexOf('/') === -1;
} else if (allowableImport.indexOf('/**/') > -1) {
const [prefix, suffix] = allowableImport.split('/**/');
return (
Expand Down

0 comments on commit feca793

Please sign in to comment.