Skip to content

Commit

Permalink
Merge remote-tracking branch 'MoOx/master' into interpolate_outputReport
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
deryni committed Dec 15, 2016
2 parents 4f05036 + dcdb4ad commit def7886
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.6.1 - 2016-11-02

- Fixed: multiples config per instance are now supported
([#105](https://github.com/MoOx/eslint-loader/issues/105) -
@jaythomas and @jameslnewell)

# 1.6.0 - 2016-10-17

- Added: Option to generate report file
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module.exports = {
}
```

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

```js
Expand Down Expand Up @@ -100,14 +100,16 @@ module.exports = {
}
```

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.

**Note that you can use both methods in order to benefit from global & specific options**

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

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
**Be careful: this option might cause webpack to enter an infinite build loop if
some issues cannot be fixed properly.**

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

### Defining `configFile` or using `eslint -c path/.eslintrc`

Bear in mind that when you define `configFile`, `eslint` doesn't automatically look for
`.eslintrc` files in the directory of the file to be linted. More information is available
in official eslint documentation in section [_Using Configuration Files_](http://eslint.org/docs/user-guide/configuring#using-configuration-files).

Related issues: [#129](https://github.com/MoOx/eslint-loader/issues/129).

## [Changelog](CHANGELOG.md)

## [License](LICENSE)
13 changes: 8 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ var loaderUtils = require("loader-utils")
var crypto = require("crypto")
var fs = require("fs")
var findCacheDir = require("find-cache-dir")
var objectHash = require("object-hash")

var engine = null
var engines = {}
var cache = null
var cachePath = null

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

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

// Save new results in the cache
if (config.cache) {
Expand Down Expand Up @@ -152,9 +154,10 @@ module.exports = function(input, map) {
)
this.cacheable()

// Create the engine only once
if (engine === null) {
engine = new eslint.CLIEngine(config)
// Create the engine only once per config
var configHash = objectHash(config)
if (!engines[configHash]) {
engines[configHash] = new eslint.CLIEngine(config)
}

// Read the cached information only once and if enable
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-loader",
"version": "1.6.0",
"version": "1.6.1",
"description": "eslint loader (for webpack)",
"keywords": [
"lint",
Expand All @@ -21,7 +21,8 @@
"dependencies": {
"find-cache-dir": "^0.1.1",
"loader-utils": "^0.2.7",
"object-assign": "^4.0.1"
"object-assign": "^4.0.1",
"object-hash": "^1.1.4"
},
"devDependencies": {
"eslint": "^3.0.0",
Expand Down
59 changes: 59 additions & 0 deletions test/multiple-engines.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
var test = require("tape")
var webpack = require("webpack")
var assign = require("object-assign")
var conf = require("./utils/conf")

test("eslint-loader will create an engine for each unique config", function(t) { // eslint-disable-line max-len
webpack(assign({},
conf,
{
entry: "./test/fixtures/good.js",
module: {
loaders: [
{
test: /\.js$/,
loader: "./index",
query: {
rules: {
quotes: [1, "single"],
},
},
exclude: /node_modules/,
},
{
test: /\.js$/,
loader: "./index",
query: {
rules: {
semi: [1, "always"],
},
},
exclude: /node_modules/,
},
],
},
}
),
function(err, stats) {
if (err) {
throw err
}

t.ok(
stats.compilation.warnings.length === 2,
"should report an error for each config"
)

t.ok(
stats.compilation.warnings.find(warning => /quotes/.test(warning)),
"should have a warning about quotes"
)

t.ok(
stats.compilation.warnings.find(warning => /semi/.test(warning)),
"should have a warning about semi"
)

t.end()
})
})

0 comments on commit def7886

Please sign in to comment.