aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Cole <40234707+DavidArthurCole@users.noreply.github.com>2024-09-19 13:51:56 -0400
committerDavid Cole <40234707+DavidArthurCole@users.noreply.github.com>2024-09-19 13:51:56 -0400
commit6c56b6da4b8f57aa49e9df7bd949f599486e122d (patch)
tree6fe5c0eac4649e4dea8ea7a2d1cbd4fab2d182ac /src
parent17f900c1d54ba6007de7e6cf4f62ded5ce0655e3 (diff)
downloadskyhanni-6c56b6da4b8f57aa49e9df7bd949f599486e122d.tar.gz
skyhanni-6c56b6da4b8f57aa49e9df7bd949f599486e122d.tar.bz2
skyhanni-6c56b6da4b8f57aa49e9df7bd949f599486e122d.zip
Init setup
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/detektrules/grammar/AvoidColour.kt38
-rw-r--r--src/main/java/at/hannibal2/skyhanni/detektrules/grammar/GrammarRuleSetProvider.kt15
-rw-r--r--src/main/resources/META-INF/services/io.gitlab.arturbosch.detekt.api.RuleSetProvider1
3 files changed, 54 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/detektrules/grammar/AvoidColour.kt b/src/main/java/at/hannibal2/skyhanni/detektrules/grammar/AvoidColour.kt
new file mode 100644
index 000000000..4b7fd2276
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/detektrules/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
+ if (text.contains("colour")) {
+ report(
+ CodeSmell(
+ issue,
+ Entity.from(expression),
+ "Avoid using the word 'colour' in code, prefer 'color' instead."
+ )
+ )
+ }
+ super.visitStringTemplateExpression(expression)
+ }
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/detektrules/grammar/GrammarRuleSetProvider.kt b/src/main/java/at/hannibal2/skyhanni/detektrules/grammar/GrammarRuleSetProvider.kt
new file mode 100644
index 000000000..963ce582b
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/detektrules/grammar/GrammarRuleSetProvider.kt
@@ -0,0 +1,15 @@
+package at.hannibal2.skyhanni.detektrules.grammar
+
+import io.gitlab.arturbosch.detekt.api.Config
+import io.gitlab.arturbosch.detekt.api.RuleSet
+import io.gitlab.arturbosch.detekt.api.RuleSetProvider
+
+class GrammarRuleSetProvider : RuleSetProvider {
+ override val ruleSetId: String = "grammar-rules"
+
+ override fun instance(config: Config): RuleSet {
+ return RuleSet(ruleSetId, listOf(
+ AvoidColour(config)
+ ))
+ }
+}
diff --git a/src/main/resources/META-INF/services/io.gitlab.arturbosch.detekt.api.RuleSetProvider b/src/main/resources/META-INF/services/io.gitlab.arturbosch.detekt.api.RuleSetProvider
new file mode 100644
index 000000000..74e85a359
--- /dev/null
+++ b/src/main/resources/META-INF/services/io.gitlab.arturbosch.detekt.api.RuleSetProvider
@@ -0,0 +1 @@
+at.hannibal2.skyhanni.detektrules.grammar.GrammarRuleSetProvider