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

Enable Ktlint two TrailingComma rules to default setting in Ktlint #5386

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion build-logic/src/main/kotlin/module.gradle.kts
Expand Up @@ -52,7 +52,7 @@ tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = Versions.JVM_TARGET
freeCompilerArgs += listOf(
"-progressive",
"-progressive"
)
allWarningsAsErrors = project.findProperty("warningsAsErrors") == "true"
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Expand Up @@ -18,7 +18,7 @@ allprojects {
io.gitlab.arturbosch.detekt.extensions.DetektExtension.DEFAULT_SRC_DIR_JAVA,
io.gitlab.arturbosch.detekt.extensions.DetektExtension.DEFAULT_TEST_SRC_DIR_JAVA,
io.gitlab.arturbosch.detekt.extensions.DetektExtension.DEFAULT_SRC_DIR_KOTLIN,
io.gitlab.arturbosch.detekt.extensions.DetektExtension.DEFAULT_TEST_SRC_DIR_KOTLIN,
io.gitlab.arturbosch.detekt.extensions.DetektExtension.DEFAULT_TEST_SRC_DIR_KOTLIN
)
buildUponDefaultConfig = true
baseline = file("$rootDir/config/detekt/baseline.xml")
Expand Down
Expand Up @@ -16,7 +16,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
class AnnotationExcluder(
root: KtFile,
private val excludes: List<Regex>,
private val context: BindingContext,
private val context: BindingContext
) {

private val fullQualifiedNameGuesser = FullQualifiedNameGuesser(root)
Expand All @@ -26,19 +26,19 @@ class AnnotationExcluder(
root,
excludes.mapAll { it }
.map { it.replace(".", "\\.").replace("*", ".*").toRegex() },
BindingContext.EMPTY,
BindingContext.EMPTY
)

@Deprecated("Use AnnotationExcluder(List<Regex>, KtFile) instead")
constructor(
root: KtFile,
excludes: List<String>,
excludes: List<String>
) : this(
root,
excludes.map {
it.replace(".", "\\.").replace("*", ".*").toRegex()
},
BindingContext.EMPTY,
BindingContext.EMPTY
)

/**
Expand Down
Expand Up @@ -86,7 +86,7 @@ fun <T : Any, U : Any> configWithFallback(
*/
fun <T : Any> configWithAndroidVariants(
defaultValue: T,
defaultAndroidValue: T,
defaultAndroidValue: T
): ReadOnlyProperty<ConfigAware, T> = configWithAndroidVariants(defaultValue, defaultAndroidValue) { it }

/**
Expand Down
Expand Up @@ -44,7 +44,7 @@ constructor(
source: SourceLocation,
endSource: SourceLocation,
text: TextLocation,
filePath: FilePath,
filePath: FilePath
) : this(source, text, filePath.absolutePath.toString(), filePath) {
this.endSource = endSource
}
Expand Down
Expand Up @@ -7,5 +7,5 @@ package io.gitlab.arturbosch.detekt.api.internal
@Target(AnnotationTarget.PROPERTY)
@Retention(AnnotationRetention.RUNTIME)
annotation class Configuration(
val description: String,
val description: String
)
Expand Up @@ -97,7 +97,7 @@ class ConfigPropertySpec {
"present" to listOf(
mapOf("value" to "a", "reason" to "reasonA"),
mapOf("value" to "b", "reason" to null),
mapOf("value" to "c"),
mapOf("value" to "c")
)
) {
val present: ValuesWithReason by config(defaultValue)
Expand Down
1 change: 0 additions & 1 deletion detekt-api/src/test/resources/library/Dummy.kt
@@ -1,2 +1 @@
package cases.library

1 change: 0 additions & 1 deletion detekt-api/src/test/resources/library/Dummy2.kt
@@ -1,2 +1 @@
package cases.library

Expand Up @@ -22,7 +22,7 @@ fun createCorrectableFinding(ruleName: String = "TestSmell", fileName: String =
fun createFinding(
issue: Issue,
entity: Entity,
message: String = entity.signature,
message: String = entity.signature
) = CodeSmell(
issue = issue,
entity = entity,
Expand Down
Expand Up @@ -8,7 +8,7 @@ import java.nio.file.Paths

class ConfigExporter(
private val arguments: CliArgs,
private val outputPrinter: Appendable,
private val outputPrinter: Appendable
) : Executable {

override fun execute() {
Expand Down
Expand Up @@ -30,7 +30,7 @@ class MainSpec {
arguments(arrayOf("--run-rule", "RuleSet:Rule"), Runner::class),
arguments(arrayOf("--print-ast"), AstPrinter::class),
arguments(arrayOf("--version"), VersionPrinter::class),
arguments(emptyArray<String>(), Runner::class),
arguments(emptyArray<String>(), Runner::class)
)
}

Expand Down
Expand Up @@ -18,7 +18,7 @@ internal fun generateBindingContext(
classpath: List<String>,
files: List<KtFile>,
debugPrinter: (() -> String) -> Unit,
warningPrinter: (String) -> Unit,
warningPrinter: (String) -> Unit
): BindingContext {
if (classpath.isEmpty()) {
return BindingContext.EMPTY
Expand All @@ -27,13 +27,13 @@ internal fun generateBindingContext(
val messageCollector = DetektMessageCollector(
minSeverity = CompilerMessageSeverity.ERROR,
debugPrinter = debugPrinter,
warningPrinter = warningPrinter,
warningPrinter = warningPrinter
)

val analyzer = AnalyzerWithCompilerReport(
messageCollector,
environment.configuration.languageVersionSettings,
false,
false
)
analyzer.analyzeAndReport(files) {
TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
Expand All @@ -54,7 +54,7 @@ internal fun generateBindingContext(
internal class DetektMessageCollector(
private val minSeverity: CompilerMessageSeverity,
private val debugPrinter: (() -> String) -> Unit,
private val warningPrinter: (String) -> Unit,
private val warningPrinter: (String) -> Unit
) : MessageCollector by MessageCollector.NONE {
private var messages = 0

Expand Down
Expand Up @@ -7,7 +7,7 @@ import io.gitlab.arturbosch.detekt.api.RuleSetId

internal class BaselineFilteredResult(
result: Detektion,
private val baseline: Baseline,
private val baseline: Baseline
) : Detektion by result {

override val findings: Map<RuleSetId, List<Finding>> = result.findings
Expand Down
Expand Up @@ -10,7 +10,7 @@ import java.nio.file.Path

internal data class DefaultBaseline(
override val manuallySuppressedIssues: FindingsIdList,
override val currentIssues: FindingsIdList,
override val currentIssues: FindingsIdList
) : Baseline {

override fun contains(id: FindingId): Boolean =
Expand Down
Expand Up @@ -15,7 +15,7 @@ internal abstract class AbstractYamlConfigValidator : ConfigValidator {
"Only supported config is the $yamlConfigClass. Actual type is $actualClass"
}
val settings = ValidationSettings(
config.subConfig("config").valueOrDefault("checkExhaustiveness", false),
config.subConfig("config").valueOrDefault("checkExhaustiveness", false)
)

return validate(config, settings)
Expand Down
Expand Up @@ -31,7 +31,7 @@ internal val DEFAULT_PROPERTY_EXCLUDES = setOf(
".*>.*>severity",
"build>weights.*",
".*>.*>ignoreAnnotated",
".*>.*>ignoreFunction",
".*>.*>ignoreFunction"
).joinToString(",")

internal fun checkConfiguration(settings: ProcessingSettings, baseline: Config) {
Expand Down
Expand Up @@ -10,7 +10,7 @@ import io.gitlab.arturbosch.detekt.core.rules.RuleSetLocator

internal class DefaultPropertiesConfigValidator(
private val settings: ProcessingSettings,
private val baseline: Config,
private val baseline: Config
) : ConfigValidator {

override fun validate(config: Config): Collection<Notification> {
Expand Down
Expand Up @@ -5,7 +5,7 @@ import io.gitlab.arturbosch.detekt.api.internal.SimpleNotification
import io.gitlab.arturbosch.detekt.core.config.YamlConfig

internal class DeprecatedPropertiesConfigValidator(
private val deprecatedProperties: Map<String, String>,
private val deprecatedProperties: Map<String, String>
) : AbstractYamlConfigValidator() {
override fun validate(
configToValidate: YamlConfig,
Expand Down Expand Up @@ -33,12 +33,12 @@ internal class DeprecatedPropertiesConfigValidator(

private fun createNotification(
propertyPath: List<String>,
deprecationDescription: String,
deprecationDescription: String
): Notification {
val prop = propertyPath.joinToString(">")
return SimpleNotification(
"Property '$prop' is deprecated. $deprecationDescription.",
Notification.Level.Warning,
Notification.Level.Warning
)
}
}
Expand Up @@ -7,7 +7,7 @@ import io.gitlab.arturbosch.detekt.core.config.YamlConfig
internal class InvalidPropertiesConfigValidator(
private val baseline: YamlConfig,
private val deprecatedProperties: Set<String>,
private val excludePatterns: Set<Regex>,
private val excludePatterns: Set<Regex>
) : AbstractYamlConfigValidator() {

override fun validate(
Expand Down Expand Up @@ -83,7 +83,7 @@ internal class InvalidPropertiesConfigValidator(
internal fun propertyShouldBeAnArray(prop: String): Notification =
SimpleNotification(
"Property '$prop' should be a YAML array instead of a comma-separated String.",
Notification.Level.Warning,
Notification.Level.Warning
)
}
}
Expand Up @@ -10,7 +10,7 @@ import java.util.ServiceLoader

internal class MissingRulesConfigValidator(
private val baseline: YamlConfig,
private val excludePatterns: Set<Regex>,
private val excludePatterns: Set<Regex>
) : AbstractYamlConfigValidator() {

override fun validate(
Expand All @@ -25,7 +25,7 @@ internal class MissingRulesConfigValidator(

private fun validateRuleSet(
ruleSet: String,
configToValidate: YamlConfig,
configToValidate: YamlConfig
): List<Notification> {
val ruleSetConfigToValidate = configToValidate.getSubMapOrNull(ruleSet)
val ruleSetConfigFromBaseline = baseline.getSubMapOrNull(ruleSet)
Expand All @@ -39,7 +39,7 @@ internal class MissingRulesConfigValidator(
private fun checkForMissingRules(
ruleSetName: String,
ruleSetConfigToValidate: Map<String, Any>,
ruleSetConfigFromBaseline: Map<String, Any>,
ruleSetConfigFromBaseline: Map<String, Any>
): List<Notification> {
if (ruleSetConfigToValidate[Config.ACTIVE_KEY] == false) {
return emptyList()
Expand All @@ -54,13 +54,13 @@ internal class MissingRulesConfigValidator(
private fun ruleMissing(ruleName: String, ruleSetName: String): Notification =
SimpleNotification(
"Rule '$ruleName' from the '$ruleSetName' rule set is missing in the configuration.",
Notification.Level.Warning,
Notification.Level.Warning
)

private fun ruleSetMissing(ruleSetName: String): Notification =
SimpleNotification(
"Rule set '$ruleSetName' is missing in the configuration.",
Notification.Level.Warning,
Notification.Level.Warning
)

@Suppress("UNCHECKED_CAST")
Expand Down
@@ -1,5 +1,5 @@
package io.gitlab.arturbosch.detekt.core.config.validation

internal data class ValidationSettings(
val checkExhaustiveness: Boolean = false,
val checkExhaustiveness: Boolean = false
)
Expand Up @@ -34,7 +34,7 @@ internal class EnvironmentFacade(
classpath,
compilerSpec.parseLanguageVersion(),
compilerSpec.parseJvmTarget(),
compilerSpec.jdkHome,
compilerSpec.jdkHome
)
createKotlinCoreEnvironment(compilerConfiguration, disposable)
}
Expand Down
Expand Up @@ -22,7 +22,7 @@ internal fun annotationSuppressorFactory(rule: ConfigAware, bindingContext: Bind
Suppressor { finding ->
val element = finding.entity.ktElement
element != null && element.isAnnotatedWith(
AnnotationExcluder(element.containingKtFile, annotations, bindingContext),
AnnotationExcluder(element.containingKtFile, annotations, bindingContext)
)
}
} else {
Expand Down
Expand Up @@ -36,14 +36,14 @@ internal fun functionSuppressorFactory(rule: ConfigAware, bindingContext: Bindin
private fun functionSuppressor(
element: KtElement,
bindingContext: BindingContext,
functionMatchers: List<FunctionMatcher>,
functionMatchers: List<FunctionMatcher>
): Boolean {
return element.isInFunctionNamed(bindingContext, functionMatchers)
}

private fun KtElement.isInFunctionNamed(
bindingContext: BindingContext,
functionMatchers: List<FunctionMatcher>,
functionMatchers: List<FunctionMatcher>
): Boolean {
return if (this is KtNamedFunction && functionMatchers.any { it.match(this, bindingContext) }) {
true
Expand Down
Expand Up @@ -16,7 +16,7 @@ fun interface Suppressor {
private fun buildSuppressors(rule: ConfigAware, bindingContext: BindingContext): List<Suppressor> {
return listOfNotNull(
annotationSuppressorFactory(rule, bindingContext),
functionSuppressorFactory(rule, bindingContext),
functionSuppressorFactory(rule, bindingContext)
)
}

Expand Down
Expand Up @@ -17,7 +17,7 @@ class PerformanceMonitor {
Binding,
LoadingExtensions,
Analyzer,
Reporting,
Reporting
}

data class Entry(val phase: Phase, val duration: Duration)
Expand Down