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

原文地址:https://www.cnblogs.com/adouwt/p/7884128.html