From f8308f265d0e4420bfb8b6290e0fbe3e2f1ede20 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Mon, 25 Apr 2016 21:35:52 -0400 Subject: [PATCH] Base ignore message on type of ignore --- lib/cli-engine.js | 25 +++++++++++++++++++------ tests/lib/cli-engine.js | 12 ++++++++---- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/lib/cli-engine.js b/lib/cli-engine.js index bae03f414c3..a54cfebd214 100644 --- a/lib/cli-engine.js +++ b/lib/cli-engine.js @@ -300,18 +300,31 @@ function processFile(filename, configHelper, options) { /** * Returns result with warning by ignore settings - * @param {string} filePath File path of checked code - * @returns {Result} Result with single warning + * @param {string} filePath - File path of checked code + * @param {string} baseDir - Absolute path of base directory + * @returns {Result} Result with single warning * @private */ -function createIgnoreResult(filePath) { +function createIgnoreResult(filePath, baseDir) { + var message; + + if (/^\./.test(path.basename(filePath))) { + message = "Hidden file ignored by default. Use '--ignore-pattern !.*' to override."; + } else if (baseDir && /^node_modules/.test(path.relative(baseDir, filePath))) { + message = "File ignored by default. Use '--ignore-pattern !node_modules/*' to override."; + } else if (baseDir && /^bower_components/.test(path.relative(baseDir, filePath))) { + message = "File ignored by default. Use '--ignore-pattern !bower_components/*' to override."; + } else { + message = "File ignored because of a matching ignore pattern. Use --no-ignore to override."; + } + return { filePath: path.resolve(filePath), messages: [ { fatal: false, severity: 1, - message: "File ignored because of a matching ignore pattern. Use --no-ignore to override." + message: message } ], errorCount: 0, @@ -612,7 +625,7 @@ CLIEngine.prototype = { var hashOfConfig; if (warnIgnored) { - results.push(createIgnoreResult(filename)); + results.push(createIgnoreResult(filename, options.cwd)); return; } @@ -734,7 +747,7 @@ CLIEngine.prototype = { } if (filename && ignoredPaths.contains(filename)) { - results.push(createIgnoreResult(filename)); + results.push(createIgnoreResult(filename, options.cwd)); } else { results.push(processText(text, configHelper, filename, options.fix, options.allowInlineConfig)); } diff --git a/tests/lib/cli-engine.js b/tests/lib/cli-engine.js index bf6d7636cbb..dac0fb464ca 100644 --- a/tests/lib/cli-engine.js +++ b/tests/lib/cli-engine.js @@ -261,10 +261,11 @@ describe("CLIEngine", function() { }); var report = engine.executeOnText("var bar = foo;", "node_modules/passing.js"); + var expectedMsg = "File ignored by default. Use \'--ignore-pattern !node_modules/*\' to override."; assert.equal(report.results.length, 1); assert.equal(report.results[0].filePath, getFixturePath("node_modules/passing.js")); - assert.equal(report.results[0].messages[0].message, "File ignored because of a matching ignore pattern. Use --no-ignore to override."); + assert.equal(report.results[0].messages[0].message, expectedMsg); }); }); @@ -391,11 +392,12 @@ describe("CLIEngine", function() { }); var report = engine.executeOnFiles(["node_modules/foo.js"]); + var expectedMsg = "File ignored by default. Use \'--ignore-pattern !node_modules/*\' to override."; assert.equal(report.results.length, 1); assert.equal(report.results[0].errorCount, 0); assert.equal(report.results[0].warningCount, 1); - assert.equal(report.results[0].messages[0].message, "File ignored because of a matching ignore pattern. Use --no-ignore to override."); + assert.equal(report.results[0].messages[0].message, expectedMsg); }); it("should not check default ignored files without --no-ignore flag", function() { @@ -433,11 +435,12 @@ describe("CLIEngine", function() { }); var report = engine.executeOnFiles(["fixtures/files/.bar.js"]); + var expectedMsg = "Hidden file ignored by default. Use \'--ignore-pattern !.*\' to override."; assert.equal(report.results.length, 1); assert.equal(report.results[0].errorCount, 0); assert.equal(report.results[0].warningCount, 1); - assert.equal(report.results[0].messages[0].message, "File ignored because of a matching ignore pattern. Use --no-ignore to override."); + assert.equal(report.results[0].messages[0].message, expectedMsg); }); it("should check .hidden files if they are passed explicitly with --no-ignore flag", function() { @@ -672,7 +675,8 @@ describe("CLIEngine", function() { it("should return a warning when an explicitly given file is ignored", function() { engine = new CLIEngine({ - ignorePath: getFixturePath(".eslintignore") + ignorePath: getFixturePath(".eslintignore"), + cwd: getFixturePath() }); var filePath = getFixturePath("passing.js");