diff --git a/packages/eslint-plugin-nx/tests/rules/enforce-module-boundaries.spec.ts b/packages/eslint-plugin-nx/tests/rules/enforce-module-boundaries.spec.ts index c52dcd94d26c6..1ea3f68bfb40a 100644 --- a/packages/eslint-plugin-nx/tests/rules/enforce-module-boundaries.spec.ts +++ b/packages/eslint-plugin-nx/tests/rules/enforce-module-boundaries.spec.ts @@ -644,6 +644,43 @@ describe('Enforce Module Boundaries', () => { expect(failures.length).toEqual(1); }); + it('should respect regexp in allow option', () => { + const failures = runRule( + { allow: ['^.*/utils/.*$'] }, + `${process.cwd()}/proj/libs/mylib/src/main.ts`, + ` + import "../../utils/a"; + `, + [ + { + name: 'mylibName', + root: 'libs/mylib', + type: ProjectType.lib, + tags: [], + implicitDependencies: [], + architect: {}, + files: [`libs/mylib/src/main.ts`], + fileMTimes: { + 'libs/mylib/src/main.ts': 1 + } + }, + { + name: 'utils', + root: 'libs/utils', + type: ProjectType.lib, + tags: [], + implicitDependencies: [], + architect: {}, + files: [`libs/utils/a.ts`], + fileMTimes: { + 'libs/utils/a.ts': 1 + } + } + ] + ); + expect(failures.length).toEqual(0); + }); + it('should error on importing a lazy-loaded library', () => { const failures = runRule( {}, diff --git a/packages/workspace/src/tslint/nxEnforceModuleBoundariesRule.spec.ts b/packages/workspace/src/tslint/nxEnforceModuleBoundariesRule.spec.ts index d847e19dc6ade..9638cc4fa8655 100644 --- a/packages/workspace/src/tslint/nxEnforceModuleBoundariesRule.spec.ts +++ b/packages/workspace/src/tslint/nxEnforceModuleBoundariesRule.spec.ts @@ -637,6 +637,43 @@ describe('Enforce Module Boundaries', () => { expect(failures.length).toEqual(1); }); + it('should respect regexp in allow option', () => { + const failures = runRule( + { allow: ['^.*/utils/.*$'] }, + `${process.cwd()}/proj/libs/mylib/src/main.ts`, + ` + import "../../utils/a"; + `, + [ + { + name: 'mylibName', + root: 'libs/mylib', + type: ProjectType.lib, + tags: [], + implicitDependencies: [], + architect: {}, + files: [`libs/mylib/src/main.ts`], + fileMTimes: { + 'libs/mylib/src/main.ts': 1 + } + }, + { + name: 'utils', + root: 'libs/utils', + type: ProjectType.lib, + tags: [], + implicitDependencies: [], + architect: {}, + files: [`libs/utils/a.ts`], + fileMTimes: { + 'libs/utils/a.ts': 1 + } + } + ] + ); + expect(failures.length).toEqual(0); + }); + it('should error on importing a lazy-loaded library', () => { const failures = runRule( {}, diff --git a/packages/workspace/src/utils/runtime-lint-utils.ts b/packages/workspace/src/utils/runtime-lint-utils.ts index 409a3fa17f9af..86ae14051688f 100644 --- a/packages/workspace/src/utils/runtime-lint-utils.ts +++ b/packages/workspace/src/utils/runtime-lint-utils.ts @@ -56,7 +56,7 @@ export function matchImportWithWildcard( extractedImport.startsWith(prefix) && extractedImport.endsWith(suffix) ); } else { - return extractedImport === allowableImport; + return new RegExp(allowableImport).test(extractedImport); } }