Skip to content

Commit

Permalink
fix(devins-linting): improve detection of duplicate agent IDs in DevI…
Browse files Browse the repository at this point in the history
…nsDuplicateAgentInspection #101

The DevInsDuplicateAgentInspection now uses a set of `DevInUsed` objects instead of strings to more accurately detect and report duplicate agent IDs. This change ensures that the inspection correctly identifies and flags only unique agent IDs within the context of their usage, improving the precision and reliability of the linting process.
  • Loading branch information
phodal committed Mar 20, 2024
1 parent e3b7960 commit df2bb82
Showing 1 changed file with 9 additions and 10 deletions.
Expand Up @@ -17,18 +17,17 @@ class DevInsDuplicateAgentInspection : LocalInspectionTool() {
}

private class DevInsDuplicateAgentVisitor(val holder: ProblemsHolder) : DevInVisitor() {
private var agentIds: MutableSet<String> = mutableSetOf()
private var agentIds: MutableSet<DevInUsed> = mutableSetOf()

override fun visitUsed(o: DevInUsed) {
o.firstChild.let { next ->
if (next.nextSibling.elementType == DevInTypes.AGENT_ID) {
if (agentIds.contains(next.text)) {
holder.registerProblem(
o,
DevInBundle.message("inspection.duplicate.agent")
)
} else {
agentIds.add(next.text)
if (o.firstChild.nextSibling.elementType == DevInTypes.AGENT_ID) {
agentIds.add(o)

if (agentIds.contains(o)) {
agentIds.forEachIndexed { index, it ->
if (index > 0) {
holder.registerProblem(it, DevInBundle.message("inspection.duplicate.agent"))
}
}
}
}
Expand Down

0 comments on commit df2bb82

Please sign in to comment.