1. 程式人生 > 其它 >vscode格式化配置-settings.jon

vscode格式化配置-settings.jon

準備擴充套件:js-beautify-html,prettier,vetur

{  
    "workbench.colorTheme": "Tiny Light",
    "workbench.iconTheme": "vscode-icons",

    "editor.detectIndentation": false,// vscode預設啟用了根據檔案型別自動設定tabsize的選項
    "editor.tabSize": 4,            // 重新設定tabsize
    
    // ESLint 配置程式碼檢查
    "eslint.format.enable": false,
    "eslint.alwaysShowStatus": false,
    "eslint.quiet": false, // 忽略檢查
    "eslint.validate": [
        "javascript",
        "javascriptreact",
        "typescript",
        "typescriptreact",
        "vue-html",
        "html",
        "vue"
    ],
    "eslint.run": "onType",
    "eslint.options": {
        "extensions": [
            ".js",
            ".vue",
        ],
    },

    "javascript.format.placeOpenBraceOnNewLineForControlBlocks": false, // 函式左括號{是否換行
    "javascript.format.insertSpaceBeforeFunctionParenthesis": false, // 不讓函式(名)和後面的括號之間加個空格
        
    // prettier 格式化配置
    "prettier.arrowParens": "avoid", //(x) => {} 箭頭函式引數只有一個時是否要有小括號。avoid:省略括號
    "prettier.bracketSpacing": true, // 在物件,陣列括號與文字之間加空格 "{ foo: bar }"
    "prettier.endOfLine": "auto", // 行尾換行格式
    "prettier.jsxBracketSameLine": false, // 在jsx中把'>' 是否單獨放一行
    "prettier.jsxSingleQuote": true,  // 在jsx中使用單引號代替雙引號
    "prettier.printWidth": 100,  // 超過最大值換行
    "prettier.singleQuote": true, //使用單引號而不是雙引號
    "prettier.semi": true,  //在語句結尾處加分號
    "prettier.tabWidth": 4, // 縮排位元組數
    "prettier.trailingComma": "none", //禁止隨時新增逗號
    "prettier.useTabs": false, // 縮排不使用tab,使用空格

    //.vue檔案template格式化支援,並使用js-beautify-html外掛
    "vetur.format.defaultFormatter.html": "js-beautify-html",
    "vetur.format.defaultFormatter.js": "prettier",
    "vetur.format.defaultFormatter.less": "prettier",
    "vetur.format.defaultFormatter.css": "prettier",
    "vetur.format.options.tabSize": 4,   //縮排為4
    "vetur.format.options.useTabs": false,
    "vetur.format.defaultFormatterOptions": {
        //js-beautify-html格式化配置
        "js-beautify-html": {
            "wrap_attributes": "force-aligned" // 屬性強制換行
        },
        "prettier": {
            "arrowParens": "avoid",    //(x) => {} 箭頭函式引數只有一個時是否要有小括號。avoid:省略括號
            "bracketSpacing": true,  // 在物件,陣列括號與文字之間加空格 "{ foo: bar }"
            "endOfLine": "auto",   // 行尾換行格式
            "eslintIntegration": false, //不讓prettier使用eslint的程式碼格式進行校驗   
            "jsxBracketSameLine": false, // 在jsx中把'>' 是否單獨放一行
            "jsxSingleQuote": false, // 在jsx中使用單引號代替雙引號
            "printWidth": 100,    // 超過最大值換行
            "singleQuote": true, //使用單引號而不是雙引號
            "semi": true, //在語句結尾處加分號
            "tabWidth": 4,  //縮排位元組數
            "trailingComma": "none", //禁止隨時新增逗號
            "tslintIntegration": false,  // 不讓prettier使用tslint的程式碼格式進行校驗
            "useTabs": false // 縮排不使用tab,使用空格
        }
    },
    // 每一種語言的預設格式化規則
    "[html]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "[javascript]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "[less]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "[css]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "prettier.useEditorConfig": false 
}