eslint 這個代碼規則,是在用webpack +vue-cli這個腳手架時候接觸的,默認的規則可能不太習慣咱們平常平時的代碼開發,須要對這個規則稍加改造。html
下面的是 eslintrc.js的基本規則(語句分號結尾,支持空格和tab的混合縮進)vue
// https://eslint.org/docs/user-guide/configuring module.exports = { root: true, parser: 'babel-eslint', parserOptions: { sourceType: 'module' }, env: { browser: true, }, // https://github.com/standard/standard/blob/master/docs/RULES-en.md extends: 'standard', // required to lint *.vue files plugins: [ 'html' ], // add your custom rules here 'rules': {
//容許使用tab 縮進 'indent':['off','tab'], // 容許箭頭函數的參數使用圓括號 'arrow-parens': 0, // 容許 async-await 'generator-star-spacing': 0, // 容許使用tab "no-tabs":"off",
// 容許在development使用debugger
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
// 關閉語句強制分號結尾
"semi": [0,';'],
//空行最多不能超過3行
"no-multiple-empty-lines": [0, {"max": 3}],
//容許禁止混用tab和空格
"no-mixed-spaces-and-tabs": 'off'
} }
配置這個規則:只要掌握這樣的規則:webpack
1.你須要改那些規則(默認都是關閉的)規則的以下:http://eslint.cn/docs/rules/git
2.關閉或者打開 。github
"off" 或者 0:關閉規則。web
"warn" 或者 1:打開規則,而且做爲一個警告(不影響exit code)。vue-cli
"error" 或者 2:打開規則,而且做爲一個錯誤(exit code將會是1)。 babel
3.具體寫法:async
舉例子ide
"semi": [0,';'] 容許分號的使用,也能夠寫"semi": [0]
"no-tabs":[0], 容許tab 的使用,也能夠寫"semi": 'off'
補充: 在用vue-cli 腳手架搭建項目的時候,會對webpack的缺乏一些基本的認識,這裏是我總結基本的webpack的認識,能夠把項目down 下來看看, 真的是基本的用法。高手請繞行哈~
https://github.com/adouwt/webpack