Add clang-format config and GitHub Actions CI check#1949
Open
lolyu wants to merge 1 commit into
Open
Conversation
Adds C++ code formatting enforcement for sonic-sairedis:
1. .clang-format — defines the project's coding style based on
analysis of existing source conventions:
- Allman brace style (every { on its own line)
- 4-space indentation, no tabs
- Pointer attached to variable name (type *var)
- Namespace body indented 4 spaces
- Soft 120-char line limit
- No auto-sort includes (preserve existing grouping)
2. .github/workflows/clang-format.yml — PR check that runs
clang-format-14 only on C/C++ files changed in the PR
(not the entire codebase), so pre-existing code is not
affected. The SAI/ submodule and debian/ directories are
excluded.
This follows the pattern established by sonic-net/sonic-linkmgrd
which is currently the only other SONiC C++ repo with clang-format.
Developers can fix format issues locally with:
git diff --name-only HEAD~1 | grep -E '\.(cpp|h)$' | xargs clang-format -i
Signed-off-by: Long Xiang Lyu <lonxlyu@microsoft.com>
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of PR
Adds C++ code formatting enforcement to sonic-sairedis using clang-format.
Type of change
What is included
.clang-format - project style config derived from analysis of existing source conventions across syncd/, lib/, meta/, vslib/, and proxylib/:
.github/workflows/clang-format.yml - PR check that:
Why diff-only?
Enforcing format on the entire existing codebase at once would create a massive diff that breaks git blame. The diff-only approach allows gradual adoption: new/modified code must be formatted, existing untouched code is not flagged.
Developer workflow
Fix format issues locally before pushing:
This follows the pattern established by sonic-net/sonic-linkmgrd which is currently the only other SONiC C++ repo with clang-format enforcement.
Back port request