vscode 對js文件不格式化的修正方案 settings.json


修正1

 "javascript.format.enable": true, // 這里false 改true

修正2 注釋掉這個地方

 // "[javascript]": {
  //   "editor.defaultFormatter": "dbaeumer.vscode-eslint"
  // },

20211102 setting.json

{
  "pasteImage.path": "${currentFileNameWithoutExt}_Images/",
  "update.mode": "manual",
  "extensions.autoUpdate": false,
  "extensions.autoCheckUpdates": false,
  "editor.formatOnSave": true, // 這個保存時候進行格式化
  "editor.codeActionsOnSave": {
    // 保存時候 eslint修復
    "source.fixAll.eslint": true
  },
  "eslint.alwaysShowStatus": true,
  "editor.fontSize": 22,
  "editor.fontFamily": "Consolas, 'Courier New', monospace",
  "editor.fontLigatures": false,
  "editor.fontWeight": "400",
  "editor.lineHeight": 28,
  "editor.letterSpacing": 0,
  "editor.tabSize": 2,
  "editor.insertSpaces": true,
  "editor.detectIndentation": true,
  "editor.wordWrap": "off",
  "editor.renderLineHighlight": "gutter",
  "editor.roundedSelection": true,
  "editor.renderControlCharacters": true,
  "editor.renderIndentGuides": true,
  "editor.dragAndDrop": false,
  "editor.minimap.enabled": false,
  "editor.minimap.showSlider": "mouseover",
  "editor.minimap.renderCharacters": true,
  "editor.minimap.maxColumn": 200,
  "editor.quickSuggestions": {
    "strings": true
  },
  "editor.suggestSelection": "first",
  "window.titleBarStyle": "native",
  "window.menuBarVisibility": "visible",
  "window.title": "${rootName} - ${dirty}${activeEditorLong}",
  "workbench.colorTheme": "Spacegray Eighties Dark",
  "workbench.iconTheme": "material-icon-theme",
  "workbench.startupEditor": "welcomePage",
  "workbench.activityBar.visible": true,
  "workbench.editor.enablePreview": true,
  "workbench.editor.tabSizing": "fit",
  "workbench.editor.wrapTabs": false,
  "workbench.editor.decorations.colors": true,
  "workbench.editor.decorations.badges": true,
  "workbench.tree.renderIndentGuides": "none",
  "workbench.colorCustomizations": {
    // "statusBar.background": "#333333",
    // "statusBar.foreground": "#adadad",
    "terminal.background": "#000000",
    "terminal.foreground": "#FFFFFF"
  },
  "breadcrumbs.enabled": true,
  "breadcrumbs.symbolPath": "off",
  "explorer.openEditors.visible": 0,
  "explorer.compactFolders": false,
  "files.encoding": "utf8",
  "files.eol": "\r\n",
  "files.hotExit": "onExit",
  "files.autoSave": "off",
  "emmet.includeLanguages": {
    "javascript": "javascriptreact"
  },
  //javascript
  // "javascript.format.insertSpaceBeforeFunctionParenthesis": true,
  "js/ts.implicitProjectConfig.experimentalDecorators": true,
  //git
  "git.path": "D:\\Git\\bin\\git.exe",
  "git.enableSmartCommit": false,
  //terminal
  //"terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\cmd.exe",
  //"terminal.integrated.shell.windows": "D:\\Git\\git-bash.exe",
  "terminal.explorerKind": "integrated",
  //eslint
  "eslint.format.enable": false,
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    "vue",
    "typescript",
    "typescriptreact"
  ],
  //bookmarks
  // "bookmarks.saveBookmarksInProject": true,
  "javascript.format.insertSpaceBeforeFunctionParenthesis": true, // 讓函數名和后面的括號之間加個空格
  "javascript.format.insertSpaceAfterCommaDelimiter": true, // 逗號后面有空格
  "javascript.format.insertSpaceBeforeAndAfterBinaryOperators": true, // 運算符前后有空格
  "javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true, // 大括號前面插空格
  "javascript.format.insertSpaceAfterKeywordsInControlFlowStatements": true, // 關鍵字后面加空格
  "javascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": true, // 匿名函數后面加空格
  "vetur.format.options.tabSize": 2, // 每個縮進級別的空格數,由所有格式化程序繼承
  "vetur.format.scriptInitialIndent": false, // js部分是否有初始縮進
  //vetur
  "vetur.format.defaultFormatter.js": "vscode-typescript",
  "vetur.format.defaultFormatter.html": "js-beautify-html",
  "vetur.format.defaultFormatterOptions": {
    "js-beautify-html": {
      // - auto: 僅在超出行長度時才對屬性進行換行
      // - force: 對除第一個屬性外的其他每個屬性進行換行
      // - force-aligned: 對除第一個屬性外的其他每個屬性進行換行,並保持對齊
      // - force-expand-multiline: 對每個屬性進行換行
      // - aligned-multiple: 當超出折行長度時,將屬性進行垂直對齊
      "wrap_attributes": "force-aligned", // 屬性折行對齊方式
      "wrap_line_length": 120, // 設置一行多少字符換行
      "semi": false, // 是否在每行末尾添加分號
      "singleQuote": true, // 使用單引號
      "end_with_newline": false
    }
  },
  //liveServer
  "liveServer.settings.donotVerifyTags": true,
  //alias-skip
  "alias-skip.mappings": {
    "@": "/src",
    "_c": "/src/components"
  },
  // "[vue]": {
  //   "editor.defaultFormatter": "esbenp.prettier-vscode"
  // },
  "[markdown]": {
    "editor.minimap.enabled": true,
    "editor.wordWrap": "on",
    "editor.quickSuggestions": false,
    "editor.formatOnSave": false
  },
  "[jsonc]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[html]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  // "[javascript]": {
  //   "editor.defaultFormatter": "dbaeumer.vscode-eslint"
  // },
  "[json]": {
    "editor.defaultFormatter": "vscode.json-language-features"
  },
  "scf.python3.path": "",
  "scf.python2.path": "",
  "tabnine.experimentalAutoImports": true,
  "javascript.format.enable": true, // 20211102bug 發現js格式化不起錯用,這個是false 並且[javascript] 需要注釋掉
  "javascript.format.insertSpaceAfterConstructor": false,
  "javascript.format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": false,
  "javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false,
  "javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
  "javascript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false,
  "javascript.format.insertSpaceAfterSemicolonInForStatements": true,
  "javascript.format.placeOpenBraceOnNewLineForControlBlocks": false,
  "javascript.format.placeOpenBraceOnNewLineForFunctions": false,
  "liveServer.settings.donotShowInfoMsg": true,
  "[typescriptreact]": {
    "editor.defaultFormatter": "vscode.typescript-language-features"
  },
  "vue-helper.alias": {
    "_c": "src/components/",
    "@": "src/"
  },
  "commentTranslate.source": "Baidu",
  "commentTranslate.targetLanguage": "zh-CN",
  "easy-translator.dictionary": [
    "YouDao",
    "Bing",
    "Google",
    "Linguee"
  ],
  "vue-helper.componentPrefix": {
    "alias": "@",
    "path": "src"
  },
  "vue-helper.componentPath": [
    "./*",
    "./components/*"
  ],
  "php.validate.executablePath": "D:/phpstudy_pro/Extensions/php/php5.6.9nts/php.exe",
  "[typescript]": {
    "editor.defaultFormatter": "vscode.typescript-language-features"
  },
  "javascript.updateImportsOnFileMove.enabled": "always",
  "[vue]": {
    "editor.defaultFormatter": "octref.vetur"
  },
  "vetur.validation.template": false,
  "git.confirmSync": false,
  "intelephense.diagnostics.languageConstraints": false,
  "files.exclude": {
    "**/.git": false
  },
  "files.associations": {
    "*.vue": "vue"
  }
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM