diff --git a/zpa-checks/src/main/kotlin/org/sonar/plsqlopen/checks/ToDateWithoutFormatCheck.kt b/zpa-checks/src/main/kotlin/org/sonar/plsqlopen/checks/ToDateWithoutFormatCheck.kt index 8b042f9a..0106525a 100644 --- a/zpa-checks/src/main/kotlin/org/sonar/plsqlopen/checks/ToDateWithoutFormatCheck.kt +++ b/zpa-checks/src/main/kotlin/org/sonar/plsqlopen/checks/ToDateWithoutFormatCheck.kt @@ -20,7 +20,7 @@ package org.sonar.plsqlopen.checks import com.felipebz.flr.api.AstNode -import org.sonar.plugins.plsqlopen.api.PlSqlPunctuator +import org.sonar.plugins.plsqlopen.api.PlSqlGrammar import org.sonar.plugins.plsqlopen.api.SingleRowSqlFunctionsGrammar import org.sonar.plugins.plsqlopen.api.annotations.* @@ -35,8 +35,8 @@ class ToDateWithoutFormatCheck : AbstractBaseCheck() { } override fun visitNode(node: AstNode) { - val firstArgument = node.getFirstChild(PlSqlPunctuator.LPARENTHESIS).nextSibling - if (!node.hasDirectChildren(PlSqlPunctuator.COMMA) && !CheckUtils.isNullLiteralOrEmptyString(firstArgument)) { + val arguments = node.getChildren(PlSqlGrammar.ARGUMENT) + if (arguments.size == 1 && !CheckUtils.isNullLiteralOrEmptyString(arguments.first().lastChild)) { addIssue(node, getLocalizedMessage()) } } diff --git a/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/SingleRowSqlFunctionsGrammar.kt b/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/SingleRowSqlFunctionsGrammar.kt index 4f1700c5..f1cf68ea 100644 --- a/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/SingleRowSqlFunctionsGrammar.kt +++ b/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/SingleRowSqlFunctionsGrammar.kt @@ -238,69 +238,69 @@ enum class SingleRowSqlFunctionsGrammar : GrammarRuleKey { b.rule(TO_BINARY_DOUBLE_EXPRESSION).define( TO_BINARY_DOUBLE, LPARENTHESIS, - EXPRESSION, + ARGUMENT, b.optional(DEFAULT_ON_ERROR_CLAUSE), - b.optional(COMMA, EXPRESSION, b.optional(COMMA, EXPRESSION)), + b.optional(COMMA, ARGUMENT, b.optional(COMMA, ARGUMENT)), RPARENTHESIS ) b.rule(TO_BINARY_FLOAT_EXPRESSION).define( TO_BINARY_FLOAT, LPARENTHESIS, - EXPRESSION, + ARGUMENT, b.optional(DEFAULT_ON_ERROR_CLAUSE), - b.optional(COMMA, EXPRESSION, b.optional(COMMA, EXPRESSION)), + b.optional(COMMA, ARGUMENT, b.optional(COMMA, ARGUMENT)), RPARENTHESIS ) b.rule(TO_BOOLEAN_EXPRESSION).define( TO_BOOLEAN, LPARENTHESIS, - EXPRESSION, + ARGUMENT, b.optional(DEFAULT_ON_ERROR_CLAUSE), RPARENTHESIS ) b.rule(TO_DATE_EXPRESSION).define( TO_DATE, LPARENTHESIS, - EXPRESSION, + ARGUMENT, b.optional(DEFAULT_ON_ERROR_CLAUSE), - b.optional(COMMA, EXPRESSION, b.optional(COMMA, EXPRESSION)), + b.optional(COMMA, ARGUMENT, b.optional(COMMA, ARGUMENT)), RPARENTHESIS ) b.rule(TO_DSINTERVAL_EXPRESSION).define( TO_DSINTERVAL, LPARENTHESIS, - EXPRESSION, + ARGUMENT, b.optional(DEFAULT_ON_ERROR_CLAUSE), RPARENTHESIS ) b.rule(TO_NUMBER_EXPRESSION).define( TO_NUMBER, LPARENTHESIS, - EXPRESSION, + ARGUMENT, b.optional(DEFAULT_ON_ERROR_CLAUSE), - b.optional(COMMA, EXPRESSION, b.optional(COMMA, EXPRESSION)), + b.optional(COMMA, ARGUMENT, b.optional(COMMA, ARGUMENT)), RPARENTHESIS ) b.rule(TO_TIMESTAMP_EXPRESSION).define( TO_TIMESTAMP, LPARENTHESIS, - EXPRESSION, + ARGUMENT, b.optional(DEFAULT_ON_ERROR_CLAUSE), - b.optional(COMMA, EXPRESSION, b.optional(COMMA, EXPRESSION)), + b.optional(COMMA, ARGUMENT, b.optional(COMMA, ARGUMENT)), RPARENTHESIS ) b.rule(TO_TIMESTAMP_TZ_EXPRESSION).define( TO_TIMESTAMP_TZ, LPARENTHESIS, - EXPRESSION, + ARGUMENT, b.optional(DEFAULT_ON_ERROR_CLAUSE), - b.optional(COMMA, EXPRESSION, b.optional(COMMA, EXPRESSION)), + b.optional(COMMA, ARGUMENT, b.optional(COMMA, ARGUMENT)), RPARENTHESIS ) b.rule(TO_YMINTERVAL_EXPRESSION).define( TO_YMINTERVAL, LPARENTHESIS, - EXPRESSION, + ARGUMENT, b.optional(DEFAULT_ON_ERROR_CLAUSE), RPARENTHESIS )