安装依赖
npm -i eslint eslint-plugin-import eslint-config-airbnb-base
配置webpack.config.js
在webpack.config.js中配置loader
module: {
rules: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
// 自动修复 eslint错误
fix: true,
},
}]
}
配置eslintConfig
在package.json中配置eslintConfig,应用airbnb-base规则
"eslintConfig": {
"extends": "airbnb-base"
}
airbnb-base规则
4.3 Use array spreads … to copy arrays.
const itemsCopy = […items];
4.4 To convert an iterable object to an array, use spreads … instead of Array.from
const foo = document.querySelectorAll(‘.foo’); const nodes = […foo];
4.5 Use Array.from for converting an array-like object to an array.
const arrLike = { 0: ‘foo’, 1: ‘bar’, 2: ‘baz’, length: 3 }; arr = Array.from(arrLike);
4.6 Use Array.from instead of spread … for mapping over iterables, because it avoids creating an intermediate array.
const baz = Array.from(foo, bar);
