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

Default value for `trailingComma` is ignored by the extension or not true in the documentation #3067

Closed kergian closed 4 months ago

kergian commented 10 months ago

Summary

While configuring my Prettier (only as a plugin for VSCode) with the .prettierrc config file, I found that according to documentation, the default value of trailingComma is either ignored by the plugin or it is not the right value in the documentation.

The documentation says the default value is all, while the code is formatted according to the value es5.

As it was found: function parameters are divided into several lines, in the default Prettier config the comma after the last parameter is removed

Steps To Reproduce:

  1. Use VSCode Insiders (tested with version 1.81.0)
  2. Install Prettier extension (tested with version 9.19.0)
  3. Use the default value for the trailingComma configure parameter
  4. Format the code with the Prettier extension. Example:
    export function setupCounter(
    element: HTMLButtonElement,
    arg0: any,
    arg1: any
    ) { ...some }
  5. Observe that there are no commas after the last argument of the function, although according to the documentation it should be.

Expected result

According to the documentation for the value all there must be a comma after the last argument of the function if the argument is divided into a set of lines

VS Code Version:

Version: 1.81.0-insider Commit: 31f183271b0d1f24a2052f6eccbb76bdef45d60b Date: 2023-07-07T05:35:32.760Z Electron: 22.3.14 ElectronBuildId: 21893604 Chromium: 108.0.5359.215 Node.js: 16.17.1 V8: 10.8.168.25-electron.0 OS: Darwin arm64 22.5.0

Prettier Extension Version:

9.19.0

OS and version: macOS Ventura 13.4.1 (22F82)

Tri125 commented 9 months ago

The extension is still using prettier 2.8.8 with the defaults configuration from that version. The default value of trailingComma was changed in prettier 3.0.0.

3069 should fix this.

According to the Readme we should have it in version 10 of the extension.

I personally can't wait, in our project we don't create a config file because we rely on the default provided by prettier. At the moment we are in a situation where the extension run with it's own internal outdated config while our CI tools runs with the default from prettier 3, conflicting with each others.

github-actions[bot] commented 7 months ago

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

kergian commented 7 months ago

For some strange reason, even considering @Tri125 comment, I have everything working as it should, latest version of the extension: v10.1.0, there is no trailingComma parameter in the config, but the plugin puts a comma after function parameters if they look like multilines.

vzvu3k6k commented 6 months ago

3069 has been reverted in v10.1.0, reverting back to prettier 2.x (changelog). And the extension's default value of trailingComma has been also reverted from all to es5 as it is in prettier 2.x (commit).

But as kergian says, placing a .prettierrc prevents the extension's prettier setting to be used.

It works even though the .prettierrc has no entries (it requires {} - an empty file won't work). The implementation only falls back to the extension's Prettier options if no config file exists (PrettierEditService.ts#L528) as README says.

github-actions[bot] commented 4 months ago

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

github-actions[bot] commented 1 month ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.