mirror of
https://github.com/jlengrand/detekt.git
synced 2026-03-10 08:11:23 +00:00
enable those rules from the style rule set that have not violation or obvious fixes (#3998)
* enable those rules from the style rule set that have not violation or obvious fixes * Enable UseIfEmptyOrIfBlank Co-authored-by: Markus Schwarz <post@markus-schwarz.net>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 }
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -25,8 +25,7 @@ class SLOCVisitor : DetektVisitor() {
|
||||
fun count(lines: List<String>): 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) } }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ class HtmlOutputReportSpec : Spek({
|
||||
it("renders a metric report correctly") {
|
||||
val detektion = object : TestDetektion() {
|
||||
override val metrics: Collection<ProjectMetric> = listOf(
|
||||
ProjectMetric("M1", 10000),
|
||||
ProjectMetric("M1", 10_000),
|
||||
ProjectMetric("M2", 2)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -155,8 +155,7 @@ class TooManyFunctions(config: Config = Config.empty) : Rule(config) {
|
||||
?.run {
|
||||
declarations
|
||||
.filterIsInstance<KtNamedFunction>()
|
||||
.filter { !isIgnoredFunction(it) }
|
||||
.size
|
||||
.count { !isIgnoredFunction(it) }
|
||||
} ?: 0
|
||||
|
||||
private fun isIgnoredFunction(function: KtNamedFunction): Boolean = when {
|
||||
|
||||
@@ -107,8 +107,7 @@ class ReturnCount(config: Config = Config.empty) : Rule(config) {
|
||||
|
||||
return statements.flatMap { it.collectDescendantsOfType<KtReturnExpression>().asSequence() }
|
||||
.filterNot { it.isExcluded() }
|
||||
.filter { it.getParentOfType<KtNamedFunction>(true) == function }
|
||||
.count()
|
||||
.count { it.getParentOfType<KtNamedFunction>(true) == function }
|
||||
}
|
||||
|
||||
private fun KtReturnExpression.isNamedReturnFromLambda(): Boolean {
|
||||
|
||||
@@ -104,7 +104,7 @@ class UtilityClassWithPublicConstructor(config: Config = Config.empty) : Rule(co
|
||||
}
|
||||
|
||||
private fun hasOnlyUtilityClassMembers(declarations: List<KtDeclaration>?): Boolean {
|
||||
if (declarations == null || declarations.isEmpty()) {
|
||||
if (declarations.isNullOrEmpty()) {
|
||||
return false
|
||||
}
|
||||
var containsCompanionObject = false
|
||||
|
||||
@@ -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 = """
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user