mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-02 16:49:12 +00:00
Add library containing detekt rules for apollo plugins
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
apply plugin: 'java-library'
|
||||
apply plugin: 'org.jetbrains.kotlin.jvm'
|
||||
apply from: "$rootDir/gradle/kotlin.gradle"
|
||||
|
||||
dependencies {
|
||||
api group: 'io.gitlab.arturbosch.detekt', name: 'detekt-api', version: detektVersion
|
||||
|
||||
test.useJUnitPlatform()
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}")
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-params:${junitJupiterVersion}")
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}")
|
||||
testImplementation("org.junit.platform:junit-platform-launcher:${junitPlatformVersion}")
|
||||
|
||||
testImplementation group: 'io.gitlab.arturbosch.detekt', name: 'detekt-test', version: detektVersion
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package org.apollo.game.plugin.detekt
|
||||
|
||||
import io.gitlab.arturbosch.detekt.api.Config
|
||||
import io.gitlab.arturbosch.detekt.api.RuleSet
|
||||
import io.gitlab.arturbosch.detekt.api.RuleSetProvider
|
||||
import org.apollo.game.plugin.detekt.rules.DeclarationInScriptRule
|
||||
|
||||
class ApolloPluginRuleSetProvider : RuleSetProvider {
|
||||
override val ruleSetId = "apollo-plugin"
|
||||
|
||||
override fun instance(config: Config): RuleSet {
|
||||
return RuleSet(ruleSetId, listOf(
|
||||
DeclarationInScriptRule()
|
||||
))
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package org.apollo.game.plugin.detekt.rules
|
||||
|
||||
import io.gitlab.arturbosch.detekt.api.*
|
||||
import org.jetbrains.kotlin.psi.KtClass
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtObjectDeclaration
|
||||
|
||||
class DeclarationInScriptRule : Rule() {
|
||||
override val issue = Issue(
|
||||
"DeclarationInScript",
|
||||
Severity.CodeSmell,
|
||||
"This rule reports a plugin file containing class or object declarations.",
|
||||
Debt.FIVE_MINS
|
||||
)
|
||||
|
||||
override fun visit(root: KtFile) {
|
||||
super.visit(root)
|
||||
|
||||
val script = root.script ?: return
|
||||
val declarations = script.declarations.filter { it is KtClass || it is KtObjectDeclaration }
|
||||
|
||||
declarations
|
||||
.forEach {
|
||||
report(CodeSmell(
|
||||
issue,
|
||||
Entity.from(it),
|
||||
message = "Declaration of ${it.name} should live in a top-level file, not a script"
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
org.apollo.game.plugin.detekt.ApolloPluginRuleSetProvider
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package org.apollo.game.plugin.detekt.rules
|
||||
|
||||
import io.gitlab.arturbosch.detekt.test.lint
|
||||
import java.nio.file.Paths
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
internal class DeclarationInScriptRuleTest {
|
||||
val rule = DeclarationInScriptRule()
|
||||
|
||||
@Test
|
||||
fun `Finds warning in script file`() {
|
||||
val srcPath = Paths.get(this.javaClass.getResource("/testData/example.kts").toURI())
|
||||
val findings = rule.lint(srcPath)
|
||||
|
||||
assertEquals(1, findings.size)
|
||||
assertEquals("Declaration of ExampleDeclaration should live in a top-level file, not a script", findings[0].message)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
class ExampleDeclaration {
|
||||
|
||||
}
|
||||
@@ -15,6 +15,7 @@ detekt {
|
||||
|
||||
dependencies {
|
||||
detekt group: 'io.gitlab.arturbosch.detekt', name: 'detekt-formatting', version: detektVersion
|
||||
detekt project(':game:plugin-detekt-rules')
|
||||
}
|
||||
|
||||
sonarqube {
|
||||
|
||||
@@ -473,3 +473,7 @@ style:
|
||||
WildcardImport:
|
||||
active: false
|
||||
excludeImports: 'java.util.*,kotlinx.android.synthetic.*'
|
||||
|
||||
apollo-plugin:
|
||||
DeclarationInScript:
|
||||
active: true
|
||||
@@ -5,6 +5,7 @@ rootProject.name = 'org.apollo'
|
||||
include ':cache'
|
||||
include ':game'
|
||||
include ':game:plugin'
|
||||
include ':game:plugin-detekt-rules'
|
||||
include ':game:plugin-testing'
|
||||
include ':net'
|
||||
include ':util'
|
||||
|
||||
Reference in New Issue
Block a user