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

Commit 3c1c296

Browse files
lmnhotMoOx
authored andcommitted
Respect userOptions.eslintPath (#195)
if them specify an eslintPath option, and it like a officer eslint folder. he dont have to install the eslint.
1 parent 7e3c75b commit 3c1c296

File tree

5 files changed

+21
-5
lines changed

5 files changed

+21
-5
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ module.exports = {
153153

154154
#### `eslintPath` (default: "eslint")
155155

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

158159
```js
159160
module.exports = {
@@ -165,7 +166,7 @@ module.exports = {
165166
exclude: /node_modules/,
166167
loader: "eslint-loader",
167168
options: {
168-
eslintPath: path.join(__dirname, "reusable-eslint-rules.js"),
169+
eslintPath: path.join(__dirname, "reusable-eslint"),
169170
}
170171
},
171172
],

index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,25 @@ module.exports = function(input, map) {
150150
loaderUtils.getOptions(webpack)
151151
)
152152

153+
var userEslintPath = userOptions.eslintPath
154+
var formatter = require("eslint/lib/formatters/stylish")
155+
156+
if (userEslintPath) {
157+
try {
158+
formatter = require(userEslintPath + "/lib/formatters/stylish")
159+
}
160+
catch (e) {
161+
formatter = require("eslint/lib/formatters/stylish")
162+
}
163+
}
164+
153165
var config = assign(
154166
// loader defaults
155167
{
156-
formatter: require("eslint/lib/formatters/stylish"),
168+
formatter: formatter,
157169
cacheIdentifier: JSON.stringify({
158170
"eslint-loader": pkg.version,
159-
eslint: require(userOptions.eslintPath || "eslint").version,
171+
eslint: require(userEslintPath || "eslint").version,
160172
}),
161173
eslintPath: "eslint",
162174
},

test/eslint-path.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test.cb("eslint-loader can use another instance of eslint via " +
1111
entry: "./test/fixtures/good.js",
1212
},
1313
{
14-
eslintPath: path.join(__dirname, "mock/eslint-mock.js"),
14+
eslintPath: path.join(__dirname, "mock/eslint"),
1515
}
1616
),
1717
function(err, stats) {
File renamed without changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = function(result) {
2+
return JSON.stringify(result)
3+
}

0 commit comments

Comments
 (0)