eslint loader for webpack
$ npm install eslint-loader
In your webpack configuration
module.exports = {
// ...
module: {
loaders: [
{test: /\.js$/, loader: "eslint-loader", exclude: /node_modules/}
]
}
// ...
}
You can pass directly some eslint options by
- Adding a query string to the loader for this loader usabe only
{
module: {
loaders: [
{
test: /\.js$/,
loader: "eslint-loader?{rules:[{semi:0}]}",
exclude: /node_modules/,
},
],
},
}
- Adding an
eslint
entry in you webpack config for global options:
module.exports = {
eslint: {
configFile: 'path/.eslintrc'
}
}
Note that you can use both method in order to benefit from global & specific options
Loader accepts a function that will have one argument: an array of eslint messages (object). The function must return the output as a string. You can use official eslint formatters.
module.exports = {
entry: "...",
module: {
// ...
}
eslint: {
// several examples !
// default value
formatter: require("eslint/lib/formatters/stylish"),
// community formatter
formatter: require("eslint-friendly-formatter"),
// custom formatter
formatter: function(results) {
// `results` format is available here
// http://eslint.org/docs/developer-guide/nodejs-api.html#executeonfiles()
// you should return a string
// DO NOT USE console.*() directly !
return "OUTPUT"
}
}
}
By default the loader will auto adjust error reporting depending
on eslint errors/warnings counts.
You can still force this behavior by using emitError
or emitWarning
options:
Loader will always returns errors if this option is set to true
.
module.exports = {
entry: "...",
module: {
// ...
}
eslint: {
emitErrors: true
}
}
Loader will always returns warning if option is set to true
.
Loader will process and report errors only and ignore warnings if this option is set to true
module.exports = {
entry: "...",
module: {
// ...
}
eslint: {
quiet: true
}
}
Loader will cause the module build to fail if there are any eslint warnings.
module.exports = {
entry: "...",
module: {
// ...
}
eslint: {
failOnWarning: true
}
}
Loader will cause the module build to fail if there are any eslint errors.
module.exports = {
entry: "...",
module: {
// ...
}
eslint: {
failOnError: true
}
}