Search code examples
htmlconfigurationvisual-studio-codeformatting

VSCode: turn off format on save only in specific directory


I'd like to configure VSCode to not auto-format files in a specific directory.

Background: I'm writing a library that renders json into html. For testing, I'm comparing the results with pre-rendered html snippets. Unfortunately, VSCode *cks up my formatting of the html files with it's auto-format feature. Although auto-formatting is very handy for my actual code, I'd like to turn it off for those snippets.

Is there any option to turn it off for files in a specific directory or for files matching a specific pattern in filename? If yes: Is it possible to have the settings stored in the project folder?

So far I only found the option to turn auto-formatting on/off per language. This is close but not perfect, since there are other html files in my project that would benefit from auto-formatting.


Solution

  • Try to add (for example, if you language is JavaScript):

    "[javascript]": {
        "editor.formatOnSave": true
    },
    "files.associations": {
        "src/some-folder/*.js": "plaintext"
    }