diff --git a/config/detekt/detekt.yml b/config/detekt/detekt.yml index 737b3c321..bdb4d0fc5 100644 --- a/config/detekt/detekt.yml +++ b/config/detekt/detekt.yml @@ -127,6 +127,14 @@ style: active: true CollapsibleIfStatements: active: true + DestructuringDeclarationWithTooManyEntries: + active: true + EqualsOnSignatureLine: + active: true + ExplicitCollectionElementAccessMethod: + active: true + ExplicitItLambdaParameter: + active: true ForbiddenComment: active: true values: @@ -136,14 +144,12 @@ style: - '@author' - '@requiresTypeResolution' excludes: ['**/detekt-rules-style/**/ForbiddenComment.kt'] + ForbiddenVoid: + active: true LibraryCodeMustSpecifyReturnType: active: true excludes: ['**/*.kt'] includes: ['**/detekt-api/src/main/**/api/*.kt'] - MaxLineLength: - active: true - excludes: ['**/test/**', '**/*Test.kt', '**/*Spec.kt'] - excludeCommentStatements: true MagicNumber: excludes: [ '**/test/**', '**/*Test.kt', '**/*Spec.kt' ] ignorePropertyDeclaration: true @@ -156,8 +162,20 @@ style: - '2' - '100' - '1000' + MandatoryBracesLoops: + active: true + MaxLineLength: + active: true + excludes: ['**/test/**', '**/*Test.kt', '**/*Spec.kt'] + excludeCommentStatements: true NestedClassesVisibility: active: true + ObjectLiteralToLambda: + active: true + RedundantExplicitType: + active: true + RedundantHigherOrderMapUsage: + active: true RedundantVisibilityModifierRule: active: true ReturnCount: @@ -165,6 +183,18 @@ style: excludeGuardClauses: true SpacingBetweenPackageAndImports: active: true + TrailingWhitespace: + active: true + UnderscoresInNumericLiterals: + active: true + UnnecessaryAnnotationUseSiteTarget: + active: true + UnnecessaryFilter: + active: true + UntilInsteadOfRangeTo: + active: true + UnusedImports: + active: true UnusedPrivateMember: active: true allowedNames: '(_|ignored|expected)' @@ -172,3 +202,11 @@ style: active: true UseEmptyCounterpart: active: true + UseIfEmptyOrIfBlank: + active: true + UseIsNullOrEmpty: + active: true + UseRequire: + active: true + UseRequireNotNull: + active: true diff --git a/detekt-api/src/main/kotlin/io/gitlab/arturbosch/detekt/api/CodeSmell.kt b/detekt-api/src/main/kotlin/io/gitlab/arturbosch/detekt/api/CodeSmell.kt index b06c03783..3a01190c0 100644 --- a/detekt-api/src/main/kotlin/io/gitlab/arturbosch/detekt/api/CodeSmell.kt +++ b/detekt-api/src/main/kotlin/io/gitlab/arturbosch/detekt/api/CodeSmell.kt @@ -38,7 +38,7 @@ open class CodeSmell( "id='$id')" } - override fun messageOrDescription(): String = if (message.isEmpty()) issue.description else message + override fun messageOrDescription(): String = message.ifEmpty { issue.description } } /** @@ -100,5 +100,5 @@ open class ThresholdedCodeSmell( override fun compact(): String = "$id - $metric - ${entity.compact()}" - override fun messageOrDescription(): String = if (message.isEmpty()) issue.description else message + override fun messageOrDescription(): String = message.ifEmpty { issue.description } } diff --git a/detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/KtFileModifier.kt b/detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/KtFileModifier.kt index 3aa2873ee..f899dda56 100644 --- a/detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/KtFileModifier.kt +++ b/detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/KtFileModifier.kt @@ -25,7 +25,7 @@ class KtFileModifier : FileProcessListener { private fun KtFile.unnormalizeContent(): String { val lineSeparator = getUserData(LINE_SEPARATOR) - require(lineSeparator != null) { + requireNotNull(lineSeparator) { "No line separator entry for ktFile ${javaFileFacadeFqName.asString()}" } return StringUtilRt.convertLineSeparators(text, lineSeparator) diff --git a/detekt-metrics/src/main/kotlin/io/github/detekt/metrics/processors/ProjectSLOCProcessor.kt b/detekt-metrics/src/main/kotlin/io/github/detekt/metrics/processors/ProjectSLOCProcessor.kt index f8cc3aa69..c1071ffb6 100644 --- a/detekt-metrics/src/main/kotlin/io/github/detekt/metrics/processors/ProjectSLOCProcessor.kt +++ b/detekt-metrics/src/main/kotlin/io/github/detekt/metrics/processors/ProjectSLOCProcessor.kt @@ -25,8 +25,7 @@ class SLOCVisitor : DetektVisitor() { fun count(lines: List): Int { return lines .map { it.trim() } - .filter { trim -> trim.isNotEmpty() && !comments.any { trim.startsWith(it) } } - .size + .count { trim -> trim.isNotEmpty() && !comments.any { trim.startsWith(it) } } } } } diff --git a/detekt-report-html/src/test/kotlin/io/github/detekt/report/html/HtmlOutputReportSpec.kt b/detekt-report-html/src/test/kotlin/io/github/detekt/report/html/HtmlOutputReportSpec.kt index 9667e5823..ae69afcba 100644 --- a/detekt-report-html/src/test/kotlin/io/github/detekt/report/html/HtmlOutputReportSpec.kt +++ b/detekt-report-html/src/test/kotlin/io/github/detekt/report/html/HtmlOutputReportSpec.kt @@ -112,7 +112,7 @@ class HtmlOutputReportSpec : Spek({ it("renders a metric report correctly") { val detektion = object : TestDetektion() { override val metrics: Collection = listOf( - ProjectMetric("M1", 10000), + ProjectMetric("M1", 10_000), ProjectMetric("M2", 2) ) } diff --git a/detekt-rules-complexity/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/complexity/LongParameterList.kt b/detekt-rules-complexity/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/complexity/LongParameterList.kt index edb37aec1..0007e1ea0 100644 --- a/detekt-rules-complexity/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/complexity/LongParameterList.kt +++ b/detekt-rules-complexity/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/complexity/LongParameterList.kt @@ -134,7 +134,7 @@ class LongParameterList(config: Config = Config.empty) : Rule(config) { private fun KtParameterList.parameterCount(): Int { val preFilteredParameters = parameters.filter { !it.isIgnored() } return if (ignoreDefaultParameters) { - preFilteredParameters.filter { !it.hasDefaultValue() }.size + preFilteredParameters.count { !it.hasDefaultValue() } } else { preFilteredParameters.size } diff --git a/detekt-rules-complexity/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/complexity/TooManyFunctions.kt b/detekt-rules-complexity/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/complexity/TooManyFunctions.kt index 6103d9cce..ed619afad 100644 --- a/detekt-rules-complexity/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/complexity/TooManyFunctions.kt +++ b/detekt-rules-complexity/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/complexity/TooManyFunctions.kt @@ -155,8 +155,7 @@ class TooManyFunctions(config: Config = Config.empty) : Rule(config) { ?.run { declarations .filterIsInstance() - .filter { !isIgnoredFunction(it) } - .size + .count { !isIgnoredFunction(it) } } ?: 0 private fun isIgnoredFunction(function: KtNamedFunction): Boolean = when { diff --git a/detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/ReturnCount.kt b/detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/ReturnCount.kt index 64f45eb97..f986bd431 100644 --- a/detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/ReturnCount.kt +++ b/detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/ReturnCount.kt @@ -107,8 +107,7 @@ class ReturnCount(config: Config = Config.empty) : Rule(config) { return statements.flatMap { it.collectDescendantsOfType().asSequence() } .filterNot { it.isExcluded() } - .filter { it.getParentOfType(true) == function } - .count() + .count { it.getParentOfType(true) == function } } private fun KtReturnExpression.isNamedReturnFromLambda(): Boolean { diff --git a/detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/UtilityClassWithPublicConstructor.kt b/detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/UtilityClassWithPublicConstructor.kt index a2b2b8a25..c9a647881 100644 --- a/detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/UtilityClassWithPublicConstructor.kt +++ b/detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/UtilityClassWithPublicConstructor.kt @@ -104,7 +104,7 @@ class UtilityClassWithPublicConstructor(config: Config = Config.empty) : Rule(co } private fun hasOnlyUtilityClassMembers(declarations: List?): Boolean { - if (declarations == null || declarations.isEmpty()) { + if (declarations.isNullOrEmpty()) { return false } var containsCompanionObject = false diff --git a/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/ObjectLiteralToLambdaSpec.kt b/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/ObjectLiteralToLambdaSpec.kt index 4caca2e00..42d58d379 100644 --- a/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/ObjectLiteralToLambdaSpec.kt +++ b/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/ObjectLiteralToLambdaSpec.kt @@ -480,8 +480,8 @@ class ObjectLiteralToLambdaSpec : Spek({ context("Edge case") { // https://github.com/detekt/detekt/pull/3599#issuecomment-806389701 it( - """Anonymous objects are always newly created, - |but lambdas are singletons, + """Anonymous objects are always newly created, + |but lambdas are singletons, |so they have the same reference.""".trimMargin() ) { val code = """ diff --git a/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/VarCouldBeValSpec.kt b/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/VarCouldBeValSpec.kt index 0aef2de4f..873be5085 100644 --- a/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/VarCouldBeValSpec.kt +++ b/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/VarCouldBeValSpec.kt @@ -2,7 +2,6 @@ package io.gitlab.arturbosch.detekt.rules.style import io.gitlab.arturbosch.detekt.rules.setupKotlinEnvironment import io.gitlab.arturbosch.detekt.test.compileAndLintWithContext -import io.gitlab.arturbosch.detekt.test.lint import org.assertj.core.api.Assertions.assertThat import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.spekframework.spek2.Spek diff --git a/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/optional/MandatoryBracesLoopsSpec.kt b/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/optional/MandatoryBracesLoopsSpec.kt index 8c89052b6..a4a6d5bc0 100644 --- a/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/optional/MandatoryBracesLoopsSpec.kt +++ b/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/optional/MandatoryBracesLoopsSpec.kt @@ -310,9 +310,9 @@ class MandatoryBracesLoopsSpec : Spek({ } it("does not report nested loops with braces") { - val code = """ - fun test() { - do { + val code = """ + fun test() { + do { while (true) { println() } @@ -324,8 +324,8 @@ class MandatoryBracesLoopsSpec : Spek({ } it("does not report nested loops on single line") { - val code = """ - fun test() { + val code = """ + fun test() { var i = 0 do do i += 1 while(i < 5) while (i < 5) } @@ -335,9 +335,9 @@ class MandatoryBracesLoopsSpec : Spek({ } it("reports in nested loop outer") { - val code = """ - fun test() { - do + val code = """ + fun test() { + do do { println() } while (true)