Repository navigation
Add .clang-format configuration file - #65049
Conversation
7290025 to
7764821
Compare
|
jenkins test make check |
|
jenkins test make check |
|
jenkins test make check arm64 |
|
jenkins test make check |
7764821 to
a368a9d
Compare
| BasedOnStyle: Google | ||
| IndentWidth: 2 | ||
| TabWidth: 8 | ||
| UseTab: Always |
There was a problem hiding this comment.
Do these settings codify mixing tabs/spaces? I really hope that perhaps we can transition tospace-only indentation which is what I usually see folks doing already.
There was a problem hiding this comment.
I would much prefer avoiding the mixed tab/space style, but that is still in the CodingStyle and that would be a much larger change.
There was a problem hiding this comment.
+1 for spaces over tabs, mostly because tabs look wrong during github review
There was a problem hiding this comment.
Any opinion on the codingStyle which calls for mixed tabs and spaces? For that matter, just about every file has an Emacs/vim header declaring mixed usage.
There was a problem hiding this comment.
The mixed style is causing issues:
- indentation seems wrong on some tools (e.g. PR review on GitHub, or beyondcompare)
- some editors have troubles supporting it;
... and - it serves no good purpose. I'm all for spaces-only.
There was a problem hiding this comment.
For changing the header of every file in the project, a single PR is probably the best way to go about it.
There was a problem hiding this comment.
That'll affect around 2,000 files. Can Github handle that? And while it would be a simple mechanical change, there would need to be approvals from every group the change touches - is that possible?
There was a problem hiding this comment.
You won't need approvals from everybody. If nobody else wants to review that I will just do a scan you aren't touching anything else in the files and then merge.
There was a problem hiding this comment.
Closer to 4000 files. I probably could break it up better, I didn't realize there was a 3000 file per change limit on what github will display
There was a problem hiding this comment.
Well, that was quick :) Fails in 'Check for Incompatible Licenses'
a368a9d to
f2a71a5
Compare
|
jenkins test make check arm64 |
|
jenkins test api |
f2a71a5 to
f3598c1
Compare
adamemerson
left a comment
There was a problem hiding this comment.
Having the configuration file is good so editors using clang-format pick up our style guidelines and not the LLVM defaults.
f3598c1 to
3255389
Compare
| # should always precede "private:" or "public:" or "protected:" | ||
| AccessModifierOffset: -2 | ||
| IndentCaseLabels: false | ||
| EmptyLineBeforeAccessModifier: Always |
There was a problem hiding this comment.
I would vote for the more permissive 'Leave'
There was a problem hiding this comment.
I find the empty line helpful to visually identify interesting blocks. Without it, the declarations tend to get muddled (to my eye)
| ContinuationIndentWidth: 4 | ||
|
|
||
| # The intended impact here is to allow up to 96 characters, but break at 80 if | ||
| # 96 is exceeded. |
There was a problem hiding this comment.
This works with the penalty values to allow some lines > 80 if it makes sense
There was a problem hiding this comment.
I'd rather keep us at 80 if we can, we've been doing that for a while in much of our code.
There was a problem hiding this comment.
A little wiggle room is handy here, otherwise this 82 char line:
mutable snapid_t cached_seq; // max seq over self and all past+present parents.
is reformatted across 2 lines
mutable snapid_t
cached_seq; // max seq over self and all past+present parents.
There was a problem hiding this comment.
That's a case where I'd just put the comment on the line above, but since we don't enforce hard-80 anywhere, wiggle room looks good to me.
|
|
||
| # Turn off comment reflow entirely | ||
| # TODO: This was done to prevent undoing user-defined formatting of multi-line | ||
| # comments. |
There was a problem hiding this comment.
... and because clang-format is known (?) to be inconsistent in re-flowing from one run to another
| # If false, a function declaration’s or function definition’s parameters | ||
| # will either all be on the same line or will have one line each. | ||
| BinPackArguments: true | ||
| BinPackParameters: true |
There was a problem hiding this comment.
I don't have a clear opinion here (been switching back and forth). I think we should hear more opinions on this one.
There was a problem hiding this comment.
I like keeping them all separate or all together. So that if you add one, you don't need to modify any adjacent lines
There was a problem hiding this comment.
Also makes review, merging, etc. easier, I think.
| # Constructor() | ||
| # : initializer1(), | ||
| # initializer2() | ||
| BreakConstructorInitializers: BeforeColon |
There was a problem hiding this comment.
I really prefer 'BeforeComma', as that allows adding/removing lines without having to fix the line before the point of change.
... and it looks better.
There was a problem hiding this comment.
What about AfterColon? That way initializers can be modified without affecting the decl line.
AfterColon (in configuration: AfterColon) Break constructor initializers after the colon and commas.
Constructor() :
initializer1(),
initializer2()
| BreakConstructorInitializers: BeforeColon | ||
|
|
||
| # Pad the braced list with spaces inside the braces. | ||
| Cpp11BracedListStyle: false |
|
|
||
| # No way to specify C vs C++ style comment for namespace closure, so just | ||
| # leave them alone. | ||
| FixNamespaceComments: false |
There was a problem hiding this comment.
Our code is mostly C++. I strongly suggest 'true'.
| BitFieldColonSpacing: Both | ||
|
|
||
| # Do not break up strings into multi-line strings. This becomes a problem when | ||
| # multi-line strings with no spaces are broken, which upsets the Tup code checker. |
There was a problem hiding this comment.
Having this set to 'false' kills one of clang-format useful and time saving features.
How bad is the problem with that Tup?
There was a problem hiding this comment.
I've run into issues when breaking up strings, not just with tup. I'll set it to true and hope for the best :)
There was a problem hiding this comment.
Do we actually use Tup anywhere?
There was a problem hiding this comment.
No, its a tool I used to use.
There was a problem hiding this comment.
But it wasn't just tup that had problems. As I recall there was a static analysis tool I liked that had issues
| # initializer list is short enough to fit on one line after the wrap, do not break | ||
| # into individual lines. | ||
| # Note NextLineOnly requires clang-format >= 15 | ||
| PackConstructorInitializers: NextLineOnly |
There was a problem hiding this comment.
Note to myself: delve deeper
There was a problem hiding this comment.
This avoids altering adjacent lines when an initializer is added or removed.
| # TODO: This was done to prevent undoing good formatting of doxygen @brief @param | ||
| # etc multi-line comments (similar to this comment). Investigate comment | ||
| # pragmas to leave these alone? | ||
| ReflowComments: false |
There was a problem hiding this comment.
... and because clang-format is known (?) to be inconsistent in re-flowing from one run to another
There was a problem hiding this comment.
Yeah, clang-format can do some ugly things here.
|
A great step forward. |
3255389 to
848c919
Compare
0e20cbd to
674ecef
Compare
|
jenkins test make check arm64 |
|
jenkins test dashboard cephadm |
674ecef to
aa96cae
Compare
|
jenkins test dashboard cephadm |
1 similar comment
|
jenkins test dashboard cephadm |
aa96cae to
828e962
Compare
|
jenkins test make check arm64 |
Update header file tab settings, based on the discussions in this PR and #65049 Reviewed-by: Ilya Dryomov <[email protected]> Reviewed-by: Anthony D Atri <[email protected]> Reviewed-by: Adam Emerson <[email protected]> Reviewed-by: Greg Farnum <[email protected]>
Update cc file tab settings, based on the discussions in this PR and #65049 Reviewed-by: Ilya Dryomov <[email protected]> Reviewed-by: Anthony D Atri <[email protected]> Reviewed-by: Greg Farnum <[email protected]>
…inder Update misc file tab settings, based on the discussions in this PR and #65049 Reviewed-by: Ilya Dryomov <[email protected]> Reviewed-by: Anthony D Atri <[email protected]> Reviewed-by: John Mulligan <[email protected]> Reviewed-by: Greg Farnum <[email protected]>
|
What needs to be done to finish this up? |
|
jenkins test make check arm64 |
1 similar comment
|
jenkins test make check arm64 |
828e962 to
9e29367
Compare
Fixes: https://tracker.ceph.com/issues/72587 Signed-off-by: Edwin Rodriguez <[email protected]>
9e29367 to
2484fdc
Compare
|
This is an automated message by src/script/redmine-upkeep.py. I have resolved the following tracker ticket due to the merge of this PR: No backports are pending for the ticket. If this is incorrect, please update the tracker |
Pull Request: Add Clang-Format Configuration for Consistent Coding Standards
This pull request introduces a
.clang-formatconfiguration file to establish a consistent codingstandard across the project. The configuration is based on the settings from this Gist and serves as a
starting point for discussion on adopting a unified formatting approach.
Purpose
The goal is to initiate a conversation about the benefits of a standardized coding style and
how best to implement it. The proposed configuration includes several settings that may spark
discussion, including:
SortIncludes: true). This organizes include statements but may be debated for its necessity or impact on readability.BinPackParameters: true, function parameters exceeding the line length are packed into fewer lines for compactness. However, this may lead to more line changes when parameters are modified. Alternatives include splitting each parameter to its own line for clarity.*and&(e.g., next to the type, variable, or in the middle) is configured. This is a stylistic choice that may require team consensus.Using
git-clang-formatTo integrate the
.clang-formatconfiguration with your workflow, you can usegit-clang-formatto apply formatting changes to only the modified lines in your Git commits, ensuring minimal disruption to the codebase. Here's how to use it:clang-formatis installed on your system. You can download it as part of LLVM or install it via a package manager (e.g.,apt install clang-formaton Ubuntu orbrew install clang-formaton macOS).git-clang-format:.clang-formatconfiguration to the modified lines in your working tree and stages the formatting changes.main), run:git-clang-format, review the formatted changes usinggit difforgit status. The tool modifies only the lines you’ve changed, preserving the rest of the codebase.git commit -m "Apply clang-format to modified lines"Note: Ensure the
.clang-formatfile is in the repository’s root directory or specify its path with the--style=file:<path>option if it’s located elsewhere.Next Steps
Please review the configuration and share feedback on the proposed settings. Additionally, discuss how
git-clang-formatcan be integrated into our workflow to maintain consistent formatting. This is an opportunity to align on a coding standard that balances readability, maintainability, and team preferences.Fixes: https://tracker.ceph.com/issues/72587
Contribution Guidelines
To sign and title your commits, please refer to Submitting Patches to Ceph.
If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.
When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist
Show available Jenkins commands
jenkins test classic perfJenkins Job | Jenkins Job Definitionjenkins test crimson perfJenkins Job | Jenkins Job Definitionjenkins test signedJenkins Job | Jenkins Job Definitionjenkins test make checkJenkins Job | Jenkins Job Definitionjenkins test make check arm64Jenkins Job | Jenkins Job Definitionjenkins test submodulesJenkins Job | Jenkins Job Definitionjenkins test dashboardJenkins Job | Jenkins Job Definitionjenkins test dashboard cephadmJenkins Job | Jenkins Job Definitionjenkins test apiJenkins Job | Jenkins Job Definitionjenkins test docsReadTheDocs | Github Workflow Definitionjenkins test ceph-volume allJenkins Jobs | Jenkins Jobs Definitionjenkins test windowsJenkins Job | Jenkins Job Definitionjenkins test rook e2eJenkins Job | Jenkins Job Definition