Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode not respecting tab size when formatting a Dart file

I want VSCode on my Mac to use 4 spaces instead of 2 when I select Format Document. This is what I have on my User Settings:

{
    "editor.fontFamily": "Andale Mono",
    "editor.fontSize": 13,
    "editor.renderWhitespace": "all",
    "editor.tabSize": 4,
    "[dart]": {
        "editor.tabSize": 4,
        "editor.detectIndentation": false
    },
    "workbench.colorTheme": "Material Theme",
    "materialTheme.fixIconsRunning": false,
    "workbench.iconTheme": "eq-material-theme-icons"
}

However when I format the document, it does not respect the 4 spaces tab. It uses 2.

like image 682
Hahnemann Avatar asked Jun 16 '18 02:06

Hahnemann


People also ask

How do I change the configuration tab size in VS Code?

Type “Indentation” into the search field then head to the “Editor: Tab Size” section. Replace the default space number with your preferred one: Your setting will be applied and reflected immediately.

How do you format a Dart code in VS Code?

Automatically formatting code in VS Code To automatically format the code in the current source code window, right-click in the code window and select Format Document . You can add a keyboard shortcut to this VS Code Preferences. To automatically format code whenever you save a file, set the editor.

How do I make my VS Code tab smaller?

In VS Code you can access the editor's tab size settings by pressing Command+Comma (Mac) or Ctrl+Comma (PC), and typing tabsizing . You can edit settings for regular and pinned tabs. Currently there are two options for sizing editor tabs: fit and shrink .

Which tool is used for formatting code in Dart?

Use the dart format command to replace the whitespace in your program with formatting that follows Dart guidelines. This is the same formatting that you can get when using an IDE or editor that has Dart support. For more information about this and other dart commands, see the Dart command-line tool page.


1 Answers

This is a limitation of the Dart plugin for VS Code. It uses the official dart_style formatter which only supports formatting with spaces (the same as running dartfmt).

If you'd like to see a more flexible formatter, please put a ThumbsUp on this GitHub issue:

https://github.com/Dart-Code/Dart-Code/issues/914

like image 197
Danny Tuppeny Avatar answered Nov 03 '22 00:11

Danny Tuppeny