vue vscode 比较好看的eslint风格检测,和保存自动格式化

1、cnpm i eslint eslint-plugin-vue
2、vscode中下载安装ESLint插件在这里插入图片描述

2、在src同级目录下创建.eslintrc.js文件

3、复制以下代码

module.exports = {
  "root": true,
  "env": {
    "node": true,
    "browser": true
  },
  "extends": [
    "plugin:vue/vue3-essential",
    "eslint:recommended"
  ],
  "parser": "vue-eslint-parser",
  "parserOptions": {
    "parser": "babel-eslint",
    "sourceType": "module"
  },
  "rules": {
    // "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 is 1 when triggered)
    "no-alert": 1, // 禁止alert
    "no-console": 0,// 禁止console
    "block-spacing": 1,// 禁止或强制在代码块中开括号前和闭括号后有空格
    "indent": [1, "tab", { "SwitchCase": 1, "VariableDeclarator": { "var": 2, "let": 2, "const": 3 } }],  // 代码缩进
    "comma-spacing": [1, { "before": false, "after": true }],
    "comma-dangle": [1, {
      "arrays": "never",
      "objects": "never",
      "imports": "never",
      "exports": "never",
      "functions": "never"
    }], // 要求或禁止使用拖尾逗号
    "comma-style": [1, "last"], // 逗号风格 
    // "no-use-before-define": "error", // 变量未声明,禁止使用
    "eol-last": [1, "always"],  // 逗号在结尾
    "implicit-arrow-linebreak": [1, "beside"],  // 强制隐式返回的箭头函数体的位置
    "key-spacing": [1, { "beforeColon": false, "mode": "strict", }],  // 强制在对象字面量的键和值之间使用一致的空格
    "keyword-spacing": [1, { "after": true }],  // 强制关键字周围空格的一致性 
    "lines-around-comment": [1, { "beforeBlockComment": true, "beforeLineComment": true, "beforeLineComment": true, "allowBlockStart": true }],  // 强制注释周围有空行
    "lines-between-class-members": [1, "always"],  // 要求或禁止在类成员之间出现空行 
    "newline-per-chained-call": [1, { "ignoreChainWithDepth": 2 }],  // 要求或禁止在类成员之间出现空行 
    "no-multi-assign": "error", // 禁止连续赋值
    "no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 1, "maxBOF": 1 }], // 不允许多个空行
    "no-trailing-spaces": 1, // 禁用行尾空白
    "no-whitespace-before-property": 1, // 禁止属性前有空白
    "object-curly-spacing": [1, "always", { "arraysInObjects": true }], // 强制在花括号中使用一致的空格 
    "one-var-declaration-per-line": [1, "always"], // 要求或禁止在变量声明周围换行
    "object-property-newline": [1, { "allowAllPropertiesOnSameLine": true }], // 强制将对象的属性放在不同的行上
    "operator-linebreak": [1, "before"], // 强制操作符使用一致的换行符风格
    // "semi": [1, "never", { "omitLastInOneLineBlock": true }], // 要求或禁止使用分号代替 ASI
    "space-before-blocks": [1, "always"], // 要求或禁止语句块之前的空格
    "space-in-parens": [1, "always", { "exceptions": [, "{}", "[]"] }], // 禁止或强制圆括号内的空格
    "space-infix-ops": 1, // 要求中缀操作符周围有空格
    "space-unary-ops": [1, { "words": true, "nonwords": false }], // 要求或禁止在一元操作符之前或之后存在空格 
    "spaced-comment": [1, "always"], // 要求或禁止在注释前有空白
    "wrap-regex": 1, // 要求正则表达式被包裹起来
    "arrow-spacing": 1, // 要求箭头函数的箭头之前或之后有空格
  }
}

4、打开vscode—设置—settings—粘贴自动格式化代码

"editor.formatOnSave": true,

在这里插入图片描述

另外:1、修改vue-html中的格式,需要配置插件 Vetur,和在settings中配置js-beautify-html这里是参数链接在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值