Closed RafaelLeeImg closed 1 year ago
clang-format result is different from the rules in CI, so code formatted by clang-format could not pass CI.
This in itself is not a bug. We have never made any guarantees that the style defined by the clang-format file will 100% match the Zephyr coding style and guidelines.
For now, clang-format support is more or less experimental and one should not expect it to be a one-stop solution to all coding formatting issues -- additional human interventions may be necessary.
Also, please see the related discussions in the following issues:
cc @gmarull
At least there shall be some way that let user to setup the coding style checker at their local computer, is there any way to do that? I didn't find any related documents.
https://docs.zephyrproject.org/latest/contribute/guidelines.html#coding-style
At least there shall be some way that let user to setup the coding style checker at their local computer, is there any way to do that? I didn't find any related documents.
Did you see The Linux kernel GPL-licensed tool checkpatch is used to check coding style conformity.
?
OK, now I know how to use that. Shall those included in Zephyr documents?
./scripts/checkpatch.pl 0001-sensors-Add-AHT20-temperature-humidity-sensor.patch
By the way, it's showing another false positive warning, it's not lables, it's bit field.
+typedef union {
0001-sensors-Add-AHT20-temperature-humidity-sensor.patch:108: WARNING:INDENTED_LABEL: labels should not be indented
#108: FILE: drivers/sensor/aht20/aht20.c:35:
+ uint8_t: 3; /* bit [0:2] */
Related code is:
typedef union {
struct {
uint8_t: 3; /* bit [0:2] */
uint8_t cal_enable : 1; /* bit [3] */
uint8_t: 1; /* bit [4] */
uint8_t: 2; /* bit [5:6], AHT20 datasheet v1.1 removed 2 mode bits */
uint8_t busy : 1; /* bit [7] */
};
uint8_t all;
} __attribute__((__packed__)) aht20_status;
OK, now I know how to use that. Shall those included in Zephyr documents?
The instruction is right there in the documentation you linked ...
By the way, it's showing another false positive warning, it's not lables, it's bit field.
This will be fixed by https://github.com/zephyrproject-rtos/zephyr/pull/51975
Unless there's a clang-format option to match checkpatch expectations, I think the best is to patch checkpatch or ignore the failure.
It should be possible to fix the clang format config. See setting BitFieldColonSpacing (BitFieldColonSpacingStyle) that is available starting from clang-format 12: https://clang.llvm.org/docs/ClangFormatStyleOptions.html This should be set to After
.
Thanks. I tried offline, it works. I have created a pull-request #52268
Pull request merged #52268 This problem is solved.
Describe the bug clang-format result is different from the rules in CI, so code formatted by clang-format could not pass CI. Let human rember coding style or trial & error is not a systematic way for clean codes. I believe that I'm not the only one who has encountered this problem.
That space is added by clang-format.
https://github.com/zephyrproject-rtos/zephyr/actions/runs/3395127653/jobs/5646003818
Please also mention any information which could help others to understand the problem you're facing:
To Reproduce Steps to reproduce the behavior:
Expected behavior Code pass CI
Impact Waste of time for multiple times.
Logs and console output
Environment (please complete the following information):
Additional context Is is an existing problem lasts for at least a year.