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): do not infer lint tasks for projects without files to lint #22944

Merged

Conversation

leosvelperez
Copy link
Member

Current Behavior

@nx/eslint/plugin infers tasks for projects without files to lint. It doesn't properly consider the ESLint ignored files configuration.

Expected Behavior

@nx/eslint/plugin should not infer tasks for projects without files to lint.

Related Issue(s)

Fixes #

@leosvelperez leosvelperez self-assigned this Apr 22, 2024
@leosvelperez leosvelperez requested review from a team as code owners April 22, 2024 16:10
@leosvelperez leosvelperez requested a review from meeroslav April 22, 2024 16:10
Copy link

vercel bot commented Apr 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview Apr 23, 2024 10:18am

Comment on lines 46 to 50
if (configDir !== '.' && configDir !== dirname(configFilePath)) {
filesToExclude.push(`${configDir}/**/*`);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe there's a possibility where a parent configDir of the configFilePath will get added to the filesToExclude paths. This would ignore everything including the files in the directory as well.

If configFiles is for libs/a/.eslintrc.json

[
  `.eslintrc.json`, // This isn't added because it's the root...
  `libs/.eslintrc.json`, // This one does get added...
  `libs/a/`.eslintrc.json`, // This is the actual config file.
]

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! I only need to ignore the nested ones. I'll amend it and add tests to cover that.

Comment on lines -66 to -69
const lintableFiles = globWithWorkspaceContext(context.workspaceRoot, [
join(dir, `**/*.{${options.extensions.join(',')}}`),
]);
return lintableFiles.length > 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

So this never handled if there were lintable files.. but they were all under a child config path right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Exactly. It never handled the ESLint ignored file configuration. It did glob for children with specific file extensions, which might or might not have been lintable for the project.

Comment on lines +183 to +177
...(existsSync(join(workspaceRoot, projectRoot, '.eslintignore'))
? ['{projectRoot}/.eslintignore']
: []),
Copy link
Collaborator

Choose a reason for hiding this comment

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

This includes proj/.eslintignore as an input?

Should it also include anything in a parent directory.. as well as anything in a child directory?

Copy link
Member Author

Choose a reason for hiding this comment

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

Only the .eslintignore file at the project root (cwd) applies (https://eslint.org/docs/latest/use/configure/ignore-deprecated#the-eslintignore-file). Other .eslintignore are not used by ESLint.

@leosvelperez leosvelperez force-pushed the eslint/plugin-respect-ignored-files branch from 78abcf8 to 088b594 Compare April 23, 2024 10:16
Comment on lines +81 to +86
for (const file of lintableFiles) {
if (!(await eslint.isPathIgnored(join(context.workspaceRoot, file)))) {
childProjectRoots.add(childProjectRoot);
break;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should probably use a Promise.all here. But you can address it in a followup PR.

].map((f) => join(configDir, f)),
nestedEslintRootPatterns.length ? nestedEslintRootPatterns : undefined
);
for (const projectFile of projectFiles) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This loop could also be a Promise.all

@FrozenPandaz FrozenPandaz merged commit 1e4324f into nrwl:master Apr 23, 2024
6 checks passed
@leosvelperez leosvelperez deleted the eslint/plugin-respect-ignored-files branch April 24, 2024 08:43
FrozenPandaz pushed a commit that referenced this pull request Apr 25, 2024
Copy link

github-actions bot commented May 1, 2024

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants