sonar-openedge
sonar-openedge copied to clipboard
TRIM with \ is likely to be a bug
Just tripped over this.
Trimming a path variable with \ will make the path invalid in Windows if it is a UNC path. Since TRIM with \ is most likely a path a rule to check this would be great. "Only RIGHT-TRIM or LEFT-TRIM should be used in combination with \"
Also "/" should likely be included for UNIX (But i am no sure about this, we only work with Windows)
Wrong:
TRIM(lcPath,"\":U).
Correct:
RIGHT-TRIM(lcPath,"\":U).
Can you escape the backslashes in your comment to make them visible please:
one \ = two \\ = \
Or simply add them to code sections (double back tick)
Incorrect:
trim( lcpath, "\":u ).
Correct:
right-trim( lcpath, "\":u ).
And as a comment on the rule - I would really really really wrap all file handling in one .p / .cls - so the reach of the rule should be limited.
I agree, all file handling schould be wrapped in a central class. But i guess we are not the only abl devs with 20+ years of legacy behind them so we have path manipulation all over the place.
But this rule would be nice to find code like this and switch to the apropriate methods.
In my opinion there is nothing wrong with trim("\")
except when you use it in the wrong place, so I do not think that Lint should warn against using trim("\")
in general, only about using it in the wrong place but that is too difficult to determine.
If what you really want is to search all sourcecode for occurences of trim("\")
to find where you can refactor to call methods in a filesystem class, then I think you should just use some editor that can search files with regexp. That is in my opinion not the purpose of Lint.
On th eother hand, I can imagine that there is already a filesystem class and you want to guard that newer sourcecode is not using that class.
In that case you may want Lint to look for patterns of filename or foldername manipulation. trim("\")
is one indication, but so is + "/" +
or if (substing(path,2,1)=":" then disk=substring(path,1,1)
or substring usage that split the extension from a filename. I would not like it if all these little fragments become a separate Lint rule.
I agree with Jurjen, In general trim(x, "\")
is valid code.
It could be a use case for a custom rule.
Unless you are absolutely sure you will never have to run any code on Linux, I would recommend using ~\ and ~/ instead of \ . There are some sonar rules for those.