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
Added UnnecessaryConversionTemporary rule #279
Conversation
private val types: Set<String> = hashSetOf("Boolean", "Byte", "Short", "Integer", "Long", "Float", "Double") | ||
|
||
override fun visitCallExpression(expression: KtCallExpression) { | ||
if (types.contains(expression.calleeExpression?.text) && expression.nextSibling?.nextSibling?.text == "toString()") { |
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.
Please extract both conditons to functions with a meaningful name.
override val issue: Issue = Issue("UnnecessaryConversionTemporary", Severity.Performance, | ||
"Avoid temporary objects when converting primitive types to String") | ||
|
||
private val types: Set<String> = hashSetOf("Boolean", "Byte", "Short", "Integer", "Long", "Float", "Double") |
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.
Why not setOf()
?
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.
Because he uses types.contains later which is O(1). setOf is a LinkedSet O(n) ?
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 thought it was a HashSet
by default, my bad 👍
import org.assertj.core.api.Assertions | ||
import org.junit.jupiter.api.Test | ||
|
||
class UnnecessaryConversionTemporaryTest { |
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 thought the rest of the project used Spek?
import io.gitlab.arturbosch.detekt.api.Severity | ||
import org.jetbrains.kotlin.psi.KtCallExpression | ||
|
||
class UnnecessaryConversionTemporary(config: Config = Config.empty) : Rule(config) { |
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.
What about UnnecessaryTemporaryInstantiation
? "conversion temporary" doesn't seem very clear to me
Thanks for the code review. |
Spek is the preferred. Junit5 is still used because spek had some issues before 1.0 where I started using it |
@arturbosch ok |
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! Like this
Looks good, will be added to RC2 soon 👍 |
No description provided.