Skip to content

Commit

Permalink
Create detekt-authors module
Browse files Browse the repository at this point in the history
  • Loading branch information
BraisGabin committed Jul 25, 2022
1 parent e4a2bf5 commit 7da777b
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 3 deletions.
3 changes: 2 additions & 1 deletion build-logic/src/main/kotlin/releasing.gradle.kts
Expand Up @@ -38,7 +38,8 @@ 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-authors").buildDir.resolve("libs/detekt-authors-${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-authors"))
}

tasks.withType<Detekt>().configureEach {
Expand Down
9 changes: 9 additions & 0 deletions detekt-authors/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 authors ruleset provides rules that ensures good practices when writing detekt rules
*/
@ActiveByDefault("1.22.0")
class AuthorsProvider : RuleSetProvider {

override val ruleSetId: String = "detekt"

@Suppress("UseEmptyCounterpart")
override fun instance(config: Config) = RuleSet(ruleSetId, listOf())
}
@@ -0,0 +1 @@
io.gitlab.arturbosch.detekt.authors.AuthorsProvider
2 changes: 2 additions & 0 deletions detekt-authors/src/main/resources/config/config.yml
@@ -0,0 +1,2 @@
detekt:
active: true
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 authorsConfigFile = "${rootProject.rootDir}/detekt-authors/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-authors/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(authorsConfigFile),
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-authors/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 == "detekt" })
}
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-authors/src/main/resources/config"), "config") {
yaml {
printRuleSetPage(pages.first { it.ruleSet.name == "detekt" })
}
}
}

private fun markdownHeader(ruleSet: String): String {
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Expand Up @@ -9,6 +9,7 @@ pluginManagement {

include("code-coverage-report")
include("detekt-api")
include("detekt-authors")
include("detekt-cli")
include("detekt-core")
include("detekt-formatting")
Expand Down

0 comments on commit 7da777b

Please sign in to comment.