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

 respect userOptions.eslintPath #195

Merged
merged 1 commit into from
Feb 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,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` .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you are trying to explain here. Can you help me to understand so we can put a better explanation?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, when someone specify the eslintPath,often means he want use another version of eslint or the eslint under other node_modules.
so he doesn't want to install eslint again in current project/node_modules


```js
module.exports = {
Expand All @@ -171,7 +172,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(this)
)

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this require("eslint/lib/formatters/stylish") redundant given the one in the try-catch below?


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)
}