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 wrong indentation about catch,finally #7371

Merged
merged 3 commits into from Oct 28, 2016

Conversation

mysticatea
Copy link
Member

@mysticatea mysticatea commented Oct 15, 2016

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

[X] Bug fix (template)

Tell us about your environment

  • ESLint Version: master
  • Node Version: 6.3.0
  • npm Version: 3.8.9

What parser (default, Babel-ESLint, etc.) are you using?

  • default

Please show your full configuration:

  • nothing

What did you do? Please include the actual source code causing the issue.

I realized this while I was reviewing #7347.

$ eslint test.js --no-ignore --no-eslintrc --rule "indent:error" --fix

test.js is:

{
    try {
    }
catch (err) {
    }
finally {
    }
}

What did you expect to happen?

ESLint fixes the code to:

{
    try {
    }
    catch (err) {
    }
    finally {
    }
}

What actually happened? Please include the actual, raw output from ESLint.

ESLint fixed the code to:

{
    try {
    }
catch (err) {
}
finally {
}
}

What changes did you make? (Give an overview)

If catch/finally keywords are at the first on a line, indent rule reports wrong indentations.

The rule does not report indentations of those keywords, then the rule makes indentations of those blocks as based on the keywords. As a result, the indentations are wrong.

In a similar case, else keyword, the rule handles the keyword correctly.
This PR changes indent rule about catch and finally (and while of DoWhileStatement) keywords as the same way of else keyword.

semver-minor: this is a bug fix which increases warnings. The following code has been no warning before.

try {
    doSomething()
}
     catch (err) { /*ignore*/ }

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

Is the place of this change right?
I wrote the code in the same place with the code of else keyword.

@mysticatea mysticatea added bug ESLint is working incorrectly enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion labels Oct 15, 2016
@eslintbot
Copy link

LGTM

@mention-bot
Copy link

@mysticatea, thanks for your PR! By analyzing the history of the files in this pull request, we identified @vitorbal, @valorkin and @gyandeeps to be potential reviewers.

}
finally {
}
}
Copy link
Member

@gyandeeps gyandeeps Oct 16, 2016

Choose a reason for hiding this comment

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

nit: I think we should stick to string concat here because this makes it hard to read in this particular scenario. (or maybe its just me)

Copy link
Member

Choose a reason for hiding this comment

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

Agreed.

@eslintbot
Copy link

LGTM

@mysticatea
Copy link
Member Author

I updated as using string concatenations.

@eslintbot
Copy link

LGTM

@mysticatea
Copy link
Member Author

I'm merging this PR since this is a good companion of brace-style rule's autofix.

@mysticatea mysticatea merged commit 1d5146f into master Oct 28, 2016
@mysticatea mysticatea deleted the fix-indent-of-catch-finally branch October 28, 2016 09:59
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@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 Feb 6, 2018
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.

None yet

6 participants