fix some linting errors noted by clang-tidy #999
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I ran this lib through clang-tidy (with a basic/non-restrictive config -- see added .clang-tidy file) and found some linting errors...
Changes
else
afterreturn
casesNo CI checks
Clang-tidy heavily depends on having a compilation database to understand how the sources are compiled. The compilation database is basically a JSON file that stores all compiler commands for each file.
Why not?
A compilation database is specific to the compilation target. To check the Pico SDK examples we'd need to run clang-tidy with different parameters (the
-p=build
option).Currently, we're using my side-project called cpp-linter to run clang-format and get PR suggestions. While it could also run clang-tidy and provide similar code suggestions in a PR, cpp-linter would have to be run multiple times for each compilation target. Unfortunately, if cpp-linter is run multiple times in a single CI event, then the PR review from cpp-linter (displayed as ) is overwritten by the last instance of cpp-linter that completed.
How to use clang-tidy going forward
First make sure clang-tidy is installed. Currently, we're using v14 of clang-format, so stick with that version.
Do not attempt this on Windows because this lib cannot be compiled (or even cross-compiled). And we need a compilation database. WSL Ubuntu could be used instead, but the C/C++ std libs may not be exactly what native Linux env uses.
Note
Reading the clang-tidy output might be tricky. Later versions of clang tools have improved the clang-tidy output, but you'll often find yourself referring to the clang-tidy docs for some errors.