Skip to content

Commit def7886

Browse files
committed
Merge remote-tracking branch 'MoOx/master' into interpolate_outputReport
* MoOx/master: README: Add information about eslint behaviour when configFile is set directly (webpack-contrib#129) (webpack-contrib#130) Add clarifying note to README (webpack-contrib#127) Removed test.only so that all tests will run (webpack-contrib#125) 1.6.1 Fixed: multiples config per instance are now supported (webpack-contrib#123)
2 parents 4f05036 + dcdb4ad commit def7886

File tree

5 files changed

+88
-9
lines changed

5 files changed

+88
-9
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 1.6.1 - 2016-11-02
2+
3+
- Fixed: multiples config per instance are now supported
4+
([#105](https://github.com/MoOx/eslint-loader/issues/105) -
5+
@jaythomas and @jameslnewell)
6+
17
# 1.6.0 - 2016-10-17
28

39
- Added: Option to generate report file

README.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ module.exports = {
5454
}
5555
```
5656

57-
[[email protected] has breaking changes](https://github.com/webpack/webpack/releases).
57+
[[email protected] has breaking changes](https://github.com/webpack/webpack/releases).
5858
`preLoaders` is removed from the webpack^2.1.0-beta.23. so move it to `loaders` and using [enforce: "pre"] instead.
5959

6060
```js
@@ -100,14 +100,16 @@ module.exports = {
100100
}
101101
```
102102

103+
Note that the config option you provide will be passed to the `CLIEngine`. This is a different set of options than what you'd specify in `package.json` or `.eslintrc`. See the [eslint docs](http://eslint.org/docs/developer-guide/nodejs-api#cliengine) for more detail.
104+
103105
**Note that you can use both methods in order to benefit from global & specific options**
104106

105107
#### `fix` (default: false)
106108

107109
This option will enable
108110
[ESLint autofix feature](http://eslint.org/docs/user-guide/command-line-interface#fix).
109111

110-
**Be careful, this option might cause webpack to enter an infinite build loop if
112+
**Be careful: this option might cause webpack to enter an infinite build loop if
111113
some issues cannot be fixed properly.**
112114

113115
#### `cache` (default: false)
@@ -258,6 +260,14 @@ will fail the build. No matter what error settings are used for `eslint-loader`.
258260
So if you want to see ESLint warnings in console during development using `WebpackDevServer`
259261
remove `NoErrorsPlugin` from webpack config.
260262

263+
### Defining `configFile` or using `eslint -c path/.eslintrc`
264+
265+
Bear in mind that when you define `configFile`, `eslint` doesn't automatically look for
266+
`.eslintrc` files in the directory of the file to be linted. More information is available
267+
in official eslint documentation in section [_Using Configuration Files_](http://eslint.org/docs/user-guide/configuring#using-configuration-files).
268+
269+
Related issues: [#129](https://github.com/MoOx/eslint-loader/issues/129).
270+
261271
## [Changelog](CHANGELOG.md)
262272

263273
## [License](LICENSE)

index.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ var loaderUtils = require("loader-utils")
44
var crypto = require("crypto")
55
var fs = require("fs")
66
var findCacheDir = require("find-cache-dir")
7+
var objectHash = require("object-hash")
78

8-
var engine = null
9+
var engines = {}
910
var cache = null
1011
var cachePath = null
1112

@@ -39,7 +40,8 @@ function lint(input, config, webpack) {
3940

4041
// Re-lint the text if the cache off or miss
4142
if (!res) {
42-
res = engine.executeOnText(input, resourcePath, true)
43+
var configHash = objectHash(config)
44+
res = engines[configHash].executeOnText(input, resourcePath, true)
4345

4446
// Save new results in the cache
4547
if (config.cache) {
@@ -152,9 +154,10 @@ module.exports = function(input, map) {
152154
)
153155
this.cacheable()
154156

155-
// Create the engine only once
156-
if (engine === null) {
157-
engine = new eslint.CLIEngine(config)
157+
// Create the engine only once per config
158+
var configHash = objectHash(config)
159+
if (!engines[configHash]) {
160+
engines[configHash] = new eslint.CLIEngine(config)
158161
}
159162

160163
// Read the cached information only once and if enable

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-loader",
3-
"version": "1.6.0",
3+
"version": "1.6.1",
44
"description": "eslint loader (for webpack)",
55
"keywords": [
66
"lint",
@@ -21,7 +21,8 @@
2121
"dependencies": {
2222
"find-cache-dir": "^0.1.1",
2323
"loader-utils": "^0.2.7",
24-
"object-assign": "^4.0.1"
24+
"object-assign": "^4.0.1",
25+
"object-hash": "^1.1.4"
2526
},
2627
"devDependencies": {
2728
"eslint": "^3.0.0",

test/multiple-engines.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
var test = require("tape")
2+
var webpack = require("webpack")
3+
var assign = require("object-assign")
4+
var conf = require("./utils/conf")
5+
6+
test("eslint-loader will create an engine for each unique config", function(t) { // eslint-disable-line max-len
7+
webpack(assign({},
8+
conf,
9+
{
10+
entry: "./test/fixtures/good.js",
11+
module: {
12+
loaders: [
13+
{
14+
test: /\.js$/,
15+
loader: "./index",
16+
query: {
17+
rules: {
18+
quotes: [1, "single"],
19+
},
20+
},
21+
exclude: /node_modules/,
22+
},
23+
{
24+
test: /\.js$/,
25+
loader: "./index",
26+
query: {
27+
rules: {
28+
semi: [1, "always"],
29+
},
30+
},
31+
exclude: /node_modules/,
32+
},
33+
],
34+
},
35+
}
36+
),
37+
function(err, stats) {
38+
if (err) {
39+
throw err
40+
}
41+
42+
t.ok(
43+
stats.compilation.warnings.length === 2,
44+
"should report an error for each config"
45+
)
46+
47+
t.ok(
48+
stats.compilation.warnings.find(warning => /quotes/.test(warning)),
49+
"should have a warning about quotes"
50+
)
51+
52+
t.ok(
53+
stats.compilation.warnings.find(warning => /semi/.test(warning)),
54+
"should have a warning about semi"
55+
)
56+
57+
t.end()
58+
})
59+
})

0 commit comments

Comments
 (0)