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

Commit d763726

Browse files
eschablowskiThomasKientz
authored andcommitted
Fix autofix for eslint < 5 (#262)
1 parent f9d48ea commit d763726

File tree

2 files changed

+64
-57
lines changed

2 files changed

+64
-57
lines changed

README.md

+52-55
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ module.exports = {
3030
options: {
3131
// eslint options (if necessary)
3232
}
33-
},
34-
],
35-
},
33+
}
34+
]
35+
}
3636
// ...
37-
}
37+
};
3838
```
3939

4040
When using with transpiling loaders (like `babel-loader`), make sure they are in correct order
@@ -48,15 +48,12 @@ module.exports = {
4848
{
4949
test: /\.js$/,
5050
exclude: /node_modules/,
51-
use: [
52-
"babel-loader",
53-
"eslint-loader",
54-
],
55-
},
56-
],
57-
},
51+
use: ["babel-loader", "eslint-loader"]
52+
}
53+
]
54+
}
5855
// ...
59-
}
56+
};
6057
```
6158

6259
To be safe, you can use `enforce: "pre"` section to check source files, not modified
@@ -71,17 +68,17 @@ module.exports = {
7168
enforce: "pre",
7269
test: /\.js$/,
7370
exclude: /node_modules/,
74-
loader: "eslint-loader",
71+
loader: "eslint-loader"
7572
},
7673
{
7774
test: /\.js$/,
7875
exclude: /node_modules/,
79-
loader: "babel-loader",
80-
},
81-
],
82-
},
76+
loader: "babel-loader"
77+
}
78+
]
79+
}
8380
// ...
84-
}
81+
};
8582
```
8683

8784
### Options
@@ -141,19 +138,19 @@ module.exports = {
141138

142139
// you should return a string
143140
// DO NOT USE console.*() directly !
144-
return "OUTPUT"
141+
return "OUTPUT";
145142
}
146143
}
147-
},
148-
],
149-
},
150-
}
144+
}
145+
]
146+
}
147+
};
151148
```
152149

153150
#### `eslintPath` (default: "eslint")
154151

155152
Path to `eslint` instance that will be used for linting.
156-
If the `eslintPath` is a folder like a official eslint, or specify a `formatter` option. now you dont have to install `eslint` .
153+
If the `eslintPath` is a folder like a official eslint, or specify a `formatter` option. now you dont have to install `eslint` .
157154

158155
```js
159156
module.exports = {
@@ -165,12 +162,12 @@ module.exports = {
165162
exclude: /node_modules/,
166163
loader: "eslint-loader",
167164
options: {
168-
eslintPath: path.join(__dirname, "reusable-eslint"),
165+
eslintPath: path.join(__dirname, "reusable-eslint")
169166
}
170-
},
171-
],
172-
},
167+
}
168+
]
173169
}
170+
};
174171
```
175172

176173
#### Errors and Warning
@@ -193,12 +190,12 @@ module.exports = {
193190
exclude: /node_modules/,
194191
loader: "eslint-loader",
195192
options: {
196-
emitError: true,
193+
emitError: true
197194
}
198-
},
199-
],
200-
},
201-
}
195+
}
196+
]
197+
}
198+
};
202199
```
203200

204201
##### `emitWarning` (default: `false`)
@@ -219,12 +216,12 @@ module.exports = {
219216
exclude: /node_modules/,
220217
loader: "eslint-loader",
221218
options: {
222-
quiet: true,
219+
quiet: true
223220
}
224-
},
225-
],
226-
},
227-
}
221+
}
222+
]
223+
}
224+
};
228225
```
229226

230227
##### `failOnWarning` (default: `false`)
@@ -241,12 +238,12 @@ module.exports = {
241238
exclude: /node_modules/,
242239
loader: "eslint-loader",
243240
options: {
244-
failOnWarning: true,
241+
failOnWarning: true
245242
}
246-
},
247-
],
248-
},
249-
}
243+
}
244+
]
245+
}
246+
};
250247
```
251248

252249
##### `failOnError` (default: `false`)
@@ -263,15 +260,16 @@ module.exports = {
263260
exclude: /node_modules/,
264261
loader: "eslint-loader",
265262
options: {
266-
failOnError: true,
263+
failOnError: true
267264
}
268-
},
269-
],
270-
},
271-
}
265+
}
266+
]
267+
}
268+
};
272269
```
273270

274271
##### `outputReport` (default: `false`)
272+
275273
Write the output of the errors to a file, for example a checkstyle xml file for use for reporting on Jenkins CI
276274

277275
The `filePath` is relative to the webpack config: output.path
@@ -288,17 +286,16 @@ module.exports = {
288286
loader: "eslint-loader",
289287
options: {
290288
outputReport: {
291-
filePath: 'checkstyle.xml',
292-
formatter: require('eslint/lib/formatters/checkstyle')
289+
filePath: "checkstyle.xml",
290+
formatter: require("eslint/lib/formatters/checkstyle")
293291
}
294292
}
295-
},
296-
],
297-
},
298-
}
293+
}
294+
]
295+
}
296+
};
299297
```
300298

301-
302299
## Gotchas
303300

304301
### NoErrorsPlugin

index.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22

3+
//var fs = require("fs");
34
var assign = require("object-assign");
45
var loaderUtils = require("loader-utils");
56
var objectHash = require("object-hash");
@@ -70,7 +71,12 @@ function printLinterOutput(res, config, webpack) {
7071
}
7172

7273
// if enabled, use eslint auto-fixing where possible
73-
if (config.fix && (res.results[0].fixableErrorCount > 0 || res.results[0].fixableWarningCount)) {
74+
if (
75+
config.fix &&
76+
(res.results[0].output !== res.src ||
77+
res.results[0].fixableErrorCount > 0 ||
78+
res.results[0].fixableWarningCount > 0)
79+
) {
7480
var eslint = require(config.eslintPath);
7581
eslint.CLIEngine.outputFixes(res);
7682
}
@@ -237,7 +243,11 @@ module.exports = function(input, map) {
237243
}
238244

239245
try {
240-
printLinterOutput(res || {}, config, webpack);
246+
printLinterOutput(
247+
assign({}, res || {}, { src: input }),
248+
config,
249+
webpack
250+
);
241251
} catch (e) {
242252
err = e;
243253
}

0 commit comments

Comments
 (0)