We use clang-tidy to lint C++ code and aim to keep the repository warning-clean. The linter is configured in the .clang-tidy file.
In order to run a specific GN target through the linter, run:
fx clang-tidy --target=<target>
You can also add --fix
in order to automatically generate fixes for some (but not all) of the warnings.
Alternatively, you can run the following to run the current patch through the linter:
../scripts/git-file-tidy [--out-dir out/debug-x64]
In order to run the entire repository through the linter, add --all
. You can also add --fix
in order to automatically generate fixes for some (but not all) of the warnings.
Any warning can be suppressed by adding a // NOLINT(<check_name>)
or a // NOLINTNEXTLINE(<check_name>)
comment to the offending line. It is also possible to disable the check entirely within the repository by editing the .clang-tidy file.
There are a number of check categories enabled, and specific checks within them have been disabled for the reasons below. The list of enabled check categories is as follows:
bugprone-*
clang-diagnostic-*
clang-analyzer-*
google-*
misc-*
modernize-
performance-*
readability-*
This list tracks the reasons for which we disabled in particular checks:
clang-analyzer-core.NullDereference
, clang-analyzer-unix.Malloc
- these checks are triggering memory access warnings at rapidjson callsites (despite the header filter regex) and we didn't find a more granular way to disable themclang-diagnostic-unused-command-line-argument
- ninja-generated compilation database contains the linker argument which ends up unused and triggers this warning for every filemisc-noexcept*
- Fuchsia doesn't use C++ exceptionsmodernize-deprecated-headers
- Fuchsia uses old-style C headersmodernize-raw-string-literal
- the check was suggesting to convert \xFF
literals, which we'd rather keep in the escaped form.modernize-return-braced-init-list
- concerns about readability of returning braced initialization list for constructor arguments, prefer to use a constructor explicitlymodernize-use-auto
- not all flagged callsites seemed worth converting to auto
modernize-use-equals-delete
- flagging all gtest TEST_Fmodernize-use-equals-default
- Fuchsia chose not to impose a preference for “= default”performance-unnecessary-value-param
- it was flagging view classes which we prefer to pass by valuereadability-implicit-bool-conversion
- Fuchsia C++ code commonly uses implicit bool cast of pointers and numbers