4

I´m using Sublime Text 3 with JSPrettier to format Javascript and JSX code.

I have the following set in my JSPrettier configuration:

// If true, will use single instead of double quotes
"singleQuote": true

Even with that, when formatting the code JSPrettier still insists on putting double quote on className and other JSX properties, like:

<div className="uxm-details-header-buttons">

or

<Icon name="refresh" />

I really expected everything with single quote, keeping double ones for special cases.

Any hint on how to solve that ?

JJJ
  • 32,902
  • 20
  • 89
  • 102
Mendes
  • 17,489
  • 35
  • 150
  • 263

2 Answers2

1

This is currently not possible using just prettier. Quotes in JSX will always be double and prettier will ignore this setting.

If you want to understand the motivation behind this decision, you can read this GitHub thread. The gist of the argument for keeping JSX quotes as double is to enforce a style across the community and the fewer config options the better.

Any hint on how to solve that ?

You can run your code through prettier-eslint. This formats your code via prettier, and then passes the result of that to eslint --fix. This way you can get the benefits of prettier's superior formatting capabilities, but also benefit from the configuration capabilities of eslint.

James Hibbard
  • 16,490
  • 14
  • 62
  • 74
1

In Sublime Text 3 this can be achieved by modifying the user preferences section of the package. ( Preferences > Package Settings > JSPrettier)

{
"prettier_options": 
  {
  "singleQuote": true
  }
}
bananaforscale
  • 820
  • 10
  • 13
  • I was doubtful this would work because why would there be a `prettier_options` property within the user settings for the specific `JSPrettier` package (isn't it inferred all these settings are `prettier_options`)? But it does seem to work for me in Sublime Text version 4121. Edit: looking at the default settings more closely, I can see that many of these settings are, in fact, 'nested' within the `prettier_options` property. – user1063287 Nov 06 '21 at 06:49