Skip to content

Conversation

jgromes
Copy link
Owner

@jgromes jgromes commented Jun 21, 2025

This PR adds script to perform uncrustify formatting check and fix. Result of the script is a .patch file which can be applied to fix the issues.

A GitHub action is also added to trigger this on every push to master and every PR.

@jgromes jgromes self-assigned this Jun 21, 2025
@jgromes jgromes added the enhancement New feature or request label Jun 21, 2025
@jgromes
Copy link
Owner Author

jgromes commented Jul 19, 2025

So after some trial and error I managed to get an uncrustify configuration that somewhat matches the existing code style. It did find some inconsistencies, whitespaces at line ends etc., but overall I'm still not completely sure about this. I see the following problems:

  1. It will require contributors to run the check, and do it with a specific uncrustify version. On Linux that's reasonably easy with the script in extras/uncrustify/uncrustify.sh, but I don't know how many contributors here use other OSes. Also, a lot of people contribute very simple fixes (simple meaning 5 changed lines or less) - especially when getting started. This automated check makes it somewhat harder and increases the barrier to entry.
  2. The script does produce a diff file that can be applied with git diff, so technically it's not necessary to run uncrustify locally, however, it requires going to the build artifacts, downloading the diff file from there and applying it manually. Again though, that requires a bit more knowledge, so it has the potential of turning new contributors away.

What do you think @StevenCellist?

@StevenCellist
Copy link
Collaborator

I'd very, very much dislike having to do this. I'm a Windows user most of the time and it sounds terrible to have to do that every time. Let alone for those users that only want to commit a missing state assert and just learned to file an issue.

My personal preference would be to have it e.g. run as part of the release CI.

@StevenCellist
Copy link
Collaborator

It's killing some alignment choices in places where we added some extra whitespace. Which is a minor inconvenience. And probably have it ignore the firmware images?

@jgromes
Copy link
Owner Author

jgromes commented Jul 21, 2025

My personal preference would be to have it e.g. run as part of the release CI.

That is indeed a solution, we can run this on release (and also occasionaly by manual trigger).

It's killing some alignment choices in places where we added some extra whitespace

Could you point out where exactly? Like I said I wasn't able to fully match the existing style

And probably have it ignore the firmware images?

I don't expect any changes there, so I actually don't really care how the firmware-only headers are formatted. Also there's no readability required there.

Copy link
Collaborator

@StevenCellist StevenCellist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marked a couple of yours and one of mine as an example.

Comment on lines 853 to -856
this->preambleDetLength = maxDetLen >= 32 ? RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_32 :
maxDetLen >= 24 ? RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_24 :
maxDetLen >= 16 ? RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_16 :
maxDetLen > 0 ? RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_8 :
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's one

Comment on lines -134 to -137
uint16_t pos = 0;
uint16_t st_idx = 0;
uint16_t st_idx_init = 0;
int16_t bits_left = nb_bits;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another

Comment on lines -523 to -531
this->rev = LoRaWANNode::ntoh<uint8_t>(&this->bufferSession[RADIOLIB_LORAWAN_SESSION_VERSION]);
this->lwClass = LoRaWANNode::ntoh<uint8_t>(&this->bufferSession[RADIOLIB_LORAWAN_SESSION_CLASS]);
this->homeNetId = LoRaWANNode::ntoh<uint32_t>(&this->bufferSession[RADIOLIB_LORAWAN_SESSION_HOMENET_ID]);
this->aFCntDown = LoRaWANNode::ntoh<uint32_t>(&this->bufferSession[RADIOLIB_LORAWAN_SESSION_A_FCNT_DOWN]);
this->nFCntDown = LoRaWANNode::ntoh<uint32_t>(&this->bufferSession[RADIOLIB_LORAWAN_SESSION_N_FCNT_DOWN]);
this->confFCntUp = LoRaWANNode::ntoh<uint32_t>(&this->bufferSession[RADIOLIB_LORAWAN_SESSION_CONF_FCNT_UP]);
this->rev = LoRaWANNode::ntoh<uint8_t>(&this->bufferSession[RADIOLIB_LORAWAN_SESSION_VERSION]);
this->lwClass = LoRaWANNode::ntoh<uint8_t>(&this->bufferSession[RADIOLIB_LORAWAN_SESSION_CLASS]);
this->homeNetId = LoRaWANNode::ntoh<uint32_t>(&this->bufferSession[RADIOLIB_LORAWAN_SESSION_HOMENET_ID]);
this->aFCntDown = LoRaWANNode::ntoh<uint32_t>(&this->bufferSession[RADIOLIB_LORAWAN_SESSION_A_FCNT_DOWN]);
this->nFCntDown = LoRaWANNode::ntoh<uint32_t>(&this->bufferSession[RADIOLIB_LORAWAN_SESSION_N_FCNT_DOWN]);
this->confFCntUp = LoRaWANNode::ntoh<uint32_t>(&this->bufferSession[RADIOLIB_LORAWAN_SESSION_CONF_FCNT_UP]);
this->confFCntDown = LoRaWANNode::ntoh<uint32_t>(&this->bufferSession[RADIOLIB_LORAWAN_SESSION_CONF_FCNT_DOWN]);
this->adrFCnt = LoRaWANNode::ntoh<uint32_t>(&this->bufferSession[RADIOLIB_LORAWAN_SESSION_ADR_FCNT]);
this->fCntUp = LoRaWANNode::ntoh<uint32_t>(&this->bufferSession[RADIOLIB_LORAWAN_SESSION_FCNT_UP]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants