Skip to content

Commit

Permalink
refactor: extract APIs for rules
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Jan 8, 2024
1 parent 940a7de commit 223ac40
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,26 @@ import cc.unitmesh.quality.extension.JavaServiceAnalyser
import cc.unitmesh.quality.extension.JavaRepositoryAnalyser
import cc.unitmesh.quality.extension.JavaControllerAnalyser
import cc.unitmesh.quality.testbadsmell.TestBadsmellAnalyser
import chapi.domain.core.CodeContainer

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

interface QualityAnalyser {

/**
* For [CodeQualityType.DocComment], we need to analysis the whole container which contains comments.
*/
fun analysis(container: CodeContainer): List<Issue> {
return listOf()
}

/**
* Normal analysis, like [CodeQualityType.BadSmell], [CodeQualityType.TestBadSmell], etc.
* Normal analysis, we only need to analysis the given nodes.
*
* - [CodeQualityType.BadSmell], [CodeQualityType.TestBadSmell]
* - [CodeQualityType.JavaController], [CodeQualityType.JavaRepository], [CodeQualityType.JavaService]
*
*/
fun analysis(nodes: List<CodeDataStruct>): List<Issue>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package cc.unitmesh.quality.comment

import cc.unitmesh.quality.QualityAnalyser
import chapi.domain.core.CodeContainer
import chapi.domain.core.CodeDataStruct
import org.archguard.rule.core.Issue

class CommentAnalyser(comments: List<CodeComment>, thresholds: Map<String, Int>) : QualityAnalyser {
override fun analysis(nodes: List<CodeDataStruct>): List<Issue> {
class CommentAnalyser(thresholds: Map<String, Int>) : QualityAnalyser {
override fun analysis(nodes: List<CodeDataStruct>): List<Issue> = listOf()

override fun analysis(container: CodeContainer): List<Issue> {
return listOf()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cc.unitmesh.quality.comment

import cc.unitmesh.quality.comment.rule.CommentRule
import chapi.domain.core.CodeContainer
import org.archguard.rule.core.Issue
import org.archguard.rule.core.RuleContext
import org.archguard.rule.core.RuleSet
import org.archguard.rule.core.RuleVisitor

class CommentRuleVisitor(val comments: List<CodeComment>, container: CodeContainer) : RuleVisitor(comments) {
override fun visitor(ruleSets: Iterable<RuleSet>): List<Issue> {
val results: MutableList<Issue> = mutableListOf()
val context = RuleContext()

ruleSets.forEach { ruleSet ->
ruleSet.rules.forEach { rule ->
val apiRule = rule as CommentRule
// resources.map {
// apiRule.visitResource(it, context, fun(rule: Rule, position: IssuePosition) {
// results += Issue(
// position,
// ruleId = rule.key,
// name = rule.name,
// detail = rule.description,
// ruleType = RuleType.HTTP_API_SMELL,
// fullName = "${it.packageName}:${it.className}:${it.methodName}",
// source = "${it.sourceHttpMethod} ${it.sourceUrl}"
// )
// })
// }
}
}

return results
}
}

0 comments on commit 223ac40

Please sign in to comment.