Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabling Format on Save for YAML Files Does Not Work #201752

Closed
Tracked by #1
MarkCaro opened this issue Jan 4, 2024 · 7 comments
Closed
Tracked by #1

Disabling Format on Save for YAML Files Does Not Work #201752

MarkCaro opened this issue Jan 4, 2024 · 7 comments
Assignees
Labels
info-needed Issue requires more information from poster

Comments

@MarkCaro
Copy link

MarkCaro commented Jan 4, 2024

Type: Bug

I don't have any YAML-related extensions installed.

I also disabled all installed extensions and reloaded VS Code during testing, so the issue is not caused by an extension.

This configuration does not work:

"editor.formatOnSave": true,
"[yaml]": {        
    "editor.formatOnSave": false
}

Is there a way to disable format on save just for YAML files?

VS Code version: Code 1.85.1 (0ee08df, 2023-12-13T09:49:37.021Z)
OS version: Windows_NT x64 10.0.22000
Modes:

System Info
Item Value
CPUs AMD Ryzen 7 4800H with Radeon Graphics (16 x 2895)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) undefined
Memory (System) 15.42GB (8.83GB free)
Process Argv D:\Mark_Files\3_Projects\Repositories\my_project --crash-reporter-id 1a597669-9013-4e03-a6f9-a37ee0845faf
Screen Reader no
VM 0%
Extensions (10)
Extension Author (truncated) Version
Bookmarks ale 13.4.2
githistory don 0.6.20
go gol 0.40.1
todo-tree Gru 0.0.226
favorites kdc 2.4.5
vscode-cfn-lint kdd 0.25.2
identical-sublime-monokai-csharp-theme-colorizer max 1.2.3
material-icon-theme PKi 4.32.0
markdown-all-in-one yzh 3.5.1
vscode-proto3 zxh 0.5.5
A/B Experiments
vsliv368:30146709
vsreu685:30147344
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
vshan820:30294714
vscoreces:30445986
vscod805cf:30301675
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593cf:30376535
py29gd2263:30899288
vsclangdf:30486550
c4g48928:30535728
azure-dev_surveyone:30548225
f6dab269:30613381
a9j8j154:30646983
pythongtdpath:30769146
i26e3531:30792625
welcomedialog:30910333
pythonidxpt:30866567
pythonnoceb:30805159
asynctok:30898717
pythontestfixt:30902429
pythonregdiag2:30928863
pyreplss1:30897532
pythonmypyd1:30879173
pythoncet0:30885854
2e7ec940:30885897
pythontbext0:30879054
accentitlementsc:30887149
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
aa_t_chat:30882232
dsvsc019:30917259
cp7184t3:30927821

@jrieken
Copy link
Member

jrieken commented Jan 8, 2024

I don't have any YAML-related extensions installed.

So, which extension does format YAML files in your case?

@jrieken jrieken added the info-needed Issue requires more information from poster label Jan 8, 2024
@MarkCaro
Copy link
Author

MarkCaro commented Jan 9, 2024

@jrieken
It shouldn't be an extension because I disabled everything during testing via "Disable All Installed Extensions."
It's most likely VS Code's built-in feature for YAML files when the editor.formatOnSave config is set to true that the YAML-specific config can't override.

I remember being able to disable a lot of built-in language-specific features in the Extensions section a couple years ago, but now I only see Extensions I installed from the Marketplace.

@jrieken jrieken assigned aeschli and jrieken and unassigned jrieken Jan 9, 2024
@jrieken
Copy link
Member

jrieken commented Jan 9, 2024

files when the editor.formatOnSave config is set to true that the

We don't ship with that setting. Please check yours and make sure you have no language specific enablement for format on save

@MarkCaro
Copy link
Author

MarkCaro commented Jan 9, 2024

@jrieke
I don't have any language-specific config for format on save aside for YAML where I try to disable it.

Below is my entire VS Code config:

{
    // ------------------
    //      General
    // ------------------
    "breadcrumbs.enabled": true,
    "editor.bracketPairColorization.enabled": true,
    "editor.codeActionsOnSave": {
        "source.fixAll": "explicit",
        "source.organizeImports": "explicit"
    },
    "editor.codeLens": false,
    "editor.comments.ignoreEmptyLines": false,
    "editor.fontFamily": "Consolas",
    "editor.fontSize": 19,
    "editor.formatOnSave": true,
    "editor.guides.bracketPairs": "active",
    "editor.minimap.enabled": false,
    "editor.mouseWheelZoom": true,
    "editor.semanticHighlighting.enabled": true,
    "editor.suggestSelection": "first",
    "editor.tokenColorCustomizations": {
        "comments": "#FF2D00" // Make all comments Red.
    },
    "explorer.compactFolders": false,
    "extensions.ignoreRecommendations": true,
    "files.associations": {
        "*.service": "shellscript" // For highlighting purposes, treat certain files as another language.
    },
    "files.trimTrailingWhitespace": true,
    "git.openRepositoryInParentFolders": "never",
    "security.workspace.trust.enabled": false,
    "terminal.integrated.defaultProfile.windows": "Command Prompt",
    "terminal.integrated.enableMultiLinePasteWarning": false,
    "terminal.integrated.enablePersistentSessions": false,
    "terminal.integrated.profiles.windows": {
        "Command Prompt": {
            "args": [],
            "icon": "terminal-cmd",
            "path": [
                "${env:windir}\\Sysnative\\cmd.exe",
                "${env:windir}\\System32\\cmd.exe"
            ]
        },
        "Git Bash": {
            "source": "Git Bash"
        },
        "PowerShell": {
            "icon": "terminal-powershell",
            "source": "PowerShell"
        }
    },
    "window.titleBarStyle": "custom",
    "workbench.editor.openPositioning": "last",
    "workbench.iconTheme": "material-icon-theme",
    "workbench.settings.editor": "json",
    "workbench.sideBar.location": "right",
    "workbench.startupEditor": "none",
    // --------------
    //       Go
    // --------------
    "go.formatFlags": [
        "-s",
        "-w"
    ],
    "go.formatTool": "gofmt",
    "go.lintFlags": [
        "--fast"
    ],
    "go.lintOnSave": "workspace",
    "go.lintTool": "golangci-lint",
    "go.toolsManagement.autoUpdate": true,    
    // ------------------
    //     TODO Tree
    // ------------------
    "todo-tree.filtering.excludeGlobs": [
        "**/c:\\go/**",
        "**/vendor/**"
    ],
    "todo-tree.general.tags": [
        "BUG",
        "HACK",
        "FIXME",
        "TODO",
        "XXX",
        "[ ]",
        "[x]"
    ],
    "todo-tree.highlights.customHighlight": {
        "TODO": {},
        "FIXME": {}
    },
    "todo-tree.highlights.defaultHighlight": {
        "foreground": "#008000",
        "type": "none"
    },
    "todo-tree.highlights.enabled": false,
    "todo-tree.regex.regex": "(//|#|<!--|;|/\\*|^|^\\s*(-|\\d+.))\\s*($TAGS)",
    "todo-tree.tree.tagsOnly": true,
    "window.zoomLevel": 1,
    "[yaml]": {
        "editor.formatOnSave": false
    },
    "workbench.colorTheme": "Sublime Monokai"    
}

@MarkCaro
Copy link
Author

MarkCaro commented Jan 9, 2024

The problem can be easily reproduced when you have a YAML file that has:

  • Extra spaces at the end of lines.
  • Lines that only consist of spaces.

When you save the file, the spaces get removed.

I raised this issue because the autoformatting changes make it difficult for code reviewers to view the actual changes.

I have format on save enabled for all languages and then try to disable it just for YAML files, which currently doesn't work:

    "editor.formatOnSave": true,
    "[yaml]": {
        "editor.formatOnSave": false
    },

@aeschli
Copy link
Contributor

aeschli commented Jan 10, 2024

VS Code doesn't ship with a YAML formatter out-of-the box.
It's the setting "files.trimTrailingWhitespace": true, that causes that. You want to disable it, at least for yaml.

    "[yaml]": {
        "files.trimTrailingWhitespace": false
    },

@aeschli aeschli closed this as completed Jan 10, 2024
@MarkCaro
Copy link
Author

@aeschli
It worked! Thanks!

@microsoft microsoft locked and limited conversation to collaborators Jun 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

3 participants