Skip to content

Commit

Permalink
Add new rules to config.yml automatically (#385)
Browse files Browse the repository at this point in the history
Enhances the rule creation script to automatically update the detekt configuration file when creating new rules.
  • Loading branch information
mrmans0n authored Nov 27, 2024
1 parent 2128757 commit 2e79be4
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions scripts/create-rule.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import org.apache.velocity.app.VelocityEngine
import org.apache.velocity.runtime.RuntimeConstants
import java.io.File
import java.io.StringWriter
import java.util.*
import java.util.Locale
import java.util.Properties
import kotlin.system.exitProcess

fun printUsage() {
Expand Down Expand Up @@ -77,8 +78,7 @@ val engine = VelocityEngine(
}
).apply { init() }

val context = VelocityContext()
context.apply {
val context = VelocityContext().apply {
put("ruleName", ruleName)
put("detektRuleName", "${newRule}Check")
put("ktlintRuleName", "${newRule}Check")
Expand Down Expand Up @@ -126,7 +126,14 @@ engine.writeTemplate(
targetName = "${ruleName}CheckTest",
context = context
)

println("Adding to detekt default ruleset...")
val detektConfig = rootDir.resolve("rules/detekt/src/main/resources/config/config.yml")
detektConfig.appendText("""
$ruleName:
active: true
"""
)
// Desirable improvements to add:
// - add to detekt's default ruleset yml rules/detekt/src/main/resources/config/config.yml
// - add rule to docs/detekt.md "default rule" values
// - add entry in docs/rules.md (likely at the end)

0 comments on commit 2e79be4

Please sign in to comment.