Skip to content

Commit

Permalink
Base ignore message on type of ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
IanVS committed Apr 26, 2016
1 parent 0e13b3c commit f8308f2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
25 changes: 19 additions & 6 deletions lib/cli-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -612,7 +625,7 @@ CLIEngine.prototype = {
var hashOfConfig;

if (warnIgnored) {
results.push(createIgnoreResult(filename));
results.push(createIgnoreResult(filename, options.cwd));
return;
}

Expand Down Expand Up @@ -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));
}
Expand Down
12 changes: 8 additions & 4 deletions tests/lib/cli-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

});
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit f8308f2

Please sign in to comment.