Skip to content

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

Merged
merged 5 commits into from
Aug 20, 2016
Merged

Add auto fix for self-closing-comp #770

merged 5 commits into from
Aug 20, 2016

Conversation

pl12133
Copy link
Contributor

@pl12133 pl12133 commented Aug 15, 2016

If you would like comments removed just let me know. Thanks for the awesome project.

@@ -107,73 +107,84 @@ ruleTester.run('self-closing-comp', rule, {
invalid: [
{
code: 'var contentContainer = <div className="content"></div>;',
output: 'var contentContainer = <div className="content"/>;',
Copy link
Member

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

Copy link
Contributor Author

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 " />"?

Copy link
Member

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/>

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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!

Copy link
Contributor Author

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.

@yannickcr yannickcr merged commit d89bc05 into jsx-eslint:master Aug 20, 2016
@yannickcr
Copy link
Member

Merged, thanks!

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

Successfully merging this pull request may close these issues.

4 participants