Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#25810] YSQL: Lint whitespace for comments with non-word characters
Summary: `fn(/*example=*/false)` did not raise a lint error, but `fn(/*example*/false)` did. This is because the regex did not account for other characters inside the comment. Update the regex, avoid a few PG cases / files that don't follow this pattern, and make some small changes in YB-owned lines to conform to this rule. Jira: DB-15108 Test Plan: Tested on the following cases. ``` /* Good examples */ /*********/ /***** title *****/ /* ---------------------- TS Template commands -----------------------*/ /*-------------*/ /* example */ /* good example */ /*- translator: both %s are strings of the form "option = value" */ /*#define TRACE_VISIBILITYMAP */ /* Bad Examples */ /*=============*/ /* no whitespace after*/ /*no whitespace before */ /*no whitespace before or after*/ /* noWhiteSpaceAfter*/ /*noWhiteSpaceBefore */ /*noWhiteSpaceBeforeOrAfter*/ /* no whitespace after=*/ /*no whitespace before= */ /*no whitespace before or after=*/ /* noWhiteSpaceAfter=*/ /*noWhiteSpaceBefore= */ /*noWhiteSpaceBeforeOrAfter=*/ /* hello*/, myvar /*helloagain */ blah(/*example=*/false) blah(/*example*/false) /*a*/ /*ab*/ /*abc*/ ``` ```lang=sh, name=test-linter.sh arc patch D41598 git checkout HEAD~ find src/postgres -type f \( -name "*.c" -o -name "*.h" \) -print0 | xargs -0 arc lint > before.txt git checkout - find src/postgres -type f \( -name "*.c" -o -name "*.h" \) -print0 | xargs -0 arc lint > after.txt diff <(grep "comment_spacing" before.txt -A 7 -B 1) <(grep "comment_spacing" after.txt -A 7 -B 1) NUM_COMMENT_SPACING_ERRORS_BEFORE=$(grep "comment_spacing" before.txt | wc -l) NUM_COMMENT_SPACING_ERRORS_AFTER=$(grep "comment_spacing" after.txt | wc -l) if (( NUM_COMMENT_SPACING_ERRORS_BEFORE - 1 != NUM_COMMENT_SPACING_ERRORS_AFTER )); then echo "Expected one less comment_spacing error after D41598" echo "Before:" $NUM_COMMENT_SPACING_ERRORS_BEFORE echo "After:" $NUM_COMMENT_SPACING_ERRORS_AFTER exit 1 fi ``` `test-linter.sh` shows the difference: ``` < < Error (S&RX) bad_parameter_comment_spacing < Spacing should be like /* param */ < < 12309 # endif < 12310 #endif < 12311 #ifndef NOOP < >>> 12312 # define NOOP /*EMPTY*/(void)0# define NOOP /*EMPTY*/(void)0 < 12313 #endif ``` The difference shows just one line that used to be a lint problem, and is not any more. No bad comment spacing complaints: ```lang=sh grep "comment_spacing" after.txt -A 7 -B 1 ``` Reviewers: jason Reviewed By: jason Subscribers: jason, yql Differential Revision: https://phorge.dev.yugabyte.com/D41598
- Loading branch information