简体   繁体   English

Sublime 3 中的 JsPrettier 不单引号 className

[英]JsPrettier in Sublime 3 does not single quote className

I´m using Sublime Text 3 with JSPrettier to format Javascript and JSX code.我正在使用带有 JSPrettier 的 Sublime Text 3 来格式化 Javascript 和 JSX 代码。

I have the following set in my JSPrettier configuration:我的 JSPrettier 配置中有以下设置:

// 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:即便如此,在格式化代码时 JSPrettier 仍然坚持在 className 和其他 JSX 属性上加上双引号,例如:

<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 ?关于如何解决这个问题的任何提示?

This is currently not possible using just prettier.目前仅使用更漂亮是不可能的。 Quotes in JSX will always be double and prettier will ignore this setting . JSX 中的引号将始终为双引号,prettier 将忽略此设置

If you want to understand the motivation behind this decision, you can read this GitHub thread .如果你想了解这个决定背后的动机,你可以阅读这个GitHub 线程 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.将 JSX 引号保持为 double 的论点的要点是在整个社区强制实施一种风格,配置选项越少越好。

Any hint on how to solve that ?关于如何解决这个问题的任何提示?

You can run your code through prettier-eslint .你可以通过prettier-eslint运行你的代码。 This formats your code via prettier, and then passes the result of that to eslint --fix .这通过eslint --fix格式化您的代码,然后将其结果传递给eslint --fix This way you can get the benefits of prettier's superior formatting capabilities, but also benefit from the configuration capabilities of eslint.这样既可以得到prettier 优越的格式化能力的好处,又可以受益于eslint 的配置能力。

In Sublime Text 3 this can be achieved by modifying the user preferences section of the package.在 Sublime Text 3 中,这可以通过修改包的用户首选项部分来实现。 ( Preferences > Package Settings > JSPrettier) (首选项> 包设置> JSPrettier)

{
"prettier_options": 
  {
  "singleQuote": true
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM