prettier / prettier-vscode

Visual Studio Code extension for Prettier
https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
MIT License
5.04k stars 446 forks source link

feat: add language-override support for VSCode configuration #3327

Closed GeekyEggo closed 1 month ago

GeekyEggo commented 2 months ago

Closes #3093

In certain cases it may be preferential to have different fallback configuration based on the language of the document, for example, the developer may have a preference towards tabs, but would still be required to use spaces for .yml files.

This pull request adds the option to override Prettier configuration, defined within VSCode's settings.json file, based on a language identifier; we are then able to fulfil the example above with the following configuration:

{
  "[yml]": {
    "prettier.useTabs": false,
    "prettier.tabWidth": 2
  },
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "prettier.useTabs": true
}

Language overridable configuration:

Question

I considered a further fallback whereby the editor's configuration could be taken into account for mappable configuration, namely tabs vs spaces and tab sizes, for example:

This would allow a developer to utilize their existing VSCode configuration for some formatting, without requiring additional prettier.* settings to be defined.

I wasn't sure how that change would be received however, so wanted to submit this for review and gather thoughts before making any further changes.

ntotten commented 1 month ago

This is great. Will review as soon as i can. Thanks!