Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Commit

Permalink
feat(rule): enable rules for visit
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Apr 16, 2022
1 parent 8cf0de3 commit cb722cd
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 27 deletions.
3 changes: 2 additions & 1 deletion rule_core/build.gradle.kts
@@ -1,8 +1,9 @@
plugins {
kotlin("jvm") version "1.6.10"
id("com.github.johnrengelman.shadow") version "7.0.0"
kotlin("plugin.serialization") version "1.6.10"
}

dependencies {
implementation("com.phodal.chapi:chapi-domain:1.5.6")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2")
}
6 changes: 4 additions & 2 deletions rule_core/src/main/kotlin/org/archguard/rule/core/Rule.kt
@@ -1,5 +1,7 @@
package org.archguard.rule.core

import chapi.domain.core.CodeDataStruct

enum class Severity {
// ERROR -> BLOCKER can be for continuous integration
HINT, WARN, INFO, BLOCKER
Expand Down Expand Up @@ -32,7 +34,7 @@ enum class RuleType {
ORGANIZATION,
}

open class Rule(
abstract class Rule(
var key: String = "",
// rule name for identify
var name: String = "",
Expand All @@ -51,7 +53,7 @@ open class Rule(
// custom for search
var tags: List<String> = listOf()
) {

open fun visit(rootNode: CodeDataStruct, callback: () -> Unit) {}
}

abstract class IfttRule : Rule() {
Expand Down
@@ -0,0 +1,5 @@
package org.archguard.rule.core

interface RuleVisitor {

}
13 changes: 12 additions & 1 deletion rule_core/src/main/kotlin/org/archguard/rule/impl/tbs/TbsRule.kt
@@ -1,7 +1,18 @@
package org.archguard.rule.impl.tbs

import chapi.domain.core.CodeDataStruct
import org.archguard.rule.core.Rule

open class TbsRule: Rule() {
// tbs context?
override fun visit(rootNode: CodeDataStruct, callback: () -> Unit) {
if(this.given.isNotEmpty()) {
processGivenCondition()
} else {
// todo: call by interface
}
}

private fun processGivenCondition() {

}
}
Expand Up @@ -4,6 +4,9 @@ import org.archguard.rule.core.RuleSet
import org.archguard.rule.core.RuleSetProvider
import org.archguard.rule.core.RuleType
import org.archguard.rule.impl.CasingRule
import org.archguard.rule.impl.tbs.rules.EmptyTestRule
import org.archguard.rule.impl.tbs.rules.NoIgnoreTestRule
import org.archguard.rule.impl.tbs.rules.SleepyTestRule

/*
* Low level provider
Expand All @@ -13,7 +16,10 @@ class TestSmellProvider: RuleSetProvider {
return RuleSet(
RuleType.CHANGE_SMELL,
"normal",
CasingRule()
CasingRule(),
EmptyTestRule(),
NoIgnoreTestRule(),
SleepyTestRule(),
)
}
}
@@ -0,0 +1,17 @@
package org.archguard.rule.impl.tbs

import chapi.domain.core.CodeDataStruct
import org.archguard.rule.core.RuleSet
import org.archguard.rule.core.RuleVisitor

class TestSmellVisitor: RuleVisitor {
internal fun visitor(ruleSets: Iterable<RuleSet>, rootNode: CodeDataStruct) {
ruleSets.forEach { ruleSet ->
ruleSet.rules.forEach {
it.visit(rootNode) {
return@visit
}
}
}
}
}
Expand Up @@ -8,8 +8,6 @@ class EmptyTestRule: TbsRule() {
this.key = this.javaClass.name
this.description = "Some casing description"
// rule for AstPath or ognl?
this.given = listOf(
"$.class.function.annotation == 'Ignore'"
)
this.given = listOf("$.class.function.calls <= 0")
}
}
Expand Up @@ -8,6 +8,6 @@ class NoIgnoreTestRule : TbsRule() {
this.key = this.javaClass.name
this.description = "Some casing description"
// rule for AstPath or ognl?
this.given = listOf("$.class.function.calls <= 0")
this.given = listOf("$.class.function.annotations contains 'Ignore'")
}
}

This file was deleted.

@@ -1,6 +1,5 @@
package org.archguard.rule.ruleset

import org.archguard.rule.core.RuleSet
import org.archguard.rule.core.RuleSetProvider

abstract class CustomRuleSetsLoader : RuleSetProvider {
Expand Down
@@ -0,0 +1,17 @@
package org.archguard.rule.impl.tbs

import chapi.domain.core.CodeDataStruct
import org.junit.jupiter.api.Test

internal class TestSmellVisitorProviderTest {
@Test
internal fun name() {
val provider = TestSmellProvider()
val visitor = TestSmellVisitor()

val ds = CodeDataStruct()

visitor
.visitor(listOf(provider.get()), ds)
}
}

0 comments on commit cb722cd

Please sign in to comment.