-
-
Notifications
You must be signed in to change notification settings - Fork 784
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
Add UnreachableCatchBlock rule #3478
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3478 +/- ##
============================================
- Coverage 80.28% 80.27% -0.02%
- Complexity 2784 2793 +9
============================================
Files 454 455 +1
Lines 8415 8434 +19
Branches 1608 1614 +6
============================================
+ Hits 6756 6770 +14
Misses 789 789
- Partials 870 875 +5
Continue to review full report at Codecov.
|
/** | ||
* Reports unreachable catch blocks. | ||
* | ||
* <noncompliant> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be good to add an extended description and compliant code example in order to have a better understand of the rule from the user point of view.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
val tryExpression = catchClause.getStrictParentOfType<KtTryExpression>() ?: return | ||
val prevCatchClauses = tryExpression.catchClauses.takeWhile { it != catchClause } | ||
if (prevCatchClauses.isEmpty()) return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this if empty
check even necessary considering the any
statement underneath?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to avoid unnecessary catchClassDescriptor()
call in the following case.
try {
} catch (e: Exception) {
}
I like this rule 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice one!
Fixes #305