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: incorrect warning message for ignored dotfiles #17196

Merged
merged 1 commit into from May 19, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 1 addition & 5 deletions lib/eslint/eslint-helpers.js
Expand Up @@ -591,13 +591,9 @@ function isErrorMessage(message) {
*/
function createIgnoreResult(filePath, baseDir) {
let message;
const isHidden = filePath.split(path.sep)
.find(segment => /^\./u.test(segment));
const isInNodeModules = baseDir && path.relative(baseDir, filePath).startsWith("node_modules");

if (isHidden) {
message = "File ignored by default. Use a negated ignore pattern (like \"--ignore-pattern '!<relative/path/to/filename>'\") to override.";
} else if (isInNodeModules) {
if (isInNodeModules) {
message = "File ignored by default because it is located under the node_modules directory. Use ignore pattern \"!**/node_modules/\" to override.";
} else {
message = "File ignored because of a matching ignore pattern. Use \"--no-ignore\" to override.";
Expand Down
20 changes: 20 additions & 0 deletions tests/lib/eslint/flat-eslint.js
Expand Up @@ -1340,6 +1340,26 @@ describe("FlatESLint", () => {
assert.strictEqual(results[0].suppressedMessages.length, 0);
});

it("should return a warning about matching ignore patterns when an explicitly given dotfile is ignored", async () => {
eslint = new FlatESLint({
overrideConfigFile: "eslint.config_with_ignores.js",
cwd: getFixturePath()
});
const filePath = getFixturePath("dot-files/.a.js");
const results = await eslint.lintFiles([filePath]);

assert.strictEqual(results.length, 1);
assert.strictEqual(results[0].filePath, filePath);
assert.strictEqual(results[0].messages[0].severity, 1);
assert.strictEqual(results[0].messages[0].message, "File ignored because of a matching ignore pattern. Use \"--no-ignore\" to override.");
assert.strictEqual(results[0].errorCount, 0);
assert.strictEqual(results[0].warningCount, 1);
assert.strictEqual(results[0].fatalErrorCount, 0);
assert.strictEqual(results[0].fixableErrorCount, 0);
assert.strictEqual(results[0].fixableWarningCount, 0);
assert.strictEqual(results[0].suppressedMessages.length, 0);
});

it("should return two messages when given a file in excluded files list while ignore is off", async () => {
eslint = new FlatESLint({
cwd: getFixturePath(),
Expand Down