【问题标题】:Eslint jsx-curly-spacing specific formatEslint jsx-curly-spacing 特定格式
【发布时间】:2018-09-08 10:02:57
【问题描述】:

我正在尝试为 React 的 jsx 部分中的卷曲间距编写特定规则,但我无法找出正确的组合。

我的目标是以下情况:

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

现在这是我使用的规则:

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

但它强制属性括号中的空格,允许组件的内容有空格。

有人对如何编写正确的规则有任何想法吗?

【问题讨论】:

    标签: reactjs jsx eslint curly-braces


    【解决方案1】:

    我尝试了以下规则:

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

    检查这是否适合您。

    【讨论】:

      猜你喜欢
      • 2021-04-29
      • 2023-02-22
      • 2018-08-22
      • 2019-03-02
      • 2016-09-17
      • 2016-12-11
      • 1970-01-01
      • 2018-07-04
      • 2019-06-25
      相关资源
      最近更新 更多