简体   繁体   English

Eslint jsx-curly-spacing特定格式

[英]Eslint jsx-curly-spacing specific format

I'm trying to write a specific rule for curly spacing in jsx parts of React, but I can't figure out a correct combination. 我正在尝试为React的jsx部分中的卷曲间距编写一个特定规则,但我找不到正确的组合。

What I'm aiming for is the following case: 我的目标是以下情况:

<Component attr1={this.props.val1} attr2={{ object: { key: value } }}>
  { this.props.text }
</Component>

For now this is the rule I'm using: 现在,这是我使用的规则:

"react/jsx-curly-spacing": ["warn", {
  "when": "always",
  "spacing": { "objectLiterals": "never" }
}]

But it forces spaces in the brackets of attributes, allowing though the content of the Component to have spaces. 但这会在属性的方括号中强制使用空格,尽管Component的内容具有空格。

Anyone has any ideas on how to write the correct rule? 任何人都对如何编写正确的规则有任何想法?

I've tried the following rules: 我尝试了以下规则:

"key-spacing": ["error", { "beforeColon": false, "afterColon": true}],
"react/jsx-curly-spacing": ["warn", {
  "when": "never",
  "children": {
    "when": "always"
  }
}]

Check if this is ok for you. 检查是否适合您。

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

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