From 4a172d3df4d7fce03087285cb38e77e7845512e7 Mon Sep 17 00:00:00 2001 From: Jason Kim Date: Wed, 18 Dec 2024 11:59:23 -0800 Subject: [PATCH] [#25360] YSQL: add some comment lint rules Summary: Add some postgres lint rules related to comments: - bad_comment_style: C++ comment style uses //. Postgres comment style is BSD style /* */. - likely_bad_multiline_comment_start: multiline comments should have a lone /* and */ at the top and bottom. There are a few exceptions that are explained in code comments. This is a warning, not error, because upstream PG makes some mistakes. - likely_bad_multiline_comment_end: for multiline comments, the last */ should have asterisk aligned with the asterisk of the first /*. This is a warning, not error, because upstream PG makes some mistakes. Jira: DB-14577 Test Plan: Close: #25360 Jenkins: skip Reviewers: telgersma Reviewed By: telgersma Subscribers: telgersma, yql Differential Revision: https://phorge.dev.yugabyte.com/D40760 --- src/postgres/ybsimplelint.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/postgres/ybsimplelint.sh b/src/postgres/ybsimplelint.sh index c231303c528c..9c6b68a64a14 100755 --- a/src/postgres/ybsimplelint.sh +++ b/src/postgres/ybsimplelint.sh @@ -27,6 +27,35 @@ grep -nE '\s(if|else if|for|while)\(' "$1" \ | grep -vE 'while\((0|1)\)' \ | sed 's/^/error:bad_spacing_after_if_else_for_while:/' +# Comments +grep -nE '//\s' "$1" \ + | sed 's/^/error:bad_comment_style:/' +# /* this is a bad +# * multiline comment */ +# TupleTableSlot slot /* this is a good +# * inline comment */ +# /************** +# * this is fine +# */ +# /*------------- +# * this is fine +# */ +# /* TypeCategory() +# * this is fine +# */ +# /* box_same +# * this is fine +# */ +grep -nE '^\s*/\*[^/]*[^)*-/]$' "$1" \ + | grep -vE '/\* \w' \ + | sed 's/^/warning:likely_bad_multiline_comment_start:/' +# /* +# * this is a bad +# * multiline comment +# */ +grep -nE '(^|^\s* )\*/' "$1" \ + | sed 's/^/warning:likely_bad_multiline_comment_end:/' + # Pointers # # Second grep below is to exclude comments: