-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add auto fix for self-closing-comp #770
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
Add auto fix for self-closing-comp #770
Conversation
@@ -107,73 +107,84 @@ ruleTester.run('self-closing-comp', rule, { | |||
invalid: [ | |||
{ | |||
code: 'var contentContainer = <div className="content"></div>;', | |||
output: 'var contentContainer = <div className="content"/>;', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these should all autofix with a space before the />
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand, as that change makes the tests fail. It seems that if there is no space before the >
then after fixing there should continue to be no space before the >
.
Would you prefer that the replacing value located in lib/rules/self-closing-comp.js - Line 88 be changed from "/>"
to " />"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's exactly what i'm suggesting. <div />
is correct, not <div/>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for clarifying, I didn't realize the white space was part of the rule. I have added that behavior now. Do you specifically want to enforce a single white space character, or would multiple be valid? For example, would the following be invalid:
<Foo /> // double white space
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think multiple would be ok, but we'd want to encourage single.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that is the only ordering possible, because the jsx-space-before-closing
rule does not produce a warning unless there is a self-closing tag. This obviously cannot happen if self-closing-comp
is in violation, because that rule implies there is no self-closing tag. Therefore I think it is impossible for jsx-space-before-closing
to produce an error on the same node as self-closing-comp
, and the warning conditions for the two rules are mutually exclusive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but someone may not have enabled jsx-space-before-closing
- I want the burden of running that extra autofixer to be on someone who has chosen "never" - which is a very unconventional choice - not on the vast majority of JSX authors who always put a space there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, in that case I can re-commit the white space character before a self-closing tag. Should there be any other behavior for white space than what is in f6cc36a?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope, that looks fine to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, let me know if you want commits squashed before merging.
Merged, thanks! |
If you would like comments removed just let me know. Thanks for the awesome project.