sonar-openedge icon indicating copy to clipboard operation
sonar-openedge copied to clipboard

Invalid number of parameters in SUBSTITUTE statement doesnt report missing substitution parameters

Open movedoa opened this issue 1 year ago • 2 comments

V 2.24 The rule doesnt seem to check if all variables are actually used in the base-string.

DEFINE VARIABLE lcFoo AS CHARACTER NO-UNDO.
 
/* 2 parameter(s) expected by SUBSTITUTE function, but 3 provided */
lcFoo = SUBSTITUTE("&1 &2":U, "1":U, "2":U, "3":U).
       
/* No issue reported, even though &2 is missing */
lcFoo = SUBSTITUTE("&1 &3":U, "1":U, "2":U, "3":U).

movedoa avatar Jan 04 '24 09:01 movedoa

The very first versions of this rule (not sure if that was part of the public release) reported those issues, but it was a bit too noisy on various codebases. I can re-introduce the check if you see enough value.

gquerret avatar Jan 08 '24 16:01 gquerret

I think this is never intentional and often a bug or at least a code smell. I noticed it when a value in a log file was not what i expected but this could lead to bigger hard to find problems.

movedoa avatar Jan 09 '24 20:01 movedoa