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

Create detekt-rules-ruleauthors module #5129

Merged
merged 1 commit into from Sep 6, 2022
Merged
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
4 changes: 3 additions & 1 deletion build-logic/src/main/kotlin/releasing.gradle.kts
Expand Up @@ -38,7 +38,9 @@ project.afterEvaluate {
files(
cliBuildDir.resolve("libs/detekt-cli-${project.version}-all.jar"),
cliBuildDir.resolve("distributions/detekt-cli-${project.version}.zip"),
project(":detekt-formatting").buildDir.resolve("libs/detekt-formatting-${project.version}.jar")
project(":detekt-formatting").buildDir.resolve("libs/detekt-formatting-${project.version}.jar"),
project(":detekt-rules-ruleauthors").buildDir
.resolve("libs/detekt-rules-ruleauthors-${project.version}.jar")
)
)
}
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Expand Up @@ -27,6 +27,7 @@ allprojects {
dependencies {
detekt(project(":detekt-cli"))
detektPlugins(project(":detekt-formatting"))
detektPlugins(project(":detekt-rules-ruleauthors"))
}

tasks.withType<Detekt>().configureEach {
Expand Down
10 changes: 9 additions & 1 deletion detekt-generator/build.gradle.kts
Expand Up @@ -22,6 +22,8 @@ val configDir = "${rootProject.rootDir}/detekt-core/src/main/resources"
val cliOptionsFile = "${rootProject.rootDir}/website/docs/gettingstarted/_cli-options.md"
val defaultConfigFile = "$configDir/default-detekt-config.yml"
val deprecationFile = "$configDir/deprecation.properties"
val formattingConfigFile = "${rootProject.rootDir}/detekt-formatting/src/main/resources/config/config.yml"
val ruleauthorsConfigFile = "${rootProject.rootDir}/detekt-rules-ruleauthors/src/main/resources/config/config.yml"

val ruleModules = rootProject.subprojects
.filter { "rules" in it.name }
Expand All @@ -36,13 +38,16 @@ val generateDocumentation by tasks.registering(JavaExec::class) {

inputs.files(
ruleModules.map { fileTree(it) },
fileTree("${rootProject.rootDir}/detekt-rules-ruleauthors/src/main/kotlin"),
fileTree("${rootProject.rootDir}/detekt-formatting/src/main/kotlin"),
file("${rootProject.rootDir}/detekt-generator/build/libs/detekt-generator-${Versions.DETEKT}-all.jar"),
)

outputs.files(
fileTree(documentationDir),
file(defaultConfigFile),
file(formattingConfigFile),
file(ruleauthorsConfigFile),
file(deprecationFile),
file(cliOptionsFile),
)
Expand All @@ -55,7 +60,10 @@ val generateDocumentation by tasks.registering(JavaExec::class) {
mainClass.set("io.gitlab.arturbosch.detekt.generator.Main")
args = listOf(
"--input",
ruleModules.plus("${rootProject.rootDir}/detekt-formatting/src/main/kotlin").joinToString(","),
ruleModules
.plus("${rootProject.rootDir}/detekt-rules-ruleauthors/src/main/kotlin")
.plus("${rootProject.rootDir}/detekt-formatting/src/main/kotlin")
.joinToString(","),
"--documentation",
documentationDir,
"--config",
Expand Down
Expand Up @@ -24,7 +24,7 @@ class DetektPrinter(private val arguments: GeneratorArgs) {
}
}
yamlWriter.write(arguments.configPath, "default-detekt-config") {
ConfigPrinter.print(pages.filterNot { it.ruleSet.name == "formatting" })
ConfigPrinter.print(pages.filterNot { it.ruleSet.name == "formatting" || it.ruleSet.name == "ruleauthors" })
}
propertiesWriter.write(arguments.configPath, "deprecation") {
// We intentionally not filter for "formatting" as we want to be able to deprecate
Expand All @@ -36,6 +36,11 @@ class DetektPrinter(private val arguments: GeneratorArgs) {
printRuleSetPage(pages.first { it.ruleSet.name == "formatting" })
}
}
yamlWriter.write(Paths.get("../detekt-rules-ruleauthors/src/main/resources/config"), "config") {
yaml {
printRuleSetPage(pages.first { it.ruleSet.name == "ruleauthors" })
}
}
}

private fun markdownHeader(ruleSet: String): String {
Expand Down
9 changes: 9 additions & 0 deletions detekt-rules-ruleauthors/build.gradle.kts
@@ -0,0 +1,9 @@
plugins {
id("module")
}

dependencies {
compileOnly(projects.detektApi)
testImplementation(projects.detektTest)
testImplementation(libs.assertj)
}
@@ -0,0 +1,18 @@
package io.gitlab.arturbosch.detekt.authors

import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.api.RuleSet
import io.gitlab.arturbosch.detekt.api.RuleSetProvider
import io.gitlab.arturbosch.detekt.api.internal.ActiveByDefault

/**
* The rule authors ruleset provides rules that ensures good practices when writing detekt rules
*/
@ActiveByDefault("1.22.0")
class RuleAuthorsProvider : RuleSetProvider {

override val ruleSetId: String = "ruleauthors"

@Suppress("UseEmptyCounterpart")
override fun instance(config: Config) = RuleSet(ruleSetId, listOf())
}
@@ -0,0 +1 @@
io.gitlab.arturbosch.detekt.authors.RuleAuthorsProvider
2 changes: 2 additions & 0 deletions detekt-rules-ruleauthors/src/main/resources/config/config.yml
@@ -0,0 +1,2 @@
ruleauthors:
active: true
1 change: 1 addition & 0 deletions settings.gradle.kts
Expand Up @@ -30,6 +30,7 @@ include("detekt-rules-errorprone")
include("detekt-rules-exceptions")
include("detekt-rules-naming")
include("detekt-rules-performance")
include("detekt-rules-ruleauthors")
include("detekt-rules-style")
include("detekt-sample-extensions")
include("detekt-test")
Expand Down