Skip to content
This repository has been archived by the owner on Sep 28, 2020. It is now read-only.

Commit

Permalink
Stop fixing loop (#244)
Browse files Browse the repository at this point in the history
* Stop Fixing if there are no fixable errors or warnings

* Update README.md

* Added Tests for infinte loop

* Fix Typo
  • Loading branch information
eschablowski authored and MoOx committed Sep 19, 2018
1 parent 7108379 commit 7040248
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
3 changes: 1 addition & 2 deletions README.md
Expand Up @@ -98,8 +98,7 @@ See the [eslint docs](http://eslint.org/docs/developer-guide/nodejs-api#cliengin
This option will enable
[ESLint autofix feature](http://eslint.org/docs/user-guide/command-line-interface#fix).

**Be careful: this option might cause webpack to enter an infinite build loop if
some issues cannot be fixed properly.**
**Be careful: this option will change source files.**

#### `cache` (default: false)

Expand Down
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -70,7 +70,7 @@ function printLinterOutput(res, config, webpack) {
}

// if enabled, use eslint auto-fixing where possible
if (config.fix && res.results[0].output) {
if (config.fix && (res.results[0].fixableErrorCount > 0 || res.results[0].fixableWarningCount)) {
var eslint = require(config.eslintPath);
eslint.CLIEngine.outputFixes(res);
}
Expand Down
56 changes: 56 additions & 0 deletions test/autofix-stop.js
@@ -0,0 +1,56 @@
var fs = require("fs");

var test = require("ava");
var webpack = require("webpack");

var conf = require("./utils/conf");

var changed = false;

// clone the "fixable" file, so that we do not lose the original contents
// when the fixes are applied to disk
test.before(function() {
fs.createReadStream("./test/fixtures/nonfixable.js")
.pipe(fs.createWriteStream("./test/fixtures/nonfixable-clone.js"))
.on("close", function() {
fs.watch("./test/fixtures/nonfixable-clone.js", function() {
changed = true;
});
});
});

test.cb("loader shouldn't change file if there are no fixable errors/warnings", function(
t
) {
t.plan(1);
webpack(
conf({
entry: "./test/fixtures/nonfixable-clone.js",
module: {
rules: [
{
test: /\.js$/,
use: "./index?fix=true",
exclude: /node_modules/
}
]
}
}),
function(err) {
if (err) {
throw err;
}
// console.log(stats.compilation.errors)
t.false(
changed,
"should not output to file again (triggering a recompile)"
);
t.end();
}
);
});

// remove the clone
test.after.always(function() {
fs.unlinkSync("./test/fixtures/nonfixable-clone.js");
});
5 changes: 5 additions & 0 deletions test/fixtures/nonfixable.js
@@ -0,0 +1,5 @@
function foo() {
return stuff;
}

foo();

0 comments on commit 7040248

Please sign in to comment.