-
Notifications
You must be signed in to change notification settings - Fork 430
RFC: Add clang-format configuration and CONTRIBUTING.md #855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lemenkov
wants to merge
1
commit into
SIPp:master
Choose a base branch
from
lemenkov:clang_format
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| # SIPp clang-format configuration | ||
| # Based on existing code style patterns in the repository | ||
|
|
||
| Language: Cpp | ||
| Standard: c++17 | ||
|
|
||
| # Base style - start from LLVM and customize | ||
| BasedOnStyle: LLVM | ||
|
|
||
| # Indentation | ||
| IndentWidth: 4 | ||
| TabWidth: 4 | ||
| UseTab: Never | ||
| IndentCaseLabels: false | ||
| IndentPPDirectives: None | ||
| NamespaceIndentation: None | ||
|
|
||
| # Braces - Allman/BSD style (braces on their own lines) | ||
| BreakBeforeBraces: Allman | ||
| # More granular control if needed: | ||
| # BraceWrapping: | ||
| # AfterClass: true | ||
| # AfterControlStatement: Always | ||
| # AfterEnum: true | ||
| # AfterFunction: true | ||
| # AfterNamespace: true | ||
| # AfterStruct: true | ||
| # AfterUnion: true | ||
| # BeforeCatch: true | ||
| # BeforeElse: true | ||
| # IndentBraces: false | ||
|
|
||
| # Line length | ||
| ColumnLimit: 120 | ||
|
|
||
| # Pointer and reference alignment - attach to variable name | ||
| PointerAlignment: Right | ||
| ReferenceAlignment: Right | ||
| # e.g., char *ptr, int &ref | ||
|
|
||
| # Spacing | ||
| SpaceAfterCStyleCast: false | ||
| SpaceAfterLogicalNot: false | ||
| SpaceBeforeAssignmentOperators: true | ||
| SpaceBeforeParens: ControlStatements | ||
| SpaceInEmptyParentheses: false | ||
| SpacesInCStyleCastParentheses: false | ||
| SpacesInParentheses: false | ||
| SpacesInSquareBrackets: false | ||
|
|
||
| # Alignment | ||
| AlignAfterOpenBracket: Align | ||
| AlignConsecutiveAssignments: false | ||
| AlignConsecutiveDeclarations: false | ||
| AlignEscapedNewlines: Left | ||
| AlignOperands: true | ||
| AlignTrailingComments: true | ||
|
|
||
| # Short statements | ||
| AllowShortBlocksOnASingleLine: Empty | ||
| AllowShortCaseLabelsOnASingleLine: false | ||
| AllowShortFunctionsOnASingleLine: Empty | ||
| AllowShortIfStatementsOnASingleLine: Never | ||
| AllowShortLoopsOnASingleLine: false | ||
|
|
||
| # Breaking | ||
| BreakBeforeBinaryOperators: None | ||
| BreakBeforeTernaryOperators: true | ||
| BreakConstructorInitializers: BeforeColon | ||
| BreakStringLiterals: true | ||
|
|
||
| # Arguments and parameters | ||
| AllowAllArgumentsOnNextLine: true | ||
| AllowAllParametersOfDeclarationOnNextLine: true | ||
| BinPackArguments: true | ||
| BinPackParameters: true | ||
|
|
||
| # Includes | ||
| IncludeBlocks: Preserve | ||
| SortIncludes: false # Don't reorder includes - can break builds | ||
|
|
||
| # Other | ||
| FixNamespaceComments: true | ||
| MaxEmptyLinesToKeep: 2 | ||
| ReflowComments: false # Don't reflow comments - can break formatting | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| ## Code Formatting | ||
|
|
||
| This project uses [clang-format](https://clang.llvm.org/docs/ClangFormat.html) to maintain consistent code style. Pull requests are automatically checked for formatting compliance. | ||
|
|
||
| ### Setup | ||
|
|
||
| Install clang-format (version 18 recommended): | ||
|
|
||
| ```bash | ||
| # Ubuntu/Debian | ||
| sudo apt install clang-format-18 | ||
|
|
||
| # macOS | ||
| brew install clang-format | ||
|
|
||
| # Fedora | ||
| sudo dnf install clang-tools-extra | ||
| ``` | ||
|
|
||
| ### Usage | ||
|
|
||
| Format a single file: | ||
|
|
||
| ```bash | ||
| clang-format -i src/myfile.cpp | ||
| ``` | ||
|
|
||
| Format all source files: | ||
|
|
||
| ```bash | ||
| find src include -type f \( -name '*.cpp' -o -name '*.hpp' -o -name '*.c' -o -name '*.h' \) | xargs clang-format -i | ||
| ``` | ||
|
|
||
| Check formatting without modifying files: | ||
|
|
||
| ```bash | ||
| clang-format --dry-run --Werror src/myfile.cpp | ||
| ``` | ||
|
|
||
| ### Editor Integration | ||
|
|
||
| Most editors support automatic formatting on save: | ||
|
|
||
| - **VS Code**: Install the "C/C++" extension, enable "Format On Save" | ||
| - **CLion**: Built-in support, enable in Settings → Editor → Code Style | ||
| - **Vim**: Use [vim-clang-format](https://github.com/rhysd/vim-clang-format) | ||
| - **Emacs**: Use [clang-format.el](https://clang.llvm.org/docs/ClangFormat.html#emacs-integration) | ||
|
|
||
| ### Style Overview | ||
|
|
||
| The project uses a style based on LLVM with these key settings: | ||
|
|
||
| - 4-space indentation (no tabs) | ||
| - Allman/BSD brace style (braces on their own lines) | ||
| - 120 character line limit | ||
| - Pointer/reference aligned right (`char *ptr`, not `char* ptr`) | ||
| - Includes are not sorted (to avoid breaking builds) | ||
|
|
||
| See `.clang-format` in the repository root for the complete configuration. |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code has both
AllmanandLinux. I generally preferLinuxactually (https://clang.llvm.org/docs/ClangFormatStyleOptions.html#breakbeforebraces)