Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix: Change error message logic for implicit file ignore (fixes #12873)…
… (#12878)
  • Loading branch information
snhardin committed Mar 28, 2020
1 parent eb1a43c commit 29f32db
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/cli-engine/cli-engine.js
Expand Up @@ -276,7 +276,8 @@ function verifyText({
*/
function createIgnoreResult(filePath, baseDir) {
let message;
const isHidden = /^\./u.test(path.basename(filePath));
const isHidden = filePath.split(path.sep)
.find(segment => /^\./u.test(segment));
const isInNodeModules = baseDir && path.relative(baseDir, filePath).startsWith("node_modules");

if (isHidden) {
Expand Down
21 changes: 21 additions & 0 deletions tests/lib/cli-engine/cli-engine.js
Expand Up @@ -1005,6 +1005,27 @@ describe("CLIEngine", () => {
assert.strictEqual(report.results[0].messages[0].message, expectedMsg);
});

// https://github.com/eslint/eslint/issues/12873
it("should not check files within a .hidden folder if they are passed explicitly without the --no-ignore flag", () => {
engine = new CLIEngine({
cwd: getFixturePath("cli-engine"),
useEslintrc: false,
rules: {
quotes: [2, "single"]
}
});

const report = engine.executeOnFiles(["hidden/.hiddenfolder/double-quotes.js"]);
const expectedMsg = "File ignored by default. Use a negated ignore pattern (like \"--ignore-pattern '!<relative/path/to/filename>'\") to override.";

assert.strictEqual(report.results.length, 1);
assert.strictEqual(report.results[0].errorCount, 0);
assert.strictEqual(report.results[0].warningCount, 1);
assert.strictEqual(report.results[0].fixableErrorCount, 0);
assert.strictEqual(report.results[0].fixableWarningCount, 0);
assert.strictEqual(report.results[0].messages[0].message, expectedMsg);
});

it("should check .hidden files if they are passed explicitly with --no-ignore flag", () => {

engine = new CLIEngine({
Expand Down

0 comments on commit 29f32db

Please sign in to comment.