networkupstools / nut

The Network UPS Tools repository. UPS management protocol Informational RFC 9271 published by IETF at https://www.rfc-editor.org/info/rfc9271 Please star NUT on GitHub, this helps with sponsorships!
https://networkupstools.org/
Other
2.12k stars 353 forks source link

Set up clang-format to maintain NUT source style #894

Open jimklimov opened 4 years ago

jimklimov commented 4 years ago

Following up from #823, yet another effort in the back of my mind was to codify the NUT source style as documented, and provide tools to check and maintain it on both CI systems and developer workstations with clang-format. Such work was already done by myself and others in zproject community, just porting is needed; the complicated part will be codifying the style itself into a configuration file. Examples:

On a similar note, clang-tidy could be added for tracking code problems though that niche is currently occupied (non-exclusively) by the CI build matrix over many OSes and distros, and LGTM.com reports.

After that, the existing codebase can be reformatted: meaning a huge commit with lots of whitespace changes, but unless some tool bugs out - the result is congruent to original state as far as preprocessor and compiler are concerned... (that might be among the ways to check the impact actually).

Subsequently, any style offense in new commits and PRs is easily noticed and fixed, including a post-processing fix to do after a merge of contribution PRs.

UPDATE: It may also be convenient for developers (at a moderate low-frequency cost to maintainers) to provide also an .editorconfig file with settings equivalent to those requested by .clang-format such that common IDEs and other text editors can ensure the expected code style.

jimklimov commented 2 years ago

Interesting trick to help developers who do not have local clang-format (more so if certain versions are needed) : https://github.com/collectd/collectd/blob/main/contrib/format.sh

jimklimov commented 1 year ago

For another inspiration, bookmarking https://github.com/stephane/libmodbus/commit/dd45f19a6efc20d6032b424a067294086a315899

Not sure I agree with all the changes it proposed to the source code base (e.g. some multi-line expressions looked better originally IMHO and got squashed into one-liners), but may still be a baseline to experiment from.