Skip to content

Respect quoted object keys, as unquoting breaks aggressive minifiers like Closure Compiler #4327

@alextreppass

Description

@alextreppass

Hi, related to the discussions in #838 and #1103, Prettier uses a consistent-as-needed approach for quoting object keys (ref: https://eslint.org/docs/rules/quote-props#options).

This behaviour is a blocker for us using Prettier in my current company (...and we'd really love to use it!) because it strips quoted object keys. This negatively impacts the input to Closure Compiler in our tool chain, which mangles all unquoted keys, and breaks places like http call serialisation where those keys have meaning.

We're unfortunately stuck with CC in our current setup, and hacks like using { ['foo']: bar } or adding // prettier ignore in various places have been viewed as muddying the code and/or too much overhead.

I'd love to see Prettier support for something like:

  • preserving object quotes, i.e. the approach suggested in #1103

  • handling quotes in a consistent way instead of consistent-as-needed, i.e. if it finds at least one quote in an object, it will ensure all keys are quoted

Is this something I could help with? Something like the PR in #1108 would be fine for us. We'd also be totally ok with consistent quoting if that's more in-line with Prettier's strongly-opinionated philosophy.

Thanks,

Metadata

Metadata

Assignees

Labels

locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.status:has prIssues with an accompanying pull request. These issues will probably be fixed soon!type:option requestIssues requesting a new option. We generally don’t accept these unless there is technical necessity.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions