-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
jsx-indent is not enforced on text #1662
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
Comments
Hmm. I’d say it’s intended but unexpected behavior. Maybe we could add an option that would enable checking text indentation? |
I could see why that would be the intent in some cases. Why would you say it's intended? Naively, I would say because of elements like Maybe apply this rule only when there are other elements, not only text? That would solve the cases above, I think. But also it's really late here, so I might be overseeing a lot of things 😅 Can you think of any? Option sounds good. If the option is uncompromising, enabled by default would be nice, but if there are tricky cases, it would be reasonable to have it disabled by default. |
Disabled by default would be necessary to avoid a breaking change. You raise a good point that inside pre or textarea (possibly others), the whitespace might be significant. |
Yes, absolutely, I should have specified "enabled by default at next major release" or something. Re: whitespace, if we're thinking about use cases, when I see: <div>
<p>Foo</p>
Bar
</div> Clearly that seems like an indentation issue to me. However, seeing: <pre>
Foo
Bar
</pre> It's likely intentional. There can be HTML elements in That might be a bit of a headache, but I'm thinking there must be a logical way to look at this. I'm too new to the JSX world to be knowledgeable, but could the JSX-specific rules around whitespace help with this? |
Hey guys, any news? Maybe there are workaround? |
@VladislavAnkudinov @astorije did you find solution for this? |
@damianobarbati, we switched to Prettier when it comes to code style, and we are very happy with it :) |
There is actually no problem with <pre>
foo
</pre> will render as |
Hmm - I just tried the OP on latest master. The Test2 line is actually incorrect - it has 2 extra spaces in front of it - and the Text1 line does get autofixed. I think this can be closed. |
Consider the following, minimal configuration of ESLint +
eslint-plugin-react
:and the following JSX file:
The
Test2
line gets flagged correctly:But the
Test1
line passes the linter just fine. I looked at thejsx-indent
doc and it didn't say that indentation only applies to actual JSX elements and not to text.Is that expected behavior, or a bug / false positive? If expected behavior, should the doc mention it?
Apologies if there is already an issue about this, there are maaany opened issues about indentation and I might have skipped it if so.
The text was updated successfully, but these errors were encountered: