aboutsummaryrefslogtreecommitdiff
path: root/detekt/src
diff options
context:
space:
mode:
authorCalMWolfs <94038482+CalMWolfs@users.noreply.github.com>2024-09-29 06:36:18 +1000
committerGitHub <noreply@github.com>2024-09-28 22:36:18 +0200
commitaa5b07a6a2686d7fc100ca8f1de9afcff2c67add (patch)
tree389a64a31e149124436d4ea006a4afc79c9a226c /detekt/src
parentf332c375c5865e4266b0e831c7b6b54ae5f701c4 (diff)
downloadskyhanni-aa5b07a6a2686d7fc100ca8f1de9afcff2c67add.tar.gz
skyhanni-aa5b07a6a2686d7fc100ca8f1de9afcff2c67add.tar.bz2
skyhanni-aa5b07a6a2686d7fc100ca8f1de9afcff2c67add.zip
Backend: Change the detekt rule to be more generalised (#2600)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'detekt/src')
-rw-r--r--detekt/src/main/kotlin/grammar/AvoidBritishSpelling.kt46
-rw-r--r--detekt/src/main/kotlin/grammar/AvoidColour.kt38
-rw-r--r--detekt/src/main/kotlin/grammar/GrammarRuleSetProvider.kt9
3 files changed, 52 insertions, 41 deletions
diff --git a/detekt/src/main/kotlin/grammar/AvoidBritishSpelling.kt b/detekt/src/main/kotlin/grammar/AvoidBritishSpelling.kt
new file mode 100644
index 000000000..6a4ea3d61
--- /dev/null
+++ b/detekt/src/main/kotlin/grammar/AvoidBritishSpelling.kt
@@ -0,0 +1,46 @@
+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 british spelling over the american spelling in the codebase,
+ * this will ignore any type annotations, i.e., `@ConfigEditorColour` will not be reported.
+ */
+class AvoidBritishSpelling(config: Config) : Rule(config) {
+ override val issue = Issue(
+ "AvoidBritishSpelling",
+ Severity.Style,
+ "Avoid using the word british spelling over american spelling.",
+ Debt.FIVE_MINS,
+ )
+
+ private val scannedWords = mapOf(
+ "colour" to "color",
+ "armour" to "armor",
+ )
+
+ 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.
+
+ for (word in scannedWords) {
+ if (text.contains(word.key, ignoreCase = true)) {
+ report(
+ CodeSmell(
+ issue,
+ Entity.from(expression),
+ "Avoid using the word '${word.key}' in code, '${word.value}' is preferred instead.",
+ ),
+ )
+ }
+ }
+ super.visitStringTemplateExpression(expression)
+ }
+}
diff --git a/detekt/src/main/kotlin/grammar/AvoidColour.kt b/detekt/src/main/kotlin/grammar/AvoidColour.kt
deleted file mode 100644
index 754148d36..000000000
--- a/detekt/src/main/kotlin/grammar/AvoidColour.kt
+++ /dev/null
@@ -1,38 +0,0 @@
-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
index 957b20147..8001fe42b 100644
--- a/detekt/src/main/kotlin/grammar/GrammarRuleSetProvider.kt
+++ b/detekt/src/main/kotlin/grammar/GrammarRuleSetProvider.kt
@@ -10,8 +10,11 @@ class GrammarRuleSetProvider : RuleSetProvider {
override val ruleSetId: String = "GrammarRules"
override fun instance(config: Config): RuleSet {
- return RuleSet(ruleSetId, listOf(
- AvoidColour(config)
- ))
+ return RuleSet(
+ ruleSetId,
+ listOf(
+ AvoidBritishSpelling(config),
+ ),
+ )
}
}