Arduino
Arduino copied to clipboard
Use clang-format for auto-format (replaces libastyle)
As per the subject, clang-format is used instead of AStyle.
The clang-format formatting style cannot match the current AStyle formatting style because clang-format has much stricter formatting rules than AStyle and is not possible to provide a configuration that is 100% matching between the two.
clang-format is a mature and maintained tool and it's used in the Arduino IDE 2.0 too.
The "Arduino" clang-format configuration is bundled within the IDE and it's used by default. It may be customized by the user by:
- adding a
.clang-formatconfiguration file in the sketch folder (so the new style is applied only to the sketch) or - adding a
.clang-formatconfiguration file in the data directory, the same directory as thepreferences.txtfile (in this case the style is applied globally)
:white_check_mark: Build completed.
Please test this code using one of the following:
:arrow_down: https://downloads.arduino.cc/javaide/pull_requests/arduino-PR-11543-BUILD-997-linux32.tar.xz :arrow_down: https://downloads.arduino.cc/javaide/pull_requests/arduino-PR-11543-BUILD-997-linux64.tar.xz :arrow_down: https://downloads.arduino.cc/javaide/pull_requests/arduino-PR-11543-BUILD-997-windows.zip :arrow_down: https://downloads.arduino.cc/javaide/pull_requests/arduino-PR-11543-BUILD-997-macosx.zip :arrow_down: https://downloads.arduino.cc/javaide/pull_requests/arduino-PR-11543-BUILD-997-linuxarm.tar.xz
:information_source: The linuxarm build is still experimental and may not be always available.
yay!
Fixes:
- https://github.com/arduino/Arduino/issues/10326
- https://github.com/arduino/Arduino/issues/10946
Good one, it also taught me a lesson when it comes to one-liner loops 😬
@ladyada
any chance your team can check if this format aligns with the one used in your clang-format step in the PR CI?
hey00 we use clang-format-8 and believe me we have learned they are not all the same so you really have to pick one and stick to it. that said, if y'all want to pick one clang format version i'm happy to change our CI to match :)
https://github.com/adafruit/ci-arduino/blob/master/actions_install.sh#L8
we have learned they are not all the same so you really have to pick one and stick to it. that said, if y'all want to pick one clang format version i'm happy to change our CI to match :)
Hi @ladyada. Thanks so much for this advice. It caused me to give more attention to the need to carefully evaluate the impact of updates to the version of ClangFormat on the output of the Arduino IDE's "Auto Format" feature.
If the recent development history is any indication, it is likely Arduino will continue to update to new versions of ClangFormat periodically. We have created a system for efficiently and reliably validating these updates:
https://github.com/arduino/tooling-project-assets/tree/main/other/clang-format-configuration
This system allows for updates to the ClangFormat version in use while ensuring consistent results for the Arduino IDE users.
The system is focused on the maintenance of Arduino's custom ClangFormat configuration file, whereas from a quick look at a few random repos it appears Adafruit is using the default configuration, so you may have slightly different considerations. However, clang-format --dump-config can be used to output the effective configuration of the tool, so really not so different after all.
Arduino IDE 2.x is currently using ClangFormat 14.0.0. Even though there was an astonishing number of changes to the configuration options since the 11.0.1 version used at the time Arduino's custom configuration was developed, backwards compatibility with the old configuration was retained and the diff between the output of the two versions was restricted to code using a few newer C++ language features.
sounds good - yes one day we will probably update to -11, but of course it could require a big sweep to assure that we can go through and fix all the libraries to pass. mostly clang-format really helps keep PRs reasonable - we would get a lot of PRs with tons of whitespace changes and clangformatting at least keeps the formatting consistant so we can review PRs without noise :)