vscode格式化配置


一、安裝常用插件:

Ctrl+shift+x打開應用商店搜索這幾個插件安裝即可

Beautify、Eslint、Vetur

二、setting.josn配置

文件-首選項-設置-在setting.josn中編輯,打開這個setting.josn文件后將下面配置復制即可

{
    // tab 大小為2個空格
    "editor.tabSize": 2,
    // 100 列后換行
    "editor.wordWrapColumn": 100,
    // 保存時格式化
    "editor.formatOnSave": true,
    // 開啟 vscode 文件路徑導航
    "breadcrumbs.enabled": true,
    // prettier 設置語句末尾不加分號
    "prettier.semi": false,
    // prettier 設置強制單引號
    "prettier.singleQuote": true,
    // 選擇 vue 文件中 template 的格式化工具
    "vetur.format.defaultFormatter.html": "prettyhtml",
    // 顯示 markdown 中英文切換時產生的特殊字符
    "editor.renderControlCharacters": true,
    // 設置 eslint 保存時自動修復
    "eslint.autoFixOnSave": true,
    // eslint 檢測文件類型
    "eslint.validate": [
        "javascript",
        "javascriptreact",
        {
            "language": "html",
            "autoFix": true
        },
        {
            "language": "vue",
            "autoFix": true
        }
    ],
    // vetur 的自定義設置
    "vetur.format.defaultFormatterOptions": {
        "prettier": {
            "singleQuote": true,
            "semi": false
        }
    },
    // 修改500ms后自動保存
    "editor.formatOnSaveTimeout": 500,
    "files.autoSave": "afterDelay",
    "files.autoSaveDelay": 500,
    "editor.codeActionsOnSaveTimeout": 500,
    "[javascript]": {
        "editor.defaultFormatter": "vscode.typescript-language-features"
    }
}

三、配置.editorconfig文件

項目根目錄下找到.editorconfig這個文件,然后復制下面配置即可

# https://editorconfig.org
root = true                         # 根目錄的配置文件,編輯器會由當前目錄向上查找,如果找到 `roor = true` 的文件,則不再查找

[*]                                 # 匹配所有的文件
indent_style = space                # 空格縮進
indent_size = 4                     # 縮進空格為4個
end_of_line = lf                    # 文件換行符是 linux 的 `\n`
charset = utf-8                     # 文件編碼是 utf-8
trim_trailing_whitespace = true     # 不保留行末的空格
insert_final_newline = true         # 文件末尾添加一個空行
curly_bracket_next_line = false     # 大括號不另起一行
spaces_around_operators = true      # 運算符兩遍都有空格
indent_brace_style = 1tbs           # 條件語句格式是 1tbs

[*.js]                              # 對所有的 js 文件生效
quote_type = single                 # 字符串使用單引號

[*.{html,less,css,json}]            # 對所有 html, less, css, json 文件生效
quote_type = double                 # 字符串使用雙引號

[package.json]                      # 對 package.json 生效
indent_size = 2                     # 使用2個空格縮進

注釋都寫了, 我就不再啰嗦,實屬干貨,上手試試吧!


免責聲明!

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



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