-
-
Notifications
You must be signed in to change notification settings - Fork 822
Add new ObjectExtendsThrowable rule #3443
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 new ObjectExtendsThrowable rule #3443
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3443 +/- ##
============================================
+ Coverage 80.26% 80.28% +0.02%
- Complexity 2778 2785 +7
============================================
Files 453 454 +1
Lines 8391 8415 +24
Branches 1605 1609 +4
============================================
+ Hits 6735 6756 +21
Misses 787 787
- Partials 869 872 +3
Continue to review full report at Codecov.
|
| CodeSmell( | ||
| issue = issue, | ||
| entity = Entity.from(element = it), | ||
| message = issue.description |
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 would recommend using a simpler message with the class name. Duplicating issue description into message makes the output feel duplicate. (See https://github.com/chao2zhang/detekt/pull/5/files, if both the message and issue description are duplicate and length, it will look pretty bad)
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.
Thanks for the suggestion. I was trying to maintain consistency with some of the existing exception rules, such as:
- InstanceOfCheckForException
- NotImplementedDeclaration
- RethrowCaughtException
- ThrowingExceptionInMain
These are just a few that reference issue.description when setting the message parameter.
Are we satisfied with the current issue description or do we feel that even the issue description could use some shortening? If we make it shorter, do we still want a separate CodeSmell message? Thanks again.
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 have not forgotten about this. Just awaiting further feedback. 🙂
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 do agree with chao here. One is the desciprtion of the rule and the oher is the description of one particular smell. I think that a description like: "XXX should be a class instead of an object because it extends from YYY" is enought for the message.
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.
or "from a throwable class"... or something like this. I'm not too good with this things :P
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.
Thanks everyone. Let me know if this works b6197eb.
...tions/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/exceptions/ObjectExtendsThrowable.kt
Outdated
Show resolved
Hide resolved
...tions/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/exceptions/ObjectExtendsThrowable.kt
Show resolved
Hide resolved
| object BanException : Throwable() | ||
| object AuthException : RuntimeException() | ||
| object ReportedException : Exception() | ||
| object FatalException : Error() | ||
| object ObjectCustomException : CustomException("singleton custom exception") |
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.
Thank you for the exhaustive test cases!
cortinico
left a comment
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.
Great work 👍 Left a couple of nits
An Exceptions rule that reports when an
objectextend any type ofThrowable. Although usingobjectmay look innocent at times, having one that extends aThrowable/Exceptioninadvertently introduces a global singleton exception instance. Any custom exception should be made instantiable by being defined as a regularclass.Addresses #3436.