-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
clang-format: improve and update #41307
Conversation
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.
I haven’t tested it but the changes look reasonable.
I didn't compare inherited options. I assume that you have tested it and results are exactly the same or even better due to enable options that were commented out for backward compatibility. Am I right with my assumption? |
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.
I tried this out on the existing code base and, at least personally, I thought it did a really nice job.
It aligned macro and function arguments that were previously unaligned. It removed extraneous spaces, which there were surprisingly things like
uint32_t x = 123;
Where the double spacing after the = would be fixed to a single space.
It generally made things more, not less, readable. I didn't run checkpatch after, that might be an interesting bout to see if they agree.
getting:
clang-format version 12.0.1 (Fedora 12.0.1-1.fc34) |
a157020
to
2b12325
Compare
Commented out this option (available since |
I'm not sure how to do this and avoiding bike-shading but in order to help getting a consensus on the change and not coming back on it later, would it be possible to demonstrate the result if this change, so each one can have a chance to give his opinion and commonly agree on the result? |
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
This isn't stale, and I still care |
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
Update the list of for each macros using the suggested command in the configuration file. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
The amount of options available on clang-format has become quite extensive over-time, making a dumped file difficult to read or maintain. In this patch the .clang-format has been re-written by inheriting from LLVM (default) since most of the options can be re-used to match the Zephyr/Linux coding style conventions. Note: The 14 release has interesting options for Zephyr, in particular, these new settings would be beneficial: IfMacros: - CHECKIF SpaceBeforeParens: Custom SpaceBeforeParensOptions: AfterForeachMacros: true AfterIfMacros: true .clang-format should be periodically updated as new clang-format releases reach Linux distros. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Prefer clang-format over uncrustify for source code formatting. uncrustify configuration files will be removed in future commits. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Remove uncrustify configuration file in favor of using clang-format, a tool that is nowadays more popular/powerful for code formatting. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
It should be noted that the clang tooling actually uses LLVM as the C / C++ parser, so it's quite accurate as it's derived from the AST. IIRC, Of course, there is also scan-build for static analysis, which uses LLVM and leverages the AST as well. |
It would be nice to introduce static const struct jm101_config jm101_config_##i = { \
... \
}; \
\ /* <- clang-format starts line with spaces here, not tab, checkpatch complains about leading spaces */
DEVICE_DT_INST_DEFINE(i, jm101_init, NULL, &jm101_data_##i, \ However, I guess we could patch checkpatch to ignore those edge cases. Our abuse of nested macros can confuse static const struct jm101_config jm101_config_##i = { \
.uart = DEVICE_DT_GET(DT_INST_PHANDLE(i, uart)), \
.addr = DT_INST_PROP(i, address), \
IF_ENABLED(CONFIG_JM101_TRIGGER, \
(.touch = GPIO_DT_SPEC_INST_GET_OR(i, touch_gpios, \
{}), )) /* */ \ /* comment added to force line break here, otherwise clang-format doesn't work well */
}; \
\
DEVICE_DT_INST_DEFINE(i, jm101_init, NULL, &jm101_data_##i, \ But overall, I had a good experience with it, specially when refactoring code. |
I'm also in favor to use |
@gmarull - that mirrors my experiences as well. It's probably something that is worth fixing upstream on behalf of the Zephyr project if we were to adopt |
Agreed, would be nice to have these small issues fixed upstream. |
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.
Yes please
+1 to clang-format, @nashif and @MaureenHelm ping |
The number of options available on clang-format has become quite
extensive over-time, making a dumped file difficult to read or maintain.
In this patch, the .clang-format has been re-written by inheriting from
LLVM (default) since most of the options can be re-used to match the
Zephyr/Linux coding style conventions.