0

I have a standard Angular app and am trying to disable trailing commas in Prettier. So I go into vscode settings (both user and workspace) and set trailing commas to none:

enter image description here

I also have an .editorconfig file and tslint.json files. The tslint.json file has trailing commas set to false. Lastly, I am using the Prettier Formatter for VSCode extension. Anyway, the trailing commas still appear unless I put this in package.json:

"prettier": {
    "bracketSpacing": true,
    "singleQuote": true,
    "trailingComma": "none"
 }

How come if my preferences are set in VSCode settings that I then have to add this snippet of redundant code in the package.json file?

Thanks for any helpful tips.

fumeng
  • 1,771
  • 5
  • 22
  • 61

3 Answers3

1

Maybe you have to set "trailing-comma": true in tslint.json. Anyway good practice is to install https://github.com/prettier/tslint-config-prettier so you don't get conflicts.

Matus Jurika
  • 305
  • 1
  • 7
  • Sorry, forgot to mention. trailing-comma is set to false in tslint.json. But I am using the Prettier formatter for VSCode, not the one you mentioned. – fumeng Aug 26 '20 at 13:28
1

Is your default formatter set to prettier? Or the default Typescript and Javascript language features?

You can check this by opening a typescript file and pressing ctrl + shift + p (for windows)

and looking for format document with and looking which is the default.

Ondie
  • 151
  • 5
  • I get this error: Extension 'esbenp.prettier-vscode' is configured as formatter but not available. Select a different default formatter to continue. – fumeng Aug 26 '20 at 13:35
  • Did you install the prettier extension? You can find it on the left side or press (ctrl + shift + x) and search for Prettier - Code formatter. – Ondie Aug 26 '20 at 13:36
  • Sorry, I just disabled Prettier. Now I've re-enabled and format document just works -- so i'm assuming it found that file. – fumeng Aug 26 '20 at 13:38
  • Wait, but it still leaves a trailing comma unless I put that snippet back in package.json. – fumeng Aug 26 '20 at 13:39
  • 1
    I would put the configuration in a `.prettierrc` file not in package.json, and that means you're not using prettier as a formatter, but the default one. – Ondie Aug 26 '20 at 13:42
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/220498/discussion-between-ondie-and-fumeng). – Ondie Aug 26 '20 at 13:44
1

Remove "trailing-comma" in yout tslint config.

intropedro
  • 2,804
  • 1
  • 24
  • 25