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

Fix: fix the fixer of lone comma with comments (fixes #10632) #11154

Merged
merged 3 commits into from Dec 8, 2018
Merged

Fix: fix the fixer of lone comma with comments (fixes #10632) #11154

merged 3 commits into from Dec 8, 2018

Conversation

g-plane
Copy link
Member

@g-plane g-plane commented Dec 4, 2018

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

[x] Bug fix

What changes did you make? (Give an overview)

Fixes #10632

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

When I tried reproducing the issue, I found that if the source code uses CRLF as linebreak, this issue may not occur, because inside the function getReplacedText, the between branch only replaces LF with empty string. So in this PR, I fix it too.

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Dec 4, 2018
Copy link
Member

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

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

Left a suggestion about further improving the line break matcher.

The test case looks good in general, but I'm not following what changed. Could you please walk me through what the test case's original output was, and how your change in the rule code helped fix it?

(Part of the issue is that usually, bug fixes are converting a valid case into an invalid case, or vice versa, and RuleTester is almost self-documenting in those cases; in this case, we're taking an invalid case with a bad autofix and turning it into an invalid case with better autofix. RuleTester does not document that quite as well.)

@@ -85,7 +85,7 @@ module.exports = {
function getReplacedText(styleType, text) {
switch (styleType) {
case "between":
return `,${text.replace("\n", "")}`;
return `,${text.replace(/\r?\n/, "")}`;
Copy link
Member

Choose a reason for hiding this comment

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

Might be good to look in ast-utils; I think we have a regular expression stored in there which handles all of the JS line break types, including \u2028 and \u2029.

Copy link
Member Author

@g-plane g-plane Dec 4, 2018

Choose a reason for hiding this comment

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

Thanks! And I have updated. You can check the latest changes.

@g-plane
Copy link
Member Author

g-plane commented Dec 4, 2018

@platinumazure I think you can use the ESLint online demo to see how ESLint behaves currently. So here I will talk the changed output and how it works.

Consider the input below:

[
  one // line
  , /* block
  comment */
]

And the changed output will be:

[
  one, // line
   /* block
  comment */
]

In the case above, there is a block comment after comma token, so in my changes you can see it gets the commemts after the comma token. Then, we check the comment and make sure it's a block comment and the comment keeps with comma token on the same line. (If it doesn't match this check, just does as current.)

The case above matches the check. On the other hand, if there is a real token after the comma, the auto fixer works well. So, at this case, we treat the block comment as a token (Yeah, it's not a real token because comment isn't a token). Next, we can use the last fixer function or first fixer function to handle this.

(I'm not an English speaker and sorry for my poor English.)

Copy link
Member

@platinumazure platinumazure 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! And thank you for the explanation as well!

Leaving open for a couple of days in case other team members want to review.

@platinumazure
Copy link
Member

For what it's worth @g-plane, your English is great! And I apologize if it seemed I had difficulty understanding due to how you were writing- in reality, I was just having difficulty understanding the technical change.

@g-plane
Copy link
Member Author

g-plane commented Dec 5, 2018

@platinumazure platinumazure added bug ESLint is working incorrectly rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Dec 7, 2018
@platinumazure
Copy link
Member

platinumazure commented Dec 7, 2018

@g-plane Thanks for the link, it helps!

I assume there is an existing test case that shows the previous logic (working correctly, without a block comment after the comma)?

@g-plane
Copy link
Member Author

g-plane commented Dec 8, 2018

@platinumazure That's right.

Copy link
Member

@not-an-aardvark not-an-aardvark 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!

@not-an-aardvark not-an-aardvark merged commit 3bf0332 into eslint:master Dec 8, 2018
@g-plane g-plane deleted the fix-10632 branch December 8, 2018 03:22
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Jun 7, 2019
@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 Jun 7, 2019
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 rule Relates to ESLint's core rules
Projects
None yet
3 participants