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

New: no-useless-catch rule (fixes #11174) #11198

Merged
merged 1 commit into from Dec 23, 2018

Conversation

agrasley
Copy link
Contributor

Moves no-useless-catch from an internal rule to a core rule. Adds docs and test cases.

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

[ ] Documentation update
[ ] Bug fix (template)
[X] 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:

#11174

What changes did you make? (Give an overview)

  • Moved no-useless-catch from an internal rule to a core rule.
  • Made tests more robust for no-useless-catch.
  • Added documentation for no-useless-catch.
  • no-useless-catch now reports the whole TryStatement node when there is no finally clause.

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

Double-checking the type and category of the rule and whether it should be recommended. Also I don't think this is a candidate for the --fix option but if people believe it is and could give me pointers on how to implement it I'd be glad to do so.

@jsf-clabot
Copy link

jsf-clabot commented Dec 16, 2018

CLA assistant check
All committers have signed the CLA.

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Dec 16, 2018
@agrasley agrasley changed the title New: no-useless-catch rule (#11174) New: no-useless-catch rule (fixes #11174) Dec 16, 2018
Copy link
Sponsor Contributor

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

Can we add some tests that ensure that it warns on the same pattern inside an async function?

.eslintrc.js Show resolved Hide resolved
@agrasley
Copy link
Contributor Author

@ljharb Do you have a case in mind that you feel would be important to guard against for async functions? I'm happy to add it but I want to make sure that we're on the same page as far as what it should be testing for.

So would something like this be what you had in mind?:

valid:

async () => {
  try {
    await doSomething();
  } catch (e) {
    doSomethingAfterCatch();
    throw e;
  }
}

invalid:

async () => {
  try {
    await doSomething();
  } catch (e) {
    throw e;
  }
}

@ljharb
Copy link
Sponsor Contributor

ljharb commented Dec 16, 2018

Both of those are perfect :-) i'm pretty confident they'll pass as-is, but this way the intention is clearly documented by the test cases for future explorers.

Moves no-useless-catch from an internal rule to a core rule. Adds docs
and test cases.
@agrasley
Copy link
Contributor Author

Okay, those have been added now.

@platinumazure platinumazure added rule Relates to ESLint's core rules feature This change adds a new feature to ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Dec 17, 2018
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 added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Dec 22, 2018
@not-an-aardvark
Copy link
Member

Marking as accepted because #11174 has also been marked as accepted.

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!

Only one thought: Should the docs make some explicit mention that try/catch (with rethrow)/finally can be replaced with try/finally? It's a corner case but some users might not be aware that try/finally workout catch is valid.

@platinumazure
Copy link
Member

I've decided we can add to the documentation in a separate change, so I'll merge this. Thanks @agrasley for contributing!

@platinumazure platinumazure merged commit 2b5a602 into eslint:master Dec 23, 2018
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Jun 22, 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 22, 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 feature This change adds a new feature to ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants