简体   繁体   English

'?' 应该放在ReactJS的行的开头

[英]'?' Should be placed at the beginning of the line in ReactJS

I am working on a ReactJS project and I am getting the following error: 我正在研究ReactJS项目,我收到以下错误:

? should be placed at the beginning of the line operator-linebreak 应该放在行operator-linebreak的开头

Here is the snippet: 这是片段:

{
  index === 0 ?
    <div className='grid__row--offset--40 row'>
      <div className='small-40 columns small-centered'>
        <a className='text--white text--center text--font-size-14 button medium radius secondary' href={lang.howTiles[0].button.url}><font><font>{lang.howTiles[0].button.title}</font></font></a>
        <a href='http://localhost/slack'><img alt='Add to Slack' height='40' width='139' src='https://platform.slack-edge.com/img/add_to_slack.png' srcSet='https://platform.slack-edge.com/img/add_to_slack.png 1x, https://platform.slack-edge.com/img/add_to_slack@2x.png 2x' /></a>
      </div>
    </div>
    : null
}

This is part of ESLint's operator-linebreak style rule: 这是ESLint的operator-linebreak样式规则的一部分:

Rule Details 规则细节

This rule enforces a consistent linebreak style for operators. 此规则为运营商强制执行一致的换行符样式。

And by default, the rule is set to allow operators to be after an expression except when using ? 默认情况下,规则设置为允许运算符表达式之后除非使用? and : : :

The default configuration is "after", { "overrides": { "?": "before", ":": "before" } } 默认配置为"after", { "overrides": { "?": "before", ":": "before" } }

Thus, put your ? 那么,把你的? on a newline before your JSX as the rule states: 在JSX之前的换行符中,规则如下:

{
  index === 0
    ? <div>
        {/* Your JSX here */}
      <div>
    : null
}

If you don't like this you can reconfigure it in your .eslintrc or other configuration file. 如果您不喜欢这样,可以在.eslintrc或其他配置文件中重新配置它。 With what you're trying to do, try this configuration: 根据您的尝试,尝试以下配置:

"operator-linebreak": [
  "error",
  "after",
  {
    "overrides": {
      ":": "before"
    }
  }
]

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

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