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

Handle @Suppress("UNCHECKED_CAST") for UnsafeCast rule #726

Closed
xgouchet opened this issue Feb 6, 2018 · 9 comments
Closed

Handle @Suppress("UNCHECKED_CAST") for UnsafeCast rule #726

xgouchet opened this issue Feb 6, 2018 · 9 comments

Comments

@xgouchet
Copy link

xgouchet commented Feb 6, 2018

IntelliJ / Android Studio detect when a cast is unsafe and show a warning, which can be disabled using the @Suppress("UNCHECKED_CAST") annotation. It seems redundant to also add the UnsafeCast rule, ending with some code annotated with @Suppress("UNCHECKED_CAST", "UnsafeCast")

@Mauin
Copy link
Collaborator

Mauin commented Feb 6, 2018

If the IntelliJ warning is enough for you, disabling the rule in your detekt configuration sounds like a good idea.

@xgouchet
Copy link
Author

xgouchet commented Feb 6, 2018

Unfortunately that doesn't do it for me. IntelliJ mostly gives a warning when generics are involved, from what I gathered. The following code won't trigger any warning in IntelliJ, but are detected by the UnsafeCast rule :

val foo = something as AnotherThing

@Mauin
Copy link
Collaborator

Mauin commented Feb 6, 2018

Ah, I see. So its more about making sure the detekt rules also match the suppression rules of IntelliJ. We could add a List to each rule that can take in the names of "similar" rules in other static analysis suites. That way we could make this possible that only one @Suppress annotation will also suppress the detekt rule.

@xgouchet
Copy link
Author

xgouchet commented Feb 6, 2018

Yep that'd be great !

@Mauin
Copy link
Collaborator

Mauin commented Feb 6, 2018

I can take a look at implementing something that will make that work. WDYT @arturbosch @schalkms does something like this make sense?

@schalkms
Copy link
Member

schalkms commented Feb 6, 2018

I makes sense. I think detekt has some rules where this mechanism can be applied. This means that this should be a generic functionality if possible.
Thanks for bringing this up @xgouchet

@Mauin
Copy link
Collaborator

Mauin commented Feb 6, 2018 via email

@arturbosch
Copy link
Member

Yep, surprisingly I thought about the same thing yesterday 👍 for this

@lock
Copy link

lock bot commented Jun 20, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related topics.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants