-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Comments
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) |
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 |
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. |
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. |
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. |
@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. |
For those who wanna working So you need to use It's a very hacky and rude way, but it's the best which we can do in the current environment I guess. |
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. |
I am also curious how this would affect functions as children. |
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
The text was updated successfully, but these errors were encountered: