From ec6e376ca612e68cd93e7a83e9d9cf58a229cef5 Mon Sep 17 00:00:00 2001 From: Miroslav Jonas Date: Mon, 9 Oct 2023 16:07:46 +0200 Subject: [PATCH 1/2] fix(core): fix linter standalone patterns --- packages/js/src/generators/library/library.ts | 11 +++++++++-- .../src/generators/lint-project/lint-project.ts | 7 +++++-- .../src/generators/application/lib/add-linting.ts | 9 ++++++++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/packages/js/src/generators/library/library.ts b/packages/js/src/generators/library/library.ts index 47560e74b2015..38339e4680e19 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 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, }); From 890ebc1729e7f408ebd3b192524f071f3d4041e8 Mon Sep 17 00:00:00 2001 From: Miroslav Jonas Date: Mon, 9 Oct 2023 22:11:45 +0200 Subject: [PATCH 2/2] fix(linter): fix broken js import --- packages/js/src/generators/library/library.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/js/src/generators/library/library.ts b/packages/js/src/generators/library/library.ts index 38339e4680e19..ef3451ede0ba6 100644 --- a/packages/js/src/generators/library/library.ts +++ b/packages/js/src/generators/library/library.ts @@ -243,10 +243,10 @@ export async function addLint( tree: Tree, options: AddLintOptions ): Promise { - const { lintProjectGenerator, mapLintPattern } = ensurePackage( - '@nx/linter', - nxVersion - ); + 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,