Skip to content

format: reject raw pointer type aliases#44062

Open
Retr0-XD wants to merge 2 commits intoenvoyproxy:mainfrom
Retr0-XD:fix/check-format-type-alias-rules
Open

format: reject raw pointer type aliases#44062
Retr0-XD wants to merge 2 commits intoenvoyproxy:mainfrom
Retr0-XD:fix/check-format-type-alias-rules

Conversation

@Retr0-XD
Copy link
Copy Markdown

Summary

Adds a check_format validation for a STYLE.md type-alias rule: regular raw pointers should not be type aliased.

Fixes #9840.

What changed

  • Added a code-format check in tools/code_format/check_format.py to flag lines like:
    • using BadPtr = int*;
  • The check skips function pointer aliases (for example using Fn = void(*)(int);).

Validation

  • Ran check_format on synthetic samples:
    • bad sample with raw pointer alias is flagged with: "Don't type alias raw pointers"
    • good sample with unique_ptr alias and function-pointer alias did not trigger the new rule
  • Note: local check_format invocation also reported clang-format permission issues in this environment, unrelated to this logic change.

Signed-off-by: Retr0-XD <sakthi.harish@edgeverve.com>
@Retr0-XD Retr0-XD had a problem deploying to external-contributors March 21, 2026 08:41 — with GitHub Actions Error
@repokitteh-read-only
Copy link
Copy Markdown

Hi @Retr0-XD, welcome and thank you for your contribution.

We will try to review your Pull Request as quickly as possible.

In the meantime, please take a look at the contribution guidelines if you have not done so already.

🐱

Caused by: #44062 was opened by Retr0-XD.

see: more, trace.

@Retr0-XD
Copy link
Copy Markdown
Author

Added a format validation check for raw pointer type aliases per STYLE.md. Would be great to get this reviewed.

@wbpcode
Copy link
Copy Markdown
Member

wbpcode commented Mar 25, 2026

Anyway if fine to me and will defer this to @phlax

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new check_format validation to enforce the STYLE.md rule that raw (non-function) pointer types should not be introduced via using aliases.

Changes:

  • Added a regex-based check in tools/code_format/check_format.py to flag using Alias = T*;-style aliases.
  • Exempts aliases that include ( to avoid flagging function-pointer aliases.

report_error("Don't use 'using testing::Test;, elaborate the type instead")
if line.startswith("using testing::TestWithParams;"):
report_error("Don't use 'using testing::Test;, elaborate the type instead")
if re.match(r"^\s*using\s+\w+\s*=\s*[^;]*\*[^;]*;", line) and "(" not in line:
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

This pattern is too broad: it matches any using ... = ...*...; line (any * anywhere), which will flag legitimate existing aliases and likely break the format CI (check_format is run repo-wide). For example, the repo already has raw-pointer aliases in iterator trait types (e.g. using element_type = AsyncClient::Stream*; / using pointer = element_type*; in source/common/http/muxdemux.h) and using ReflectableMessage = ::google::protobuf::Message*; in source/common/protobuf/protobuf.h.

Consider narrowing the check to only catch the STYLE.md case of aliasing a top-level raw pointer type (e.g. require the aliased type to end with * before optional const/volatile), and/or restrict to the naming pattern you want to ban (e.g. aliases whose name ends with Ptr). If some raw-pointer aliases are intentionally required, add an allowlist for those paths/patterns.

Suggested change
if re.match(r"^\s*using\s+\w+\s*=\s*[^;]*\*[^;]*;", line) and "(" not in line:
if re.match(r"^\s*using\s+\w*Ptr\s*=\s*[^;]*\*\s*(?:const|volatile)?\s*;", line) and "(" not in line:

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this feedback seems correct/reasonable

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

added suggestions to feat branch

@Retr0-XD
Copy link
Copy Markdown
Author

Retr0-XD commented Mar 25, 2026

merged suggestions into fix branch

Changed regex from overly broad pattern that matches any line containing
a '*' character to a narrowed check that only flags aliases ending with
'Ptr' pattern (e.g., using BadPtr = int*;). This avoids false positives
on legitimate existing aliases like element_type and pointer iterators.

The check still exempts function pointers (lines containing '(').

Signed-off-by: Retr0-XD <sakthi.harish@edgeverve.com>
@Retr0-XD Retr0-XD temporarily deployed to external-contributors March 27, 2026 14:53 — with GitHub Actions Inactive
@phlax
Copy link
Copy Markdown
Member

phlax commented Mar 27, 2026

/retest

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.

format: add checks for type aliases

4 participants