Webpack 2 eslint加载程序自动修复

Webpack 2 eslint加载程序自动修复,webpack,eslint,webpack-2,Webpack,Eslint,Webpack 2,在webpack 1.x中,我可以在我的webpack配置中使用eslint属性来启用自动修复我的linting错误,方法是: ... module.exports = { devtool: 'source-map', entry: './src/app.js', eslint: { configFile: '.eslintrc', fix: true }, ... 然而,在Webpack2.x中,thusfar我无法使用自动修复功能,因为我不知道在我的We

在webpack 1.x中,我可以在我的webpack配置中使用eslint属性来启用自动修复我的linting错误,方法是:

...

module.exports = {
  devtool: 'source-map',
  entry: './src/app.js',
  eslint: {
    configFile: '.eslintrc',
    fix: true
  },

...
然而,在Webpack2.x中,thusfar我无法使用自动修复功能,因为我不知道在我的WebpackConfig中设置它的位置。在我的webpack配置文件中使用eslint属性会抛出一个
WebpackOptionsValidationError

使用webpack v2(及更高版本)自动修复linting规则的最常见方法是使用

webpack.config.js
中,您将执行以下操作:

module.exports={
// ...
模块:{
规则:[
{
测试://\.jsx?$//,//.js和.jsx
加载程序:“eslint加载程序”,
包括:path.resolve(process.cwd(),'src'),
强制执行:“预”,
选项:{
菲克斯:没错,
},
},
// ...
],
},
// ...
};

谢谢格伦。我在配置中设置了完全相同的规则。除了我使用的是
use:'eslint loader'
而不是
loader:'eslint loader'
。我的印象是这些键具有相同的功能(),但区别在于
use
需要一个数组作为值,
loader
只需要一个字符串。