aboutsummaryrefslogtreecommitdiff
path: root/detekt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-09-19 20:49:04 +0200
committerLinnea Gräf <nea@nea.moe>2024-09-19 20:49:04 +0200
commit3724cbcfd774bae43f6fc3ac3f561922fcb2a5fa (patch)
tree426e4ac1bb584924dc5fba6cf33ebbee795c525a /detekt
parent6c56b6da4b8f57aa49e9df7bd949f599486e122d (diff)
downloadskyhanni-3724cbcfd774bae43f6fc3ac3f561922fcb2a5fa.tar.gz
skyhanni-3724cbcfd774bae43f6fc3ac3f561922fcb2a5fa.tar.bz2
skyhanni-3724cbcfd774bae43f6fc3ac3f561922fcb2a5fa.zip
Fix up previous work on detekt
Diffstat (limited to 'detekt')
-rw-r--r--detekt/build.gradle.kts12
-rw-r--r--detekt/detekt.yml25
-rw-r--r--detekt/src/main/kotlin/grammar/AvoidColour.kt38
-rw-r--r--detekt/src/main/kotlin/grammar/GrammarRuleSetProvider.kt17
-rw-r--r--detekt/src/main/kotlin/root.kt1
5 files changed, 93 insertions, 0 deletions
diff --git a/detekt/build.gradle.kts b/detekt/build.gradle.kts
new file mode 100644
index 000000000..02c5c463a
--- /dev/null
+++ b/detekt/build.gradle.kts
@@ -0,0 +1,12 @@
+plugins {
+ kotlin("jvm")
+ id("com.google.devtools.ksp")
+}
+
+dependencies {
+ implementation("io.gitlab.arturbosch.detekt:detekt-api:1.23.7")
+ ksp(libs.autoservice.ksp)
+ implementation(libs.autoservice.annotations)
+ testImplementation("io.kotest:kotest-assertions-core:5.9.1")
+ testImplementation("io.gitlab.arturbosch.detekt:detekt-test:1.23.7")
+}
diff --git a/detekt/detekt.yml b/detekt/detekt.yml
new file mode 100644
index 000000000..31bf77bc3
--- /dev/null
+++ b/detekt/detekt.yml
@@ -0,0 +1,25 @@
+
+config:
+ validation: true
+
+GrammarRules:
+ AvoidColour:
+ active: true
+
+
+style:
+ MagicNumber: # I, Linnea Gräf, of sound mind and body, disagree with disabling this rule
+ active: false
+ UnusedParameter:
+ active: true
+ ignoreAnnotated:
+ - 'SubscribeEvent'
+ - 'HandleEvent'
+ ReturnCount:
+ active: true
+# max: 5
+ excludeGuardClauses: true
+ MaxLineLength:
+ active: true
+ maxLineLength: 140
+ excludeCommentStatements: true
diff --git a/detekt/src/main/kotlin/grammar/AvoidColour.kt b/detekt/src/main/kotlin/grammar/AvoidColour.kt
new file mode 100644
index 000000000..754148d36
--- /dev/null
+++ b/detekt/src/main/kotlin/grammar/AvoidColour.kt
@@ -0,0 +1,38 @@
+package at.hannibal2.skyhanni.detektrules.grammar
+
+import io.gitlab.arturbosch.detekt.api.CodeSmell
+import io.gitlab.arturbosch.detekt.api.Config
+import io.gitlab.arturbosch.detekt.api.Debt
+import io.gitlab.arturbosch.detekt.api.Entity
+import io.gitlab.arturbosch.detekt.api.Issue
+import io.gitlab.arturbosch.detekt.api.Rule
+import io.gitlab.arturbosch.detekt.api.Severity
+import org.jetbrains.kotlin.psi.KtStringTemplateExpression
+
+/**
+ * This rule reports all usages of the word "colour" in the codebase,
+ * preferring the 'American' spelling "color" - this will ignore any
+ * type annotations, i.e., `@ConfigEditorColour` will not be reported.
+ */
+class AvoidColour(config: Config) : Rule(config) {
+ override val issue = Issue(
+ "AvoidColour",
+ Severity.Style,
+ "Avoid using the word 'colour' in code, prefer 'color' instead.",
+ Debt.FIVE_MINS
+ )
+
+ override fun visitStringTemplateExpression(expression: KtStringTemplateExpression) {
+ val text = expression.text // Be aware .getText() returns the entire span of this template, including variable names contained within. This should be rare enough of a problem for us to not care about it.
+ if (text.contains("colour", ignoreCase = true)) {
+ report(
+ CodeSmell(
+ issue,
+ Entity.from(expression),
+ "Avoid using the word 'colour' in code, prefer 'color' instead."
+ )
+ )
+ }
+ super.visitStringTemplateExpression(expression)
+ }
+}
diff --git a/detekt/src/main/kotlin/grammar/GrammarRuleSetProvider.kt b/detekt/src/main/kotlin/grammar/GrammarRuleSetProvider.kt
new file mode 100644
index 000000000..957b20147
--- /dev/null
+++ b/detekt/src/main/kotlin/grammar/GrammarRuleSetProvider.kt
@@ -0,0 +1,17 @@
+package at.hannibal2.skyhanni.detektrules.grammar
+
+import com.google.auto.service.AutoService
+import io.gitlab.arturbosch.detekt.api.Config
+import io.gitlab.arturbosch.detekt.api.RuleSet
+import io.gitlab.arturbosch.detekt.api.RuleSetProvider
+
+@AutoService(RuleSetProvider::class)
+class GrammarRuleSetProvider : RuleSetProvider {
+ override val ruleSetId: String = "GrammarRules"
+
+ override fun instance(config: Config): RuleSet {
+ return RuleSet(ruleSetId, listOf(
+ AvoidColour(config)
+ ))
+ }
+}
diff --git a/detekt/src/main/kotlin/root.kt b/detekt/src/main/kotlin/root.kt
new file mode 100644
index 000000000..9b95a398f
--- /dev/null
+++ b/detekt/src/main/kotlin/root.kt
@@ -0,0 +1 @@
+package at.hannibal2.skyhanni.detektrules