Apply more formatting rules to our code (#3615)

* Update formatting configuration

* Apply autocorrect to the project

* Format using ktlint 0.41 --experimental

* Minor manual improvements
This commit is contained in:
Brais Gabín
2021-03-28 19:00:03 +02:00
committed by GitHub
parent 84009f24af
commit 92b6a01903
285 changed files with 3103 additions and 1739 deletions

View File

@@ -45,10 +45,12 @@ import org.jetbrains.kotlin.psi.psiUtil.getReceiverExpression
*/
class ForEachOnRange(config: Config = Config.empty) : Rule(config) {
override val issue = Issue("ForEachOnRange",
Severity.Performance,
"Using the forEach method on ranges has a heavy performance cost. Prefer using simple for loops.",
Debt.FIVE_MINS)
override val issue = Issue(
"ForEachOnRange",
Severity.Performance,
"Using the forEach method on ranges has a heavy performance cost. Prefer using simple for loops.",
Debt.FIVE_MINS
)
private val minimumRangeSize = 3
private val rangeOperators = setOf("..", "downTo", "until", "step")

View File

@@ -28,15 +28,19 @@ import org.jetbrains.kotlin.psi.KtExpression
*/
class UnnecessaryTemporaryInstantiation(config: Config = Config.empty) : Rule(config) {
override val issue: Issue = Issue("UnnecessaryTemporaryInstantiation", Severity.Performance,
"Avoid temporary objects when converting primitive types to String.",
Debt.FIVE_MINS)
override val issue: Issue = Issue(
"UnnecessaryTemporaryInstantiation",
Severity.Performance,
"Avoid temporary objects when converting primitive types to String.",
Debt.FIVE_MINS
)
private val types: Set<String> = hashSetOf("Boolean", "Byte", "Short", "Integer", "Long", "Float", "Double")
override fun visitCallExpression(expression: KtCallExpression) {
if (isPrimitiveWrapperType(expression.calleeExpression) &&
isToStringMethod(expression.nextSibling?.nextSibling)) {
isToStringMethod(expression.nextSibling?.nextSibling)
) {
report(CodeSmell(issue, Entity.from(expression), issue.description))
}
}