Skip to content

Script to uncrustify files not modified on branches

username-removed-84494 requested to merge martin-t/uncrustify into master

This should allow us to format at least some files without causing lots of merge conflicts. It can be run periodically as more branches get merged (but some dead branches will keep certain files unformatted until we remove them or format everything eventually).

Now it's pretty conservative so if a branch merged master into itself it'll mark more files as modified than necessary, I am not sure if there's a clean way to get only files modified on that branch.

Some (potential) issues with the uncrustify config I noticed:

  • It indents #define but not #elif defined or #undef.
    • This also leaves comments unindented and only indents code. Can we just not introduce an indent level for #ifdefs? One of my changes took care of this whole thing. Now uncrustify seems to mostly leave indentation in ifdefs as is.
  • Messes up ENTCS_PROP a little by putting } on new lines. // *INDENT-OFF* FTW
  • Some macros with MACRO_END in lib/iter.qh end up indented very incorrectly. A proper mix of removing curly braces, adding curly braces and adding semicolons fixed it.
  • Puts curly braces of do while on new lines. I fixed that to make it consistent with other control statements.
  • Some macros in cl_damagetext get line wrapped but others don't so it's ugly. Not just in cl_damagetext. There was a lot of cases where uncrutify split a line slightly above 120 into 3 lines and often completely randomly, not according to operator precedence or anything so I disabled line wrapping unless someone wants to go through a lot of code and fix it to appease a clearly bad algorithm.
  • Exponentiation operator (**) some gets broken into * *, sometimes the space after it is removed as if it was double dereference. I am not sure how to fix this in the general case without breaking comments like /** */ or the notes in ./common/weapons/weapon/tuba.qc. Can we just wrap ** in a macro and wrap that in // *INDENT-OFF*? I did just that, when we compile QC to a better language this is gonna be easier anyway.

I changed indent_with_tabs to 2, otherwise code inside macros (like FOREACH loops) would be indented with a mix of spaces and tabs. To be fair, the option is kinda stupid, it only uses spaces when not on a multiple of 4, not to align above indent level as the description suggests. (In other words, it aligned with tabs anyway most of the time)

Some other options were changed, sometimes i tried both/all values and picked the one with fewest changes, some changes are to avoid really bad indentation in macro-heavy code. The switch and do/while changes are to be consistent with if, for and while.

Now the script ignores branches that weren't changed in the last 2 years, it allows some 200 additional files to be formatted.

I scanned through the resulting diff and could not find any obviously broken things. I'll commit the formatted code in a new branch so it's easier to review these changes separately and when the tests finish we'll see if the formatting triggered any new compiler bugs ;)

Edited by username-removed-84494

Merge request reports