Skip to content

格式化

自带

VS Code 默认缩进 4 个空格,并检测打开文件的偶数缩进空格。

在设置中开启 Editor: Format on Save ,保存时自动格式化,统一缩进 4 个空格。如果需要绕开 VS Code 自动格式化,可以使用其他编辑器,编辑保存。

在配置文件 settings.json 中修改,可以保存时自动格式化、控制缩进、关闭检测缩进等。

{
    "editor.formatOnSave": true,
    "[typescriptreact]": {
        "editor.tabSize": 2,
        "editor.detectIndentation": false
    },
    "[typescript]": {
        "editor.tabSize": 2,
        "editor.detectIndentation": false
    },
    "[javascript]": {
        "editor.tabSize": 2,
        "editor.detectIndentation": false
    }
}

插件

开启保存时自动格式化。

插件 EditorConfig for VS Code,可以快速配置缩进等格式化规则。配置文件 .editorconfig

root = true

[*]
indent_style = space

[*.{ts,tsx,js,jsx,mjs,json}]
indent_size = 2

联系 math@baima.site