HankLiu Vue Eslint
提供Vue项目中基础的eslint规则和插件
安装
npm install @hankliu/eslint-vue -D
or
yarn add @hankliu/eslint-vue -D
使用
- in .eslintrc.js
const eslint = require('@hankliu/eslint-vue');
// 修改规则
// eslint.plugins.push('vue');
// eslint.rules = Object.assign(eslint.rules, {
// 'vue/jsx-uses-vars': 'error',
// 'vue/max-attributes-per-line': 'off',
// 'vue/component-name-in-template-casing': [
// 'error',
// 'kebab-case', {
// 'ignores': []
// }
// ],
// 'vue/singleline-html-element-content-newline': 'off'
// });
// eslint.globals = Object.assign(eslint.globals, {
// 'app.less': true,
// '$': true
// });
module.exports = eslint;
- in webpack with eslint-loader
{
rules: [{
test: /\.(js|vue)$/,
enforce: 'pre',
loader: 'eslint-loader',
options: {
eslintPath: require.resolve('eslint'),
baseConfig: {
extends: [require.resolve('@hankliu/eslint-vue')]
},
ignore: false,
useEslintrc: false,
formatter: require('eslint-friendly-formatter')
}
}]
}
注意
我们使用的是 peerDependencies 管理依赖,如果是在npm2中使用该插件,不许需要在自己项目中额外安装下列依赖,npm2会自行强制安装peerDependencies所要求指定的依赖包;如果是在npm3+中使用该插件,npm3中不会再要求peerDependencies所指定的依赖包被强制安装,相反npm3会在安装结束后检查本次安装是否正确,如果不正确会给用户打印警告提示。
"peerDependencies": {
"babel-eslint": "^10.x",
"eslint": "^5.x",
"eslint-config-airbnb-base": "^13.x",
"eslint-config-standard": "^12.x",
"eslint-plugin-flowtype": "^3.x",
"eslint-plugin-import": "^2.x",
"eslint-plugin-vue": "^5.x"
}