4

我正在使用带有 JSPrettier 的 Sublime Text 3 来格式化 Javascript 和 JSX 代码。

我的 JSPrettier 配置中有以下设置:

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

即使这样,在格式化代码时 JSPrettier 仍然坚持在 className 和其他 JSX 属性上加上双引号,例如:

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

或者

<Icon name="refresh" />

我真的期望一切都用单引号,特殊情况下保留双引号。

关于如何解决的任何提示?

4

2 回答 2

1

在 Sublime Text 3 中,这可以通过修改包的用户首选项部分来实现。( 首选项 > 包设置 > JSPrettier)

{
"prettier_options": 
  {
  "singleQuote": true
  }
}
于 2020-02-17T17:14:37.567 回答
0

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.

于 2017-12-03T18:53:58.060 回答