question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

More lenient jsx-no-multiline-js rule

See original GitHub issue

I think the rule should be lenient about these kinds of multiline expressions because they don’t hinder readability too much:

image

update: we should also add more exemptions:

  • allow-function-call to ignore function call expressions
  • allow-literal to ignore checking object and array literals
  • allow-element to ignore JSX elements

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:6
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
pingshunhuangcommented, Apr 3, 2018

@adidahiya Could you please recommend a way for the 2 cases you gave above. I got this rules triggered a lot and I’m not sure how to improve them. Thanks.

1reaction
adidahiyacommented, Aug 7, 2017

@MiguelMadero eh, that wouldn’t really solve my use case because so much of JS syntax is a valid expression. My primary motivation for using this rule was to ban multiline ternarys and function calls (primarily .map, since it’s used to generate lists)

// bad
<div className={
    someComplicatedCondition
        ? "positive-case"
        : "positive-case"}
    otherProp={true}
/>

// bad
<div>
    {this.props.foo.map((f) => {
        return <span>{f}</span>;
    })}
</div>

I could imagine another option here for stylistic preference, however, ignore-conditional-expressions, to allow multiline ternarys like in my first example ^

Read more comments on GitHub >

github_iconTop Results From Across the Web

New Rule: jsx-no-multiline-js · Issue #4 · palantir/tslint-react
This rule is most for readability than another one reason and its awesome, I just get a legacy project with nested multiline jsx...
Read more >
Multiline JS expressions inside JSX are forbidden
I use tslint to check my react typescript app. I created this and it works but i get this message from tslint: "Multiline...
Read more >
Introducing JSX
By default, React DOM escapes any values embedded in JSX before rendering them. Thus it ensures that you can never inject anything that's...
Read more >
multiline-ternary - ESLint - Pluggable JavaScript Linter
This rule enforces or disallows newlines between operands of a ternary expression. Note: The location of the operators is not enforced by this...
Read more >
ValidateJavaScript - Online Tool to Find & Fix JavaScript Errors
ValidateJavaScript is an online validating (or linting) tool that will automatically find basic errors and help prevent potentially destructive bugs in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found