Closed key-notes closed 3 years ago
For single-line or multi-line objects? And were you using a different version previously? And do you have Prettier installed in your project? If so, you can double-check in the extension console (enable Extension development in Nova preferences, then a new item appear in the menu bar) if it's actually using that version of Prettier. The bundled Prettier is 2.1.2 and as of 2.0.0 Prettier defaults to always adding trailing comma's to multi-line objects: https://prettier.io/docs/en/options.html#trailing-commas
Hi Alexander,
Thanks for your reply. I've enabled the extension console, but it doesn't seem to report the version of Prettier. Here's the output:
Prettier[16:05:45.887000] Loading bundled prettier at /Users/albert/Library/Application Support/Nova/Extensions/alexanderweiss.prettier/node_modules/prettier
Prettier[16:05:46.476000] Starting Prettier service
I did have Prettier enabled upon save but disabled it today after bugs persisted. The project is set to follow the extension preferences.
I've also checked the /prettier folder listed, and even the readme.md file doesn't seem to show the version. Where exactly can users find out which version is used? Can you update the extension to output the version in the console?
Many thanks,
Albert
On Oct 11, 2020, at 10:46 AM, Alexander Weiss notifications@github.com wrote:
For single-line or multi-line objects? And were you using a different version previously? And do you have Prettier installed in your project? If so, you can double-check in the extension console (enable Extension development in Nova preferences, then a new item appear in the menu bar) if it's actually using that version of Prettier. The bundled Prettier is 2.1.2 and as of 2.0.0 Prettier defaults to always adding trailing comma's to multi-line objects: https://prettier.io/docs/en/options.html#trailing-commas
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
So is it a multiline object or single-line? And is this JS (or what language)?
The output shows it's using the bundled version. That's 2.1.2. So unless you have a .prettierrc
file that says something else it should use comma's for every line of a multiline object, but not after the last item in a single-line object.
It's a multiline object in JS. The last key/value pair incorrectly appends a comma. The project doesn't use a .prettierrc file, so it must be using 2.1.2. Hope this helps.
On Oct 11, 2020, at 8:04 PM, Alexander Weiss notifications@github.com wrote:
So is it a multiline object or single-line? And is this JS (or what language)? The output shows it's using the bundled version. That's 2.1.2. So unless you have a .prettierrc file that says something else it should use comma's for every line of a multiline object, but not after the last item in a single-line object.
In that case it’s the correct behaviour. It’s Prettier’s default: https://prettier.io/docs/en/options.html#trailing-commas
You can add a .prettierrc file to the project to change this behaviour. I’m also looking at adding a way to configure Prettier in the Nova UI without a config file.
Thanks, Alexander. Does the fact that adding a trailing comma to a multiline array is the default behavior imply that it is considered best practice?
I see that there's an option to disable it, so maybe I can create a config file—or just leave it as-is if it turns out to be correct.
On Oct 12, 2020, at 10:02 PM, Alexander Weiss notifications@github.com wrote:
In that case it’s the correct behaviour. It’s Prettier’s default: https://prettier.io/docs/en/options.html#trailing-commas
You can add a .prettierrc file to the project to change this behaviour. I’m also looking at adding a way to configure Prettier in the Nova UI without a config file.
Alexander
Prettier has a rationale on their blog here: https://prettier.io/blog/2020/03/21/2.0.0.html Hope that helps!
1.7.1 always adds a comma to the last entry in a dictionary, e.g.:
"abc": "xyz", };