vscode代码保存自动格式化

242 阅读1分钟
{
  "workbench.colorTheme": "One Dark Pro",  //主题
  "settingsSync.ignoredSettings": [],
  "window.zoomLevel": 1.5,  // 窗口缩放尺寸
  "npm.exclude": "",
  "npm.autoDetect": "on",
  "npm.scriptExplorerAction": "run",
  "npm.packageManager": "npm",
  "vetur.ignoreProjectWarning": true,  // 忽略vetur警告
  "editor.tabSize": 2,
  "editor.fontSize": 14,
  "editor.tabCompletion": "on", // 用来在出现推荐值时,按下Tab键是否自动填入最佳推荐值
  "editor.formatOnSave": true, // 每次保存的时候自动格式化
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true, // 每次保存的时候将代码按eslint格式进行修复
    "source.organizeImports": true // 这个属性能够在保存时,自动调整 import 语句相关顺序,能够让你的 import 语句按照字母顺序进行排列
  },
  "editor.detectIndentation": false,
  // eslint 设置
  "eslint.options": {
    "extensions": [
      ".js",
      ".vue"
    ]
  },
  "eslint.validate": [
    "javascript", // 用eslint的规则检测js文件
    "javascriptreact",
    "vue",
    "html",
  ],
  "eslint.format.enable": true,
  "eslint.run": "onSave",
  // #让vue中的js按"prettier"格式进行格式化
  "vetur.format.defaultFormatter.html": "js-beautify-html",
  "vetur.format.defaultFormatter.js": "prettier-eslint",
  "vetur.format.defaultFormatterOptions": {
    "js-beautify-html": {
      // #vue组件中html代码格式化样式
      "wrap_attributes": "auto", //也可以设置为“auto”,效果会不一样
      "wrap_line_length": 200,
      "end_with_newline": false,
      "semi": false,
      "singleQuote": true
    },
    "prettier": {
      "semi": false,
      "singleQuote": true,
      "editor.tabSize": 2
    },
    "prettyhtml": {
      "printWidth": 160,
      "singleQuote": false,
      "wrapAttributes": false,
      "sortAttributes": false
    }
  },
  "[vue]": {
    "editor.defaultFormatter": "octref.vetur"
  },
  "[css]": {
    "editor.defaultFormatter": "sibiraj-s.vscode-scss-formatter"
  },
  // stylelint配置
  "stylelint.enable": true,
  "css.validate": false,
  "less.validate": false,
  "scss.validate": true,
  "[scss]": {
    "editor.formatOnSave": true
  },
  "editor.fontLigatures": true,
}