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

Update: fix counting jsx comment len in max-len (fixes #12213) #12661

Merged
merged 6 commits into from Jan 9, 2020
Merged

Update: fix counting jsx comment len in max-len (fixes #12213) #12661

merged 6 commits into from Jan 9, 2020

Conversation

yeonjuan
Copy link
Member

@yeonjuan yeonjuan commented Dec 13, 2019

What is the purpose of this pull request? (put an "X" next to item)

[ ] Documentation update
[x] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

What changes did you make? (Give an overview)
This pr will fix #12213.

If the comment is in the single line jsx comment, change the comment node for checking with JSXExpressionContainer.

ex)

<>
  {/* comment */}
</>

Is there anything you'd like reviewers to focus on?

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Dec 13, 2019
@kaicataldo kaicataldo added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Dec 14, 2019
@kaicataldo
Copy link
Member

kaicataldo commented Dec 14, 2019

CI is failing because of the issue reported here. This has been fixed. 🎉

Copy link
Member

@kaicataldo kaicataldo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! Do you mind adding some tests for cases where a JSXExpressionContainer node might contain an expression in addition to a comment?

const example = <A 
	attr={a && b /* comment */} 
></A>

const example2 = <A 
	attr={/* comment */ a && b} 
></A>

@yeonjuan
Copy link
Member Author

@kaicataldo sure!

@yeonjuan
Copy link
Member Author

@kaicataldo Friendly ping :)

Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good, thanks! I left two questions about some edge cases.

I think the decision to treat the whole { /* */ } as a comment only if everything incl. braces is on the same line is a good decision, since it's a minimal change in behavior.

lib/rules/max-len.js Outdated Show resolved Hide resolved
lib/rules/max-len.js Outdated Show resolved Hide resolved
@yeonjuan
Copy link
Member Author

@kaicataldo
Thanks!. I added more test cases you mentioned.
But Maybe there would be no change in those cases compared with the actual version.

@mdjermanovic
I changed the code and commit. Thanks! :)

Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just some minor details

lib/rules/max-len.js Outdated Show resolved Hide resolved
tests/lib/rules/max-len.js Outdated Show resolved Hide resolved
Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just some detail that could be missing in otherwise very comprehensive tests.

lib/rules/max-len.js Show resolved Hide resolved
Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Just to note that this change can produce new warnings if someone has comments max len < code max len configured, which is probably quite rare but maybe this should be labeled as a breaking change?

/* eslint max-len: ["error", {
   code: 100,
   comments: 50
}]*/

var jsx = (
    <p>
       {/* this line will be a new error, because it becomes a comment line with > 50 characters */}
    </p>
)

@kaicataldo
Copy link
Member

I think it's fine to accept this as a semver-minor bug fix (though, in practice I'm not sure it matters since we are merging breaking changes in preparation for v8 right now).

Copy link
Member

@kaicataldo kaicataldo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@kaicataldo kaicataldo merged commit 14b42c3 into eslint:master Jan 9, 2020
@kaicataldo
Copy link
Member

Thanks for contributing to ESLint!

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Jul 9, 2020
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Jul 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

max-len: comments: ignores JSX
3 participants