Skip to content

Commit

Permalink
Fix: Warning behavior for executeOnText (fixes #6611) (#6632)
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas authored and gyandeeps committed Jul 8, 2016
1 parent e6004be commit baeb313
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
7 changes: 5 additions & 2 deletions lib/cli-engine.js
Expand Up @@ -742,8 +742,11 @@ CLIEngine.prototype = {
if (filename && !path.isAbsolute(filename)) {
filename = path.resolve(options.cwd, filename);
}
if (filename && warnIgnored && ignoredPaths.contains(filename)) {
results.push(createIgnoreResult(filename, options.cwd));

if (filename && ignoredPaths.contains(filename)) {
if (warnIgnored) {
results.push(createIgnoreResult(filename, options.cwd));
}
} else {
results.push(processText(text, configHelper, filename, options.fix, options.allowInlineConfig));
}
Expand Down
20 changes: 16 additions & 4 deletions tests/lib/cli-engine.js
Expand Up @@ -148,7 +148,7 @@ describe("CLIEngine", function() {
assert.equal(report.results[0].filePath, getFixturePath("test.js"));
});

it("should return a warning when given a filename by --stdin-filename in excluded files list if warnIgnored is set", function() {
it("should return a warning when given a filename by --stdin-filename in excluded files list if warnIgnored is true", function() {
engine = new CLIEngine({
ignorePath: getFixturePath(".eslintignore"),
cwd: getFixturePath("..")
Expand All @@ -167,6 +167,19 @@ describe("CLIEngine", function() {
assert.equal(report.results[0].warningCount, 1);
});

it("should not return a warning when given a filename by --stdin-filename in excluded files list if warnIgnored is false", function() {
engine = new CLIEngine({
ignorePath: getFixturePath(".eslintignore"),
cwd: getFixturePath("..")
});

// intentional parsing error
var report = engine.executeOnText("va r bar = foo;", "fixtures/passing.js", false);

// should not report anything because the file is ignored
assert.equal(report.results.length, 0);
});

it("should suppress excluded file warnings by default", function() {
engine = new CLIEngine({
ignorePath: getFixturePath(".eslintignore"),
Expand All @@ -175,9 +188,8 @@ describe("CLIEngine", function() {

var report = engine.executeOnText("var bar = foo;", "fixtures/passing.js");

assert.equal(report.results.length, 1);
assert.equal(report.results[0].errorCount, 0);
assert.equal(report.results[0].warningCount, 0);
// should not report anything because there are no errors
assert.equal(report.results.length, 0);
});

it("should return a message when given a filename by --stdin-filename in excluded files list and ignore is off", function() {
Expand Down

0 comments on commit baeb313

Please sign in to comment.