.eslintignore
指定哪些文件或者文件夹不进行检查
/build/
/config/
/dist/
/test/unit/coverage/
.eslintrc.js
配置文件,几个信息可以配置:
环境 - 脚本设计运行的环境。每个环境都带有一组预定义的全局变量。
全局变量 - 脚本在执行期间访问的其他全局变量。
规则 - 启用哪些规则以及错误级别。
vue 项目 .eslintrc.js
配置文件
// https://eslint.org/docs/user-guide/configuring
module.exports = {
root: true,
parserOptions: {
parser: 'babel-eslint'
},
env: {
browser: true,
},
extends: [
// https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
// consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
'plugin:vue/essential',
// https://github.com/standard/standard/blob/master/docs/RULES-en.md
'standard'
],
// required to lint *.vue files
plugins: [
'vue'
],
// add your custom rules here
rules: {
// allow async-await
'generator-star-spacing': 'off',
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-tabs': 0
}
}
忽略单行检查
// eslint-disable-line
let a = 1
let b = {} // eslint-disable-line
let c = true
忽略多行检查
/* eslint-disable */
和 /* eslint-enable */
组合使用
/* eslint-disable */
let myCar = new Object()
myCar.make = 'Ford'
myCar.model = 'Mustang'
myCar.year = 1969
/* eslint-enable */
忽略整个文件或者以下代码全部忽略
/* eslint-disable */
写在文件头部或写在需要忽略的代码上方
main.js
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
Vue.config.productionTip = false
/* eslint-disable */
new Vue({
el: '#app',
router,
template: '<App/>',
components: { App }
})