天天看點

eslint 的基本配置介紹

eslint 這個代碼規則,是在用webpack +vue-cli這個腳手架時候接觸的,預設的規則可能不太習慣我們日常平時的代碼開發,需要對這個規則稍加改造。

下面的是 eslintrc.js的基本規則(語句分号結尾,支援空格和tab的混合縮進)

// 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' 
} }      

配置這個規則:隻要掌握這樣的規則:

1.你需要改那些規則(預設都是關閉的)規則的如下:

http://eslint.cn/docs/rules/

2.關閉或者打開 。

  "off" 或者 0:關閉規則。

  "warn" 或者 1:打開規則,并且作為一個警告(不影響exit code)。

  "error" 或者 2:打開規則,并且作為一個錯誤(exit code将會是1)。     

3.具體寫法:

舉例子

"semi": [0,';']    允許分号的使用,也可以寫"semi": [0]

"no-tabs":[0],     允許tab 的使用,也可以寫"semi": 'off'      
補充: 在用vue-cli 腳手架搭建項目的時候,會對webpack的缺少一些基本的認識,這裡是我總結基本的webpack的認識,可以把項目down 下來看看, 真的是基本的用法。高手請繞行哈~
        https://github.com/adouwt/webpack          

繼續閱讀