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

Commit

Permalink
Fixed: multiples config per instance are now supported (#123)
Browse files Browse the repository at this point in the history
Closes #105
  • Loading branch information
jameslnewell authored and MoOx committed Nov 2, 2016
1 parent 570730c commit 672a100
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
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 @@ -149,9 +151,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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.only("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 672a100

Please sign in to comment.