prettier / prettier-vscode

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

Option to let prettier determine format options instead of falling back to VSCode settings when project doesn't contain explicit prettier config #3508

Open jedwards1211 opened 2 months ago

jedwards1211 commented 2 months ago

Is your feature request related to a problem? Please describe.

There are many OSS projects that keep their code formatted with prettier with its default settings. They don't declare any explicit prettier config.

Anyone developing on a project like that needs prettier-vscode to apply the same format as running the prettier CLI would.

But prettier-vscode falls back to format options from prettier-vscode settings instead. If I could I would workaround by making the prettier-vscode settings match prettier's own defaults. But prettier has changed some defaults, for example trailing comma:

Default value changed from es5 to all in v3.0.0

(prettier-vscode still considers es5 the default)

So it's impossible to make prettier-vscode always format the way prettier would right now, without bending over backwards.

Describe the solution you'd like

An extension option: Always format the same way prettier CLI would

When enabled, if a project doesn't have explicit prettier config, prettier-vscode would ignore all format options in its own VSCode settings, and instead use the same default format options as prettier CLI. In other words, it wouldn't pass any format option values to prettier.format(...), letting prettier determine options from loading config or applying defaults.

Describe alternatives you've considered

If it were up to me I would have made this the default behavior and required users to opt into using format config from VSCode settings.

But unfortunately #3487 was rejected.

Additional context

I think it's ridiculous that the official prettier extension doesn't currently support letting the project's installed prettier control the options in all cases. Was this never a design goal? Did this use case get forgotten when people who want to format without installing prettier in projects asked for support?

It's just such an inane situation to have the official prettier extension actively cause incorrect format in a PR on a project that uses prettier, I feel so frustrated at the decisions that led to this.

aryzing commented 2 months ago

Related:

KholdStare commented 1 month ago

Agreed completely - the vscode plugin should just let the prettier CLI tool determine its own options. We migrated to prettier 3 and are having the same issue with trailing commas. 🤦

aryzing commented 1 month ago

I have a feeling that perhaps the plugin values were set as a way of providing reasonable defaults at the time. Prettier, albeit slowly, does change it's defaults from time to time. Probably best to go with the package defaults rather than trying to set them through the plugin if not explicitly set by users.

jedwards1211 commented 1 month ago

Really, the options in VSCode settings should be fallback values that only apply when formatting in a project that doesn't have prettier installed (though there should also be an option to only format if prettier is installed in the project)