Skip to content

Commit

Permalink
fix: incorrect warning message for ignored dotfiles (#17196)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic authored May 19, 2023
1 parent ddc5291 commit 4f5440d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
6 changes: 1 addition & 5 deletions lib/eslint/eslint-helpers.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 4f5440d

Please sign in to comment.