diff --git a/packages/js/src/generators/library/library.ts b/packages/js/src/generators/library/library.ts index 47560e74b2015d..38339e4680e19e 100644 --- a/packages/js/src/generators/library/library.ts +++ b/packages/js/src/generators/library/library.ts @@ -243,7 +243,10 @@ export async function addLint( tree: Tree, options: AddLintOptions ): Promise { - const { lintProjectGenerator } = ensurePackage('@nx/linter', nxVersion); + const { lintProjectGenerator, mapLintPattern } = ensurePackage( + '@nx/linter', + nxVersion + ); const projectConfiguration = readProjectConfiguration(tree, options.name); const task = lintProjectGenerator(tree, { project: options.name, @@ -254,7 +257,11 @@ export async function addLint( ], unitTestRunner: options.unitTestRunner, eslintFilePatterns: [ - `${options.projectRoot}/**/*.${options.js ? 'js' : 'ts'}`, + mapLintPattern( + options.projectRoot, + options.js ? 'js' : 'ts', + options.rootProject + ), ], setParserOptionsProject: options.setParserOptionsProject, rootProject: options.rootProject, diff --git a/packages/linter/src/generators/lint-project/lint-project.ts b/packages/linter/src/generators/lint-project/lint-project.ts index c46646159f84e9..dd631df9187534 100644 --- a/packages/linter/src/generators/lint-project/lint-project.ts +++ b/packages/linter/src/generators/lint-project/lint-project.ts @@ -52,8 +52,11 @@ export function mapLintPattern( extension: string, rootProject?: boolean ) { - const infix = rootProject ? 'src/' : ''; - return `${projectRoot}/${infix}**/*.${extension}`; + if (rootProject && (projectRoot === '.' || projectRoot === '')) { + return `${projectRoot}/src/**/*.${extension}`; + } else { + return `${projectRoot}/**/*.${extension}`; + } } export async function lintProjectGenerator( diff --git a/packages/next/src/generators/application/lib/add-linting.ts b/packages/next/src/generators/application/lib/add-linting.ts index 56f5d37a12d4a0..4ee945c296265b 100644 --- a/packages/next/src/generators/application/lib/add-linting.ts +++ b/packages/next/src/generators/application/lib/add-linting.ts @@ -15,6 +15,7 @@ import { isEslintConfigSupported, updateOverrideInLintConfig, } from '@nx/linter/src/generators/utils/eslint-file'; +import { mapLintPattern } from '@nx/linter/src/generators/lint-project/lint-project'; export async function addLinting( host: Tree, @@ -27,7 +28,13 @@ export async function addLinting( joinPathFragments(options.appProjectRoot, 'tsconfig.app.json'), ], unitTestRunner: options.unitTestRunner, - eslintFilePatterns: [`${options.appProjectRoot}/**/*.{ts,tsx,js,jsx}`], + eslintFilePatterns: [ + mapLintPattern( + options.appProjectRoot, + '{ts,tsx,js,jsx}', + options.rootProject + ), + ], skipFormat: true, rootProject: options.rootProject, });