Skip to content

Conversation

HasithDeAlwis
Copy link
Contributor

@HasithDeAlwis HasithDeAlwis commented Sep 10, 2025

Closes #27319

Summary

Add lint checks for Form/FormData pairs and handle type transformations

Enhancements:

  • Validate that each Form_* type in yb_typedefs.list has a corresponding FormData_* entry and vice versa
  • Ensure YB_DEFINE_HANDLE_TYPE macros correspond to Ybc-prefixed types in yb_typedefs.list

@HasithDeAlwis HasithDeAlwis changed the title Add linter check for form yb defs [YSQL] add lint rule for yb_typedefs.list Form_* and YB_DEFINE_HANDLE_TYPE Sep 10, 2025
Copy link

netlify bot commented Sep 10, 2025

Deploy Preview for infallible-bardeen-164bc9 ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 08d9c42
🔍 Latest deploy log https://app.netlify.com/projects/infallible-bardeen-164bc9/deploys/68c1f9443a7f170008f71187
😎 Deploy Preview https://deploy-preview-28549--infallible-bardeen-164bc9.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

fi
done

find src -name '*.h' -exec grep -l 'YB_DEFINE_HANDLE_TYPE' {} \; 2>/dev/null | \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check adds a lot of time (around 4 seconds on my Mac). Are we ok with this?

YB_DEFINE_HANDLE_TYPE is only used in src/yb/yql/pggate/ybc_pg_typedefs.h, so it feels almost odd to check the entire src/ directory.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please only check src/yb/yql/pggate: grep -rl YB_DEFINE_HANDLE_TYPE src/yb/yql/pggate

Copy link
Contributor

@jasonyb jasonyb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arc lint src/postgres/src/tools/pgindent/yb_typedefs.list to test

fi
done

find src -name '*.h' -exec grep -l 'YB_DEFINE_HANDLE_TYPE' {} \; 2>/dev/null | \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please only check src/yb/yql/pggate: grep -rl YB_DEFINE_HANDLE_TYPE src/yb/yql/pggate

grep -o 'Form_[a-zA-Z0-9_]*' "$1" | while read -r form; do
formdata="FormData_${form#Form_}"
if ! grep -q "^$formdata$" "$1"; then
echo "error:missing_FormData:$formdata is missing for $form"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo "error:missing_FormData:$formdata is missing for $form"
echo "error:missing_formdata:$formdata is missing for $form"

grep -o 'FormData_[a-zA-Z0-9_]*' "$1" | while read -r formdata; do
form="Form_${formdata#FormData_}"
if ! grep -q "^$form$" "$1"; then
echo "error:missing_Form:$form is missing for $formdata"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo "error:missing_Form:$form is missing for $formdata"
echo "error:missing_form:$form is missing for $formdata"

sed 's/YB_DEFINE_HANDLE_TYPE(//' | sed 's/)//' | sort -u | while read -r handle_type; do
transformed_type="Ybc${handle_type}"
if ! grep -q "^$transformed_type$" "$1"; then
echo "error:missing_handle_type:$transformed_type is missing for YB_DEFINE_HANDLE_TYPE($handle_type)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long

grep -o 'Form_[a-zA-Z0-9_]*' "$1" | while read -r form; do
formdata="FormData_${form#Form_}"
if ! grep -q "^$formdata$" "$1"; then
echo "error:missing_FormData:$formdata is missing for $form"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff --git i/src/postgres/src/tools/pgindent/yb_typedefs.list w/src/postgres/src/tools/pgindent/yb_typedefs.list
index 53ecb19f4b..86c2d322f1 100644
--- i/src/postgres/src/tools/pgindent/yb_typedefs.list
+++ w/src/postgres/src/tools/pgindent/yb_typedefs.list
@@ -1,6 +1,5 @@
 FormData_pg_yb_migration
 FormData_pg_yb_profile
-FormData_pg_yb_role_profile
 FormData_pg_yb_tablegroup
 FormData_yb_pg_catalog_version
 FormData_yb_pg_invalidation_messages

does not cause lint failure. you are missing filename and line number from the message

@@ -25,6 +25,29 @@ if [[ "$1" == */yb_typedefs.list ]]; then
grep -Env "$pattern" "$1" \
| sed 's/^/error:missing_yb_in_type_name:'\
'Types in yb_typedefs.list should have "yb":/'

grep -o 'Form_[a-zA-Z0-9_]*' "$1" | while read -r form; do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
grep -o 'Form_[a-zA-Z0-9_]*' "$1" | while read -r form; do
grep -o '^Form_[a-zA-Z0-9_]*' "$1" | while read -r form; do

fi
done

grep -o 'FormData_[a-zA-Z0-9_]*' "$1" | while read -r formdata; do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
grep -o 'FormData_[a-zA-Z0-9_]*' "$1" | while read -r formdata; do
grep -o '^FormData_[a-zA-Z0-9_]*' "$1" | while read -r formdata; do

grep -o 'FormData_[a-zA-Z0-9_]*' "$1" | while read -r formdata; do
form="Form_${formdata#FormData_}"
if ! grep -q "^$form$" "$1"; then
echo "error:missing_Form:$form is missing for $formdata"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff --git i/src/postgres/src/tools/pgindent/yb_typedefs.list w/src/postgres/src/tools/pgindent/yb_typedefs.list
index 53ecb19f4b..f16a49fe48 100644
--- i/src/postgres/src/tools/pgindent/yb_typedefs.list
+++ w/src/postgres/src/tools/pgindent/yb_typedefs.list
@@ -9,7 +9,6 @@ Form_pg_yb_migration
 Form_pg_yb_profile
 Form_pg_yb_role_profile
 Form_pg_yb_tablegroup
-Form_yb_pg_catalog_version
 Form_yb_pg_invalidation_messages
 Form_yb_pg_logical_client_version
 YBExecuteMessageFunctorContext

does not cause lint failure for same reason

sed 's/YB_DEFINE_HANDLE_TYPE(//' | sed 's/)//' | sort -u | while read -r handle_type; do
transformed_type="Ybc${handle_type}"
if ! grep -q "^$transformed_type$" "$1"; then
echo "error:missing_handle_type:$transformed_type is missing for YB_DEFINE_HANDLE_TYPE($handle_type)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff --git i/src/postgres/src/tools/pgindent/yb_typedefs.list w/src/postgres/src/tools/pgindent/yb_typedefs.list
index 53ecb19f4b..c655a151ab 100644
--- i/src/postgres/src/tools/pgindent/yb_typedefs.list
+++ w/src/postgres/src/tools/pgindent/yb_typedefs.list
@@ -267,7 +267,6 @@ YbcPgSession
 YbcPgSessionState
 YbcPgSessionTxnInfo
 YbcPgSplitDatum
-YbcPgStatement
 YbcPgSysColumns
 YbcPgSysTablePrefetcherCacheMode
 YbcPgTableDesc

does not cause lint failure for same reason

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[YSQL] add lint rule for yb_typedefs.list Form_*
2 participants