aboutsummaryrefslogtreecommitdiff
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
parent17f900c1d54ba6007de7e6cf4f62ded5ce0655e3 (diff)
downloadskyhanni-6c56b6da4b8f57aa49e9df7bd949f599486e122d.tar.gz
skyhanni-6c56b6da4b8f57aa49e9df7bd949f599486e122d.tar.bz2
skyhanni-6c56b6da4b8f57aa49e9df7bd949f599486e122d.zip
Init setup
-rw-r--r--.github/workflows/detekt.yml14
-rw-r--r--build.gradle.kts36
-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
-rw-r--r--versions/1.8.9/detekt/baseline.yml0
-rw-r--r--versions/1.8.9/detekt/detekt.yml3
7 files changed, 106 insertions, 1 deletions
diff --git a/.github/workflows/detekt.yml b/.github/workflows/detekt.yml
new file mode 100644
index 000000000..da0d50daf
--- /dev/null
+++ b/.github/workflows/detekt.yml
@@ -0,0 +1,14 @@
+name: detekt
+on:
+ - pull_request
+jobs:
+ detekt:
+ name: Run detekt
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: "checkout"
+ uses: actions/checkout@v2
+
+ - name: "detekt"
+ uses: natiginfo/action-detekt-all@1.23.7
diff --git a/build.gradle.kts b/build.gradle.kts
index e8464ada2..0162dcf44 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -3,6 +3,8 @@ import at.skyhanni.sharedvariables.MultiVersionStage
import at.skyhanni.sharedvariables.ProjectTarget
import at.skyhanni.sharedvariables.SHVersionInfo
import at.skyhanni.sharedvariables.versionString
+import io.gitlab.arturbosch.detekt.Detekt
+import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask
import net.fabricmc.loom.task.RunGameTask
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
@@ -18,6 +20,7 @@ plugins {
kotlin("plugin.power-assert")
`maven-publish`
id("moe.nea.shot") version "1.0.0"
+ id("io.gitlab.arturbosch.detekt") version "1.23.7"
}
val target = ProjectTarget.values().find { it.projectPath == project.path }!!
@@ -177,10 +180,14 @@ dependencies {
exclude(module = "unspecified")
isTransitive = false
}
- testImplementation("org.junit.jupiter:junit-jupiter:5.10.0")
+ testImplementation("org.junit.jupiter:junit-jupiter:5.11.0")
testImplementation("io.mockk:mockk:1.12.5")
implementation("net.hypixel:mod-api:0.3.1")
+
+ compileOnly("io.gitlab.arturbosch.detekt:detekt-api:1.23.7")
+ testImplementation("io.kotest:kotest-assertions-core:5.9.1")
+ testImplementation("io.gitlab.arturbosch.detekt:detekt-test:1.23.7")
}
afterEvaluate {
@@ -343,3 +350,30 @@ publishing.publications {
}
}
}
+
+// Detekt:
+detekt {
+ buildUponDefaultConfig = true // preconfigure defaults
+ config.setFrom("$projectDir/detekt/detekt.yml") // point to your custom config defining rules to run, overwriting default behavior
+ baseline = file("$projectDir/detekt/baseline.xml") // a way of suppressing issues before introducing detekt
+ source.setFrom(
+ "$projectDir/src/main/kotlin",
+ "$projectDir/src/main/java"
+ )
+}
+
+tasks.withType<Detekt>().configureEach {
+ reports {
+ html.required.set(true) // observe findings in your browser with structure and code snippets
+ xml.required.set(true) // checkstyle like format mainly for integrations like Jenkins
+ sarif.required.set(true) // standardized SARIF format (https://sarifweb.azurewebsites.net/) to support integrations with GitHub Code Scanning
+ md.required.set(true) // simple Markdown format
+ }
+}
+
+tasks.withType<Detekt>().configureEach {
+ jvmTarget = "1.8"
+}
+tasks.withType<DetektCreateBaselineTask>().configureEach {
+ jvmTarget = "1.8"
+}
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
diff --git a/versions/1.8.9/detekt/baseline.yml b/versions/1.8.9/detekt/baseline.yml
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/versions/1.8.9/detekt/baseline.yml
diff --git a/versions/1.8.9/detekt/detekt.yml b/versions/1.8.9/detekt/detekt.yml
new file mode 100644
index 000000000..50f05d12a
--- /dev/null
+++ b/versions/1.8.9/detekt/detekt.yml
@@ -0,0 +1,3 @@
+grammar-rules:
+ AvoidColour:
+ active: true