Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More lenient jsx-no-multiline-js rule #50

Closed
adidahiya opened this issue Dec 15, 2016 · 8 comments
Closed

More lenient jsx-no-multiline-js rule #50

adidahiya opened this issue Dec 15, 2016 · 8 comments

Comments

@adidahiya
Copy link
Contributor

adidahiya commented Dec 15, 2016

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
@markwongsk
Copy link
Contributor

How lenient do you think it should be? Should we just allow object literals, or do you think this should allow things like

popoverProps={this.computePopoverProps({
    popoverClassName: "docs-dropdown-ramen-popover",
})}

Also, this rule currently doesn't care about spread attributes, eg

<Dropdown {...{
    items: mocks.groups(),
    placeholder: "Ramen joint",
}} />

but that's probably a separate issue.

@piotrwitek
Copy link

@adidahiya @markwongsk this is hanging for quite some time, can we push for this change?

I really need this configurability and I think that disable for object literals is enough for a start.
Checking tslint conventions suggested name might be: "ignore-object-literal"

@adidahiya
Copy link
Contributor Author

@markwongsk I guess we could break down the use cases into "be lenient on multiline functions / lambdas" and "be lenient on object or array literals". so this rule could have two new options: ignore-functions and ignore-literals

@piotrwitek open to PRs, as always :)

@MiguelMadero
Copy link

Would it be a simpler distinction between JS statements and expressions? It seems like multline expressions (object literals, ternary, function calls, etc) make more sense than multiple statements.

@adidahiya
Copy link
Contributor Author

adidahiya commented Aug 2, 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 ^

@adidahiya adidahiya changed the title jsx-no-multiline-js should not fail on object literals More lenient jsx-no-multiline-js rule Aug 7, 2017
@pingshunhuang
Copy link

@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.

@petrdanecek
Copy link

Is there any plan or update about this topic?

@adidahiya
Copy link
Contributor Author

Closing due to deprecation, see #210

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants