Skip to content

Commit

Permalink
fix(grammar): Use ARGUMENT instead of EXPRESSION in conversion functi…
Browse files Browse the repository at this point in the history
…ons because in a PL/SQL context they can be called with named arguments like `var := to_number(right => val);`
  • Loading branch information
felipebz committed Sep 28, 2024
1 parent c753425 commit 2c1ca33
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*

Expand All @@ -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())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down

0 comments on commit 2c1ca33

Please sign in to comment.