-
-
Notifications
You must be signed in to change notification settings - Fork 101
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
Draft: Add a lint job #166
base: master
Are you sure you want to change the base?
Conversation
67bc810
to
75b2ae8
Compare
Hi! Btw, something I tried to configure is to avoid the linter aggressively reorder the whitespaces in the struct definitions. For example this file became this after a lint pass, something I consider a regression in the code style. If you know a wayt to tell clang-format to not bother with these alignment, please let me know. |
Thanks @silseva ! Looking forward to your guidance on where these changes are undesired and clang-format needs more configuration. Regarding the whitespace concern you mention, I can fix this. I'll push up a change in a few minutes, |
Here you are the clang-format file I began to tweak. As you'll see, I set the
Thanks for the work done so far! |
d5f4fc8
to
f5f14d0
Compare
@silseva when you get a moment, please re-review and point me to some examples of the patterns of issues that you see. I do notice right now where the following rule from the website is being contradicted:
Unfortunately it does not appear that this is compatible with clang-format. The formatter will always remove the spaces. There are some changes this introduces to typedef names collapsing onto the end of the struct's definition block, but I'm also not seeing a way to change this with clang-format. Other than these, I'm not seeing other coding styles that are obstructed by this change. But C/C++ is not my experience, and so I'm sure that I'm missing things. |
bandCalData_t data[2]; // Calibration data for VHF (index 0) and UHF (index 1) bands | ||
freq_t vhfCalPoints[8]; // VHF calibration points for both TX power and mod1Amplitude | ||
bandCalData_t | ||
data[2]; // Calibration data for VHF (index 0) and UHF (index 1) bands |
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.
Is there a way to avoid having the lint doing this? Ok that the line goes above the 80 column limit, but breaking it like this make it unreadable. Probably the only way to fix this behavior is to split the comment (but geez).
} | ||
mod17Calib_t; | ||
uint8_t mic_gain; | ||
uint8_t tx_invert : 1, rx_invert : 1, _padding : 6; |
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.
We should prevent the lint from doing this
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.
Right now this is happening because there are no comments after the field definition. The other cases where the newlines are maintained are there because of the comments. I'm unclear on whether we can force these to new lines without comments (or disabling clang-format for the block).
Will investigate feasibility here more later.
|
||
|
||
uint8_t rxToneEn : 1, //< RX CTC/DCS tone enable | ||
rxTone : 7; //< RX CTC/DCS tone index |
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.
All the fields should stay aligned, like it was before. This makes them more readable
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.
Help me understand what I'm looking at here, is this called a "multiple adjacent bit field"?
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!
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.
Haven't cracked how to do this yet.
openrtx/include/core/graphics.h
Outdated
@@ -223,8 +221,11 @@ uint8_t gfx_getFontHeight(fontSize_t size); | |||
* @param buf: char buffer | |||
* @return text width and height as point_t coordinates | |||
*/ | |||
point_t gfx_printBuffer(point_t start, fontSize_t size, textAlign_t alignment, | |||
color_t color, const char *buf); | |||
point_t gfx_printBuffer(point_t start, |
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.
Probably is better to avoid having the pile of arguments, when they are more than three the linted version becomes a bit more messy than the original one
class RingBuffer | ||
{ | ||
public: |
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.
Is it possible to leave the private
, public
and protected
fields with indentation zero (as they where before)?
openrtx/include/core/gps.h
Outdated
float tmg_true; // Course over ground, degrees, true | ||
} | ||
gps_t; | ||
datetime_t timestamp; // Timestamp of the latest GPS update |
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.
Is it possible to tell the lint to do the opposite of what is doing here? Instead of chewing up the extra spaces, I think is better, for readability, to have all the field names aligned.
openrtx/include/core/state.h
Outdated
@@ -35,32 +35,31 @@ | |||
*/ | |||
typedef struct | |||
{ |
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.
Just another example: removing the extra spaces broke the alignment of the fields, making the code less clear
@@ -198,23 +198,21 @@ typedef enum | |||
vpAnnounceLessCommonSymbols = 0x10, | |||
vpAnnounceASCIIValueForUnknownChars = 0x20, | |||
vpAnnouncePhoneticRendering = 0x40, | |||
} | |||
vpFlags_t; | |||
} vpFlags_t; | |||
|
|||
/** | |||
* Queuing flags determining if speech is interrupted, played immediately, | |||
* whether prompts are queued for values, etc. | |||
*/ | |||
typedef enum | |||
{ |
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.
Urgh! Also here: please, lint, leave the alignment as it was :)
@@ -36,22 +37,73 @@ namespace M17 | |||
/** | |||
* Puncture matrix for linx setup frame. | |||
*/ | |||
static constexpr auto LSF_PUNCTURE = std::experimental::make_array< uint8_t > |
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.
Here the lint went crazy!
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.
Haha, going to have to use a //clang-format off
here.
static constexpr syncw_t EOT_SYNC_WORD = {0x55, 0x5D}; // End of transmission sync word | ||
static constexpr syncw_t LSF_SYNC_WORD = {0x55, 0xF7}; // LSF sync word | ||
static constexpr syncw_t BERT_SYNC_WORD = {0xDF, 0x55}; // BERT data sync word | ||
static constexpr syncw_t STREAM_SYNC_WORD = {0xFF, |
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.
Why did the lint break this? Again for the 80 column overflow?
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, but we can force the comment to wrap instead.
static constexpr float CONV_STATS_ALPHA = 0.005f; | ||
static constexpr float CONV_THRESHOLD_FACTOR = 3.40; | ||
static constexpr int16_t QNT_SMA_WINDOW = 8; | ||
static constexpr size_t M17_RX_SAMPLE_RATE = 24000; |
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.
Ok that we overflowed the 80 columns, but it was more readable... Probably we have to add lint exceptions here and there
|
||
/* | ||
* Buffers | ||
*/ | ||
std::unique_ptr< int16_t[] > baseband_buffer; ///< Buffer for baseband audio handling. |
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.
Also here we have a readability regression
I did a round of revision and, while doing it, I remembered why at some point I gave up with adjusting the clang-format file: I found that in some occasions the lint behavior is way too rigid and leads to code worse than before in terms of readability. Comments/opinions are welcome! |
Thanks for the detailed feedback. I'll work on these items next. As far as the rigidity of the formatter, I agree that at times that results in less readable code. The tradeoff, that contributors and reviewers no longer have to be concerned with formatting as they make changes, is quite empowering. In most of my past projects we've found that the compromise is worth it -- but that doesn't necessarily mean that it is here. Let's see how close I can continue to make this PR before we really consider that question. If in the end it is still unclear what path to take, there are other options that we can take too (optional? just formatting the changed code?). |
…and clang-format-ignore to be a little more courteous
2d75e11
to
04d6d01
Compare
What
When I was contributing, I realized that code styles could be replaced with just enforcing clang-format. There appears to have been a previous integration done, but it's not been maintained. Let's fix that by adding a CI job. That way format can just be on auto-pilot and we don't need to be concerned, letting us remove the entire
code_style
page from the website.Why
To make contributing easier, both for the contributor and the maintainer.
How
This PR leverages where meson automatically creates the
clang-format
andclang-format-check
target if the host has clang-format installed.The timing of landing this PR is critical -- just before it lands, catch this branch up with wherever it's being merged, and then
mason setup build; ninja -C build clang-format
needs to run and have the resulted checked in. Otherwise builds will be blocked.Note this requires clang-format-16 due to the complex standards this project has for AlignTrailingComments.
Next steps
meson setup build; ninja -C build clang-format
)clang-format
portion of Remove default include paths #96 by @carpikes