diff --git a/packages/js/src/generators/library/library.ts b/packages/js/src/generators/library/library.ts index 47560e74b2015..ef3451ede0ba6 100644 --- a/packages/js/src/generators/library/library.ts +++ b/packages/js/src/generators/library/library.ts @@ -244,6 +244,9 @@ export async function addLint( options: AddLintOptions ): Promise { const { lintProjectGenerator } = ensurePackage('@nx/linter', nxVersion); + const { mapLintPattern } = + // nx-ignore-next-line + require('@nx/linter/src/generators/lint-project/lint-project'); 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 c46646159f84e..dd631df918753 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 56f5d37a12d4a..4ee945c296265 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, });