eslint规则

2021-01-16  本文已影响0人  wyc0859

新建 .eslintrc.js 文件

module.exports = {
  root: true,
  env: {
    node: true
  },
  'extends': [
    'plugin:vue/essential',
    'eslint:recommended'
  ],
  rules: {
    'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    "no-mixed-spaces-and-tabs": "off",  //可以使用混合空格和制表符进行缩进
    "no-unused-vars":"off"  //已定义未使用
  },
  parserOptions: {
    parser: 'babel-eslint'
  }
}

忽略验证的注释写法

/ 1. 在整个文件中取消eslint检查:
/* eslint-disable */
alert(‘foo’);

// 2. 在整个文件中禁用某一项eslint规则的检查:
/* eslint-disable no-alert */
alert(‘foo’);

// 3. 在整个文件中禁用多项eslint规则的检查:
/* eslint-disable no-alert, no-console */
alert(‘foo’);
console.log(‘bar’);

// 4. 针对某一行禁用eslint检查:
alert(‘foo’); // eslint-disable-line

// eslint-disable-next-line
alert(‘foo’);

// 5. 针对某一行的某一具体规则禁用eslint检查:
alert(‘foo’); // eslint-disable-line no-alert

// eslint-disable-next-line no-alert
alert(‘foo’);

// 6. 针对某一行禁用多项具体规则的检查:

alert(‘foo’); // eslint-disable-line no-alert, quotes, semi

// eslint-disable-next-line no-alert, quotes, semi
alert(‘foo’);

ESLint fix自动修复所有格式问题

如报错:potentially fixable with the --fix option

找到package.json文件,在 scripts中添加 :

"lint-fix": "eslint --fix --ext .js --ext .jsx --ext .vue src/",

然后运行 npm run lint-fix即可修复

上一篇下一篇

猜你喜欢

热点阅读