Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(linter): fix linter standalone patterns in Js and Next #19508

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 === '')) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of E2E projects generated alongside the standalone project, the rootProject would be still true, but project root would point to some e2e-ish folder

return `${projectRoot}/src/**/*.${extension}`;
} else {
return `${projectRoot}/**/*.${extension}`;
}
}

export async function lintProjectGenerator(
Expand Down
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