Skip to content

Commit

Permalink
fix(linter): fix linter standalone patterns in Js and Next (nrwl#19508)
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav authored Oct 10, 2023
1 parent fce2c08 commit 8bf6a97
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
9 changes: 8 additions & 1 deletion packages/js/src/generators/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ export async function addLint(
options: AddLintOptions
): Promise<GeneratorCallback> {
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,
Expand All @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions packages/linter/src/generators/lint-project/lint-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 8 additions & 1 deletion packages/next/src/generators/application/lib/add-linting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
});
Expand Down

0 comments on commit 8bf6a97

Please sign in to comment.