prettier-vscode icon indicating copy to clipboard operation
prettier-vscode copied to clipboard

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

Open jedwards1211 opened this issue 1 year ago • 6 comments
trafficstars

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.

jedwards1211 avatar Aug 14 '24 16:08 jedwards1211

Related:

  • https://github.com/prettier/prettier-vscode/issues/3453
  • https://github.com/prettier/prettier-vscode/issues/3508

aryzing avatar Sep 03 '24 11:09 aryzing

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. 🤦

KholdStare avatar Sep 23 '24 19:09 KholdStare

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.

aryzing avatar Sep 23 '24 19:09 aryzing

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)

jedwards1211 avatar Sep 25 '24 00:09 jedwards1211

This issue has been labeled as stale due to inactivity. Reply to keep this issue open.

github-actions[bot] avatar Feb 11 '25 02:02 github-actions[bot]

Not stale

jedwards1211 avatar Feb 11 '25 05:02 jedwards1211

Quoting the line from the output log, for ease of searching for this issue:

No local configuration (i.e. .prettierrc or .editorconfig) detected, falling back to VS Code configuration

robatwilliams avatar Sep 09 '25 13:09 robatwilliams

I also strongly desire this.

2754github avatar Nov 04 '25 08:11 2754github