eslint 的使用

ESLint的用途

  1. 审查代码是否符合编码规范和统一的代码风格
  2. 审查代码是否存在语法错误

官网

https://eslint.org/

居然找到了一个中文网站:

http://eslint.cn/docs/user-guide/configuring#configuration-file-formats

开始使用

npm install eslint --save-de

https://eslint.org/docs/user-guide/getting-started

配置 ESlint

配置注释

可以使用块注释,来临时禁止规则出现警告

/* eslint-disable*/
console.log(1)

配置文件

ESLint 可以通过 .eslintrc.* file 或 package.json 中的 eslintConfig 字段来配置

.eslintrc.js:

module.exports = {
    rules: {
        'no-console': 'off',
    },
};

package.json:
以下是vue-cli的默认配置

"eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "eslint:recommended"
    ],
    "rules": {},
    "parserOptions": {
      "parser": "babel-eslint"
    }
  },
vue-cli 配置 ESlint:

https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint

eslint 0, 1, 2 means
  • “off” or 0 - turn the rule off
  • “warn” or 1 - turn the rule on as a warning (doesn’t affect exit code)
  • “error” or 2 - turn the rule on as an error (exit code will be 1)

http://eslint.org/docs/user-guide/getting-started#configuration

console 报错处理

https://eslint.org/docs/rules/no-console

用户总结:https://morning.work/page/maintainable-nodejs/getting-started-with-eslint.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值