Checkstyle: Add checkstyle rule for %d in Preconditions.checkArgument#5057
Conversation
|
Looks like some violation in Spark 3.0? Also fyi , @kbendick |
dc65746 to
d5aceef
Compare
|
@szehon-ho I committed a fixup to the violation (missed it while running the checkstyle locally in the IDE for some reason) |
|
Sounds good, sorry i am pretty bad at regex, what do you mean:
The [^;]* can be removed? The purpose now is to not match %d in the Precondition.checkArgument()'s first argument (or is it for something else)? |
|
@szehon-ho I'll explain a little bit more: might be mistakenly matched. To avoid matching it, the |
d5aceef to
e1e1208
Compare
|
Updated the PR again, and now also tested the build locally to pass, sorry for that. |
|
@xrl1 thanks for the explanation for those points. How about the last point:
Do you think we should simplify this? I don't see much possibility of %d in the first argument of Precondition (which is evaluating a boolean), other than a modulo operation but in that case there is a space after %. Or let me know if I missed what you mean. |
Preconditions.checkArgument only works with %s, as %d does not parse and returns a bad error message Added a RegexpMultiline to find wrong usages.
e1e1208 to
2154578
Compare
|
@szehon-ho Yeah you are right, it is really unlikely to encounter Preconditions\.checkArgument\([^;]+%d[^;]+\); |
|
Great, thanks for spending time on this. Will merge once it passes |
Could you update the PR description with the explanation of this regex (so we don't have to look it up in the conversation) @xrl1? I believe the original regex is still there. |
|
@kbendick Yeah sure, updated. |
Closes #4618
From the issue:
Preconditions.checkArgumentonly works with %s, as %d does not parse and returns a bad error message.Created a multiline regex to prevent this.
The regex is as follows:
The logic behind it: Find the function call, then any characters (except
;) until%d, and finally search until the function closes and a ';'.[^;]*instead of.*, because this is a multiline search and the dotall regex param (enabled bymatchAcrossLinesconfig) is aggressive and this is the best way to break its search.Also, fixed %d usages that the Checkstyle rule found