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

Commit

Permalink
Respect userOptions.eslintPath (#195)
Browse files Browse the repository at this point in the history
if them specify an eslintPath option, and it like a officer eslint folder. he dont have to install the eslint.
  • Loading branch information
lmnsg authored and MoOx committed Feb 26, 2018
1 parent 7e3c75b commit 3c1c296
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ module.exports = {

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

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

```js
module.exports = {
Expand All @@ -165,7 +166,7 @@ module.exports = {
exclude: /node_modules/,
loader: "eslint-loader",
options: {
eslintPath: path.join(__dirname, "reusable-eslint-rules.js"),
eslintPath: path.join(__dirname, "reusable-eslint"),
}
},
],
Expand Down
16 changes: 14 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,25 @@ module.exports = function(input, map) {
loaderUtils.getOptions(webpack)
)

var userEslintPath = userOptions.eslintPath
var formatter = require("eslint/lib/formatters/stylish")

if (userEslintPath) {
try {
formatter = require(userEslintPath + "/lib/formatters/stylish")
}
catch (e) {
formatter = require("eslint/lib/formatters/stylish")
}
}

var config = assign(
// loader defaults
{
formatter: require("eslint/lib/formatters/stylish"),
formatter: formatter,
cacheIdentifier: JSON.stringify({
"eslint-loader": pkg.version,
eslint: require(userOptions.eslintPath || "eslint").version,
eslint: require(userEslintPath || "eslint").version,
}),
eslintPath: "eslint",
},
Expand Down
2 changes: 1 addition & 1 deletion test/eslint-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test.cb("eslint-loader can use another instance of eslint via " +
entry: "./test/fixtures/good.js",
},
{
eslintPath: path.join(__dirname, "mock/eslint-mock.js"),
eslintPath: path.join(__dirname, "mock/eslint"),
}
),
function(err, stats) {
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions test/mock/eslint/lib/formatters/stylish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function(result) {
return JSON.stringify(result)
}

0 comments on commit 3c1c296

Please sign in to comment.