prettier icon indicating copy to clipboard operation
prettier copied to clipboard

[JavaScript] Make consistent format for object property values with a string literal and template string

Open dimaMachina opened this issue 3 years ago • 7 comments

Description

Fixes https://github.com/prettier/prettier/issues/12408 Consistent format, do not break a new line for long string literals

Checklist

  • [x] I’ve added tests to confirm my change works.
  • [x] (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory).
  • [x] (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • [x] I’ve read the contributing guidelines.

Try the playground for this PR

dimaMachina avatar Mar 15 '22 21:03 dimaMachina

@fisker @sosukesuzuki Hey guys 👋, it's been over a month since I created my small PR that fixes the current inconsistency, can someone review it and say what you think?

dimaMachina avatar Apr 25 '22 12:04 dimaMachina

Sorry for the long delay.

I'm not sure if we want to change it, at least not until a better solution found. Making an exception here is really bad. People will ask why long identifiers/numbers/bigints don't format like this. If you want to change the output, add more tests, we'll see if it's fine to accept.

fisker avatar Apr 25 '22 12:04 fisker

@fisker which tests would you prefer that I add? Only for properties of an object?

dimaMachina avatar May 05 '22 11:05 dimaMachina

long identifiers/numbers/bigints

fisker avatar May 05 '22 13:05 fisker

@fisker added more tests

dimaMachina avatar May 06 '22 12:05 dimaMachina

@fisker @sosukesuzuki friendly ping

dimaMachina avatar May 16 '22 17:05 dimaMachina

The current behavior for string literals is intentional. Please see https://prettier.io/blog/2021/05/09/2.3.0.html#prevent-wrapping-object-properties-with-short-keys-10335httpsgithubcomprettierprettierpull10335-by-thorn0httpsgithubcomthorn0

If we're going to change something here, that should be the behavior for template literals.

thorn0 avatar Aug 29 '22 12:08 thorn0