Skip to content

Commit cc52630

Browse files
committed
Fixed check for List type test data
1 parent 5b5f561 commit cc52630

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/main/kotlin/org/domaframework/doma/intellij/inspection/sql/visitor/SqlTestDataAfterBlockCommentVisitor.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import com.intellij.psi.PsiComment
2020
import com.intellij.psi.PsiElement
2121
import com.intellij.psi.PsiFile
2222
import com.intellij.psi.PsiLiteralExpression
23-
import com.intellij.psi.PsiWhiteSpace
2423
import com.intellij.psi.util.PsiTreeUtil
2524
import com.intellij.psi.util.nextLeafs
2625
import org.domaframework.doma.intellij.common.isInjectionSqlFile
@@ -102,13 +101,16 @@ class SqlTestDataAfterBlockCommentVisitor(
102101
* These values can be separated by commas, and the entire list must be enclosed in parentheses.
103102
*/
104103
private fun isMatchListTestData(element: PsiElement): Boolean {
104+
// Ensure the list starts with an opening parenthesis, as this is required
105+
// for the structure to match the expected "list type test data" pattern.
106+
if (element.nextSibling?.elementType != SqlTypes.LEFT_PAREN) return false
105107
val parenthesesListPattern =
106108
Regex(
107109
"""^\(\s*(?:(?:"[^"]*"|'[^']*'|\d+|true|false|null)\s*(?:,\s*(?:"[^"]*"|'[^']*'|\d+|true|false|null)\s*)*)?\)$""",
108110
)
109111
val testDataText =
110112
element.nextLeafs
111-
.takeWhile { it !is PsiWhiteSpace }
113+
.takeWhile { it.prevSibling is PsiElement && it.prevSibling?.elementType != SqlTypes.RIGHT_PAREN }
112114
.toList()
113115
.joinToString("") { it.text }
114116
return testDataText.matches(parenthesesListPattern)

src/test/testData/src/main/resources/META-INF/doma/example/dao/inspection/TestDataCheckDao/commentBlock.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ SELECT e.employee_id AS employeeId
99
/*%! This comment will be removed */
1010
WHERE e.employee_id = <error descr="Bind variables must be followed by test data">/*^ id */</error>
1111
AND e.age >= /*^ literalAge */99
12-
AND e.sub_id IN /* subIds */(1,2,3)
12+
AND e.sub_id IN /* subIds */(1, 2, 3)

0 commit comments

Comments
 (0)