Home > Web Front-end > JS Tutorial > Introduction to the ESlint configuration file eslintrc.js in vue-cli

Introduction to the ESlint configuration file eslintrc.js in vue-cli

小云云
Release: 2018-02-01 10:24:21
Original
2380 people have browsed it

eslint is a tool used to manage and detect js code style. It can be used with an editor, such as vscode's eslint plug-in. When there is code that does not conform to the content of the configuration file, an error or warning will be reported. This article mainly shares with you the detailed explanation of the ESlint configuration file eslintrc.js in vue-cli. The editor thinks it is quite good. Now I will share it with you and help you make it. a reference.

Install exlint


npm init -y
npm install eslint --save-dev
node_modules\.bin\eslint --init 初始化配置文件,此配置文件配置好之后,vscode编辑器自动识别
Copy after login

Explanation of vue-cli’s .eslintrc.js configuration file


// http://eslint.org/docs/user-guide/configuring

module.exports = {
  //此项是用来告诉eslint找当前配置文件不能往父级查找
  root: true, 
  //此项是用来指定eslint解析器的,解析器必须符合规则,babel-eslint解析器是对babel解析器的包装使其与ESLint解析
  parser: 'babel-eslint',
  //此项是用来指定javaScript语言类型和风格,sourceType用来指定js导入的方式,默认是script,此处设置为module,指某块导入方式
  parserOptions: {
    sourceType: 'module'
  },
  //此项指定环境的全局变量,下面的配置指定为浏览器环境
  env: {
    browser: true,
  },
  // https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
  // 此项是用来配置标准的js风格,就是说写代码的时候要规范的写,如果你使用vs-code我觉得应该可以避免出错
  extends: 'standard',
  // required to lint *.vue files
  // 此项是用来提供插件的,插件名称省略了eslint-plugin-,下面这个配置是用来规范html的
  plugins: [
    'html'
  ],
  // add your custom rules here
  // 下面这些rules是用来设置从插件来的规范代码的规则,使用必须去掉前缀eslint-plugin-
  // 主要有如下的设置规则,可以设置字符串也可以设置数字,两者效果一致
  // "off" -> 0 关闭规则
  // "warn" -> 1 开启警告规则
  //"error" -> 2 开启错误规则
  // 了解了上面这些,下面这些代码相信也看的明白了
  'rules': {
    // allow paren-less arrow functions
    'arrow-parens': 0,
    // allow async-await
    'generator-star-spacing': 0,
    // allow debugger during development
    'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
  }
}
Copy after login

Related recommendations:

Detailed examples of vue-cli vscode configuration eslint

How to turn off ESLint in the vue project

Detailed explanation of ESLint rules (1)

The above is the detailed content of Introduction to the ESlint configuration file eslintrc.js in vue-cli. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template