diff --git a/README.md b/README.md index 9da7bbb..9b493c5 100644 --- a/README.md +++ b/README.md @@ -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` . ```js module.exports = { @@ -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"), } }, ], diff --git a/index.js b/index.js index cbb8536..d620c29 100644 --- a/index.js +++ b/index.js @@ -150,13 +150,25 @@ module.exports = function(input, map) { loaderUtils.getOptions(this) ) + 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", }, diff --git a/test/eslint-path.js b/test/eslint-path.js index d2550ad..741bead 100644 --- a/test/eslint-path.js +++ b/test/eslint-path.js @@ -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) { diff --git a/test/mock/eslint-mock.js b/test/mock/eslint/index.js similarity index 100% rename from test/mock/eslint-mock.js rename to test/mock/eslint/index.js diff --git a/test/mock/eslint/lib/formatters/stylish.js b/test/mock/eslint/lib/formatters/stylish.js new file mode 100644 index 0000000..b01be9e --- /dev/null +++ b/test/mock/eslint/lib/formatters/stylish.js @@ -0,0 +1,3 @@ +module.exports = function(result) { + return JSON.stringify(result) +}