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

react/jsx-no-multiline-js #2516

Open
ar53n opened this issue Dec 8, 2019 · 9 comments
Open

react/jsx-no-multiline-js #2516

ar53n opened this issue Dec 8, 2019 · 9 comments

Comments

@ar53n
Copy link

ar53n commented Dec 8, 2019

Hello, there is a suggestion to add the new rule from the tslint-react. Thank you.
https://github.com/palantir/tslint-react/blob/master/src/rules/jsxNoMultilineJsRule.ts

@ljharb
Copy link
Member

ljharb commented Dec 8, 2019

I don't see how this could be a viable rule - this would block most inline arrays, objects, or functions from being represented cleanly. Can you justify the purpose of the rule beyond "This helps reduce mental overhead when parsing JSX syntax"?

(https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-first-prop-new-line.md set to "never" seems related but not nearly enough for this)

@ar53n
Copy link
Author

ar53n commented Dec 9, 2019

Thank you for you answer. Its not about only props. This rule prevents writing large js code in render. Forces to break complex sections of code into simpler ones and extract logic from a template into functions

@ljharb
Copy link
Member

ljharb commented Dec 9, 2019

All it would force you to do is move things into intermediate variables, which isn't always an improvement - most react components i've seen have multiline JS inside their jsx, to great effect.

@BiosBoy
Copy link

BiosBoy commented Mar 13, 2020

I guess it should be up to the developer to choose btw. That's how most of the linting rules works. Anyway, it's so pitying that no port of this rule has been in eslint or eslint-plugin-react yet.

@ljharb
Copy link
Member

ljharb commented Mar 13, 2020

Currently, your choices include sticking with the year-plus-deprecated tslint, writing the rule yourself, or forgoing the rule. I'd suggest the third, even if a fourth option appeared in the future.

@BiosBoy
Copy link

BiosBoy commented Mar 14, 2020

@ljharb Well, it's not even about tslint, it's about linting in common.

OK, it seems like all the maintainers here are too busy to make such a useful rule implementation or don't think it so is for some reason. Anyway, it's a pity.

Perhaps I'll write it on my own for personal use. Thanks for your job man though.

@BiosBoy
Copy link

BiosBoy commented Mar 17, 2020

For those who wanna working jsx-no-multiline-js rule from tslint-react inside eslint config! You will need to get through nine circles of hell, but it's possible to deal with.

So you need to use typescript-eslint package inside your eslint config and also make some configurations inside it. I've made a short manual here: typescript-eslint/typescript-eslint#1737

It's a very hacky and rude way, but it's the best which we can do in the current environment I guess.

@jsphstls
Copy link
Contributor

Is there an example of how this rule works? All I see is a text descripting and the rule code. Simply going by a number of lines opens up the option to create one line expressions in the JSX, which IMO is even harder to mentally parse when abused.

Rather than porting the rule, I think a better rule would say that JSX can only contain references. I tend to write this way so that JSX only expresses the structure while any other logic is handled elsewhere. I do agree with @ljharb that the typical workaround would be to start moving things around, which does not guarantee that anything becomes easier to mentally parse.

@jsphstls
Copy link
Contributor

I am also curious how this would affect functions as children.

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

No branches or pull requests

4 participants