简体   繁体   English

Eslint react/jsx-one-expression-per-line:允许变量和 JSX 字符串在同一行,但不允许元素

[英]Eslint react/jsx-one-expression-per-line: allow variables and JSX strings on the same line, but not elements

Eg for this JSX:例如对于这个 JSX:

<h1>
  Hi {name}
</h1>

The react/jsx-one-expression-per-line plugin wants it as: react/jsx-one-expression-per-line插件希望它为:

<h1>
  Hi
  {' '}
  {name}
</h1>

or或者

<h1>
  {`Hi ${name}`}
</h1>

I think both of those are ugly.我觉得这两个都很丑I want to allow the first example.我想允许第一个例子。 However, I don't want to disable the plugin because I don't want to allow multiple elements on one line:但是,我不想禁用插件,因为我不想在一行上允许多个元素:

<p>hi</p><p>bye</p>

How would I do this?我该怎么做?

How about this?这个怎么样?

const welcomeMessage = `Hi ${name}`;
<h1>
  {welcomeMessage}
</h1>

You can disable the rule for that line only:您只能禁用该行的规则:

<h1>
{/* eslint-disable-next-line react/jsx-one-expression-per-line */}
  Hi {name}
</h1>

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

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