[英]Webpack 2 eslint-loader auto fix
在 webpack 1.x 中,我可以在我的 webpack 配置中使用 eslint 属性来启用自动修复我的 linting 错误,方法是:
...
module.exports = {
devtool: 'source-map',
entry: './src/app.js',
eslint: {
configFile: '.eslintrc',
fix: true
},
...
然而,在 webpack 2.x 中,到目前为止我一直无法使用自动修复功能,因为我不知道在我的 webpack 配置中设置它的位置。 在我的 webpack configFile 中使用 eslint 属性会引发WebpackOptionsValidationError
。
使用webpack v2 (及更高版本) 自动修复linting规则的最常用方法是使用eslint-loader
。
在你的webpack.config.js
你会这样做:
module.exports = {
// ...
module: {
rules: [
{
test: /\.jsx?$/, // both .js and .jsx
loader: 'eslint-loader',
include: path.resolve(process.cwd(), 'src'),
enforce: 'pre',
options: {
fix: true,
},
},
// ...
],
},
// ...
};
带有 eslint-webpack-plugin 的 Webpack 5:
const ESLintPlugin = require('eslint-webpack-plugin');
....
plugins: [
...
new ESLintPlugin({fix: true}),
...
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.