vscode 保存代码自动格式化(vue)

1 根据项目配置的eslint规则保存代码后,自动格式化代码

2 需要安装prettier 和 vetur

// settings.json
{
  "codestream.serverUrl": "https://api.codestream.com",
  "security.workspace.trust.untrustedFiles": "open",
  "editor.language.brackets": false,
  "editor.formatOnSave": true,
  // "eslint.autoFixOnSave": true,
  "eslint.packageManager": "yarn",
  "eslint.validate": [
    "javascript", //  用eslint的规则检测js文件
    {
      "language": "vue", // 检测vue文件
      "autoFix": true //  为vue文件开启保存自动修复的功能
    },
    {
      "language": "html",
      "autoFix": true
    }
  ],
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  },
  "editor.tabSize": 2,
  "diffEditor.ignoreTrimWhitespace": false,
  "vetur.format.defaultFormatterOptions": {
    "js-beautify-html": {
      // 超过120的部分换行
      "wrap_line_length": 120,
      "wrap_attributes": "auto",
      "end_with_newline": false
    },

    "prettier": {
      // 设置分号
      "singleQuote": true,
      // 双引号变成单引号
      "semi": false,
      // 超过120的部分换行
      "printWidth": 120,

      "wrapAttributes": true,

      "sortAttributes": false,
      // 禁止随时添加逗号
      "trailingComma": "none"
    }
  },
  // 设置编译器默认使用vetur方式格式化代码
  "[vue]": {
    "editor.defaultFormatter": "octref.vetur"
  }
}

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值