2014-02-26 00:46:13 +08:00
|
|
|
==========
|
|
|
|
Clang-Tidy
|
|
|
|
==========
|
|
|
|
|
2016-02-08 23:09:39 +08:00
|
|
|
.. contents::
|
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2015-08-28 02:10:07 +08:00
|
|
|
.. toctree::
|
|
|
|
:maxdepth: 1
|
|
|
|
|
2016-02-08 23:09:39 +08:00
|
|
|
The list of clang-tidy checks <checks/list>
|
2019-01-18 02:31:34 +08:00
|
|
|
Clang-tidy IDE/Editor Integrations <Integrations>
|
|
|
|
Getting Involved <Contributing>
|
2015-08-28 02:10:07 +08:00
|
|
|
|
2016-02-26 18:24:29 +08:00
|
|
|
:program:`clang-tidy` is a clang-based C++ "linter" tool. Its purpose is to
|
2014-02-26 00:46:13 +08:00
|
|
|
provide an extensible framework for diagnosing and fixing typical programming
|
|
|
|
errors, like style violations, interface misuse, or bugs that can be deduced via
|
|
|
|
static analysis. :program:`clang-tidy` is modular and provides a convenient
|
|
|
|
interface for writing new checks.
|
|
|
|
|
|
|
|
|
|
|
|
Using clang-tidy
|
|
|
|
================
|
|
|
|
|
|
|
|
:program:`clang-tidy` is a `LibTooling`_-based tool, and it's easier to work
|
|
|
|
with if you set up a compile command database for your project (for an example
|
2014-07-16 21:26:51 +08:00
|
|
|
of how to do this see `How To Setup Tooling For LLVM`_). You can also specify
|
2014-02-26 00:46:13 +08:00
|
|
|
compilation options on the command line after ``--``:
|
|
|
|
|
2014-09-28 05:33:33 +08:00
|
|
|
.. code-block:: console
|
2014-02-26 00:46:13 +08:00
|
|
|
|
|
|
|
$ clang-tidy test.cpp -- -Imy_project/include -DMY_DEFINES ...
|
|
|
|
|
|
|
|
:program:`clang-tidy` has its own checks and can also run Clang static analyzer
|
|
|
|
checks. Each check has a name and the checks to run can be chosen using the
|
2014-05-16 21:07:18 +08:00
|
|
|
``-checks=`` option, which specifies a comma-separated list of positive and
|
|
|
|
negative (prefixed with ``-``) globs. Positive globs add subsets of checks,
|
|
|
|
negative globs remove them. For example,
|
2014-02-26 00:46:13 +08:00
|
|
|
|
2014-09-28 05:33:33 +08:00
|
|
|
.. code-block:: console
|
2014-05-16 21:07:18 +08:00
|
|
|
|
2016-11-09 02:12:56 +08:00
|
|
|
$ clang-tidy test.cpp -checks=-*,clang-analyzer-*,-clang-analyzer-cplusplus*
|
2014-05-16 21:07:18 +08:00
|
|
|
|
|
|
|
will disable all default checks (``-*``) and enable all ``clang-analyzer-*``
|
2016-11-09 02:12:56 +08:00
|
|
|
checks except for ``clang-analyzer-cplusplus*`` ones.
|
2014-05-16 21:07:18 +08:00
|
|
|
|
|
|
|
The ``-list-checks`` option lists all the enabled checks. When used without
|
2015-07-27 21:41:30 +08:00
|
|
|
``-checks=``, it shows checks enabled by default. Use ``-checks=*`` to see all
|
2014-05-16 21:07:18 +08:00
|
|
|
available checks or with any other value of ``-checks=`` to see which checks are
|
|
|
|
enabled by this value.
|
2014-02-26 00:46:13 +08:00
|
|
|
|
2016-08-18 19:06:09 +08:00
|
|
|
.. _checks-groups-table:
|
2016-08-18 07:20:00 +08:00
|
|
|
|
2014-07-16 21:26:51 +08:00
|
|
|
There are currently the following groups of checks:
|
2014-02-26 00:46:13 +08:00
|
|
|
|
2016-08-16 01:44:29 +08:00
|
|
|
====================== =========================================================
|
|
|
|
Name prefix Description
|
|
|
|
====================== =========================================================
|
2018-08-22 22:03:30 +08:00
|
|
|
``abseil-`` Checks related to Abseil library.
|
[clang-tidy][Part1] Add a new module Android and three new checks.
Summary:
A common source of security bugs is code that opens a file descriptors without using the O_CLOEXEC flag. (Without that flag, an opened sensitive file would remain open across a fork+exec to a lower-privileged SELinux domain, leaking that sensitive data.).
Add a new Android module and one checks in clang-tidy.
-- open(), openat(), and open64() should include O_CLOEXEC in their flags argument. [android-file-open-flag]
Links to part2 and part3:
https://reviews.llvm.org/D33745
https://reviews.llvm.org/D33747
Reviewers: chh, alexfh, aaron.ballman, hokein
Reviewed By: alexfh, hokein
Subscribers: jbcoe, joerg, malcolm.parsons, Eugene.Zelenko, srhines, mgorny, xazax.hun, cfe-commits, krytarowski
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D33304
llvm-svn: 306165
2017-06-24 05:37:29 +08:00
|
|
|
``android-`` Checks related to Android.
|
2016-08-16 01:44:29 +08:00
|
|
|
``boost-`` Checks related to Boost library.
|
2017-07-14 20:15:55 +08:00
|
|
|
``bugprone-`` Checks that target bugprone code constructs.
|
2016-08-16 01:44:29 +08:00
|
|
|
``cert-`` Checks related to CERT Secure Coding Guidelines.
|
|
|
|
``clang-analyzer-`` Clang Static Analyzer checks.
|
2020-03-21 18:30:30 +08:00
|
|
|
``cppcoreguidelines-`` Checks related to C++ Core Guidelines.
|
|
|
|
``darwin-`` Checks related to Darwin coding conventions.
|
2017-11-29 05:09:25 +08:00
|
|
|
``fuchsia-`` Checks related to Fuchsia coding conventions.
|
2017-05-26 01:22:29 +08:00
|
|
|
``google-`` Checks related to Google coding conventions.
|
|
|
|
``hicpp-`` Checks related to High Integrity C++ Coding Standard.
|
2020-03-21 18:30:30 +08:00
|
|
|
``linuxkernel-`` Checks related to the Linux Kernel coding conventions.
|
2016-08-16 01:44:29 +08:00
|
|
|
``llvm-`` Checks related to the LLVM coding conventions.
|
[clang-tidy] Add module for llvm-libc and restrict-system-libc-header-check.
Summary: This adds a new module to enforce standards specific to the llvm-libc project. This change also adds the first check which restricts user from including system libc headers accidentally which can lead to subtle bugs that would be a challenge to detect.
Reviewers: alexfh, hokein, aaron.ballman
Reviewed By: aaron.ballman
Subscribers: juliehockett, arphaman, jfb, abrachet, sivachandra, Eugene.Zelenko, njames93, mgorny, xazax.hun, MaskRay, cfe-commits
Tags: #clang-tools-extra, #libc-project, #clang
Differential Revision: https://reviews.llvm.org/D75332
2020-03-13 02:38:05 +08:00
|
|
|
``llvmlibc-`` Checks related to the LLVM-libc coding standards.
|
2016-08-16 01:44:29 +08:00
|
|
|
``misc-`` Checks that we didn't have a better category for.
|
|
|
|
``modernize-`` Checks that advocate usage of modern (currently "modern"
|
|
|
|
means "C++11") language constructs.
|
|
|
|
``mpi-`` Checks related to MPI (Message Passing Interface).
|
2017-10-26 16:23:20 +08:00
|
|
|
``objc-`` Checks related to Objective-C coding conventions.
|
[clang-tidy] A new OpenMP module
Summary:
Just the empty skeleton.
Previously reviewed as part of D57113.
Reviewers: JonasToth, aaron.ballman, alexfh, xazax.hun, hokein, gribozavr
Reviewed By: JonasToth, gribozavr
Subscribers: jdoerfert, mgorny, rnkovacs, guansong, arphaman, cfe-commits
Tags: #clang-tools-extra, #openmp, #clang
Differential Revision: https://reviews.llvm.org/D57571
llvm-svn: 356800
2019-03-23 03:46:01 +08:00
|
|
|
``openmp-`` Checks related to OpenMP API.
|
2016-08-16 01:44:29 +08:00
|
|
|
``performance-`` Checks that target performance-related issues.
|
2018-03-08 00:57:42 +08:00
|
|
|
``portability-`` Checks that target portability-related issues that don't
|
|
|
|
relate to any particular coding style.
|
2016-08-16 01:44:29 +08:00
|
|
|
``readability-`` Checks that target readability-related issues that don't
|
|
|
|
relate to any particular coding style.
|
2018-03-15 07:47:50 +08:00
|
|
|
``zircon-`` Checks related to Zircon kernel coding conventions.
|
2016-08-16 01:44:29 +08:00
|
|
|
====================== =========================================================
|
2014-02-26 00:46:13 +08:00
|
|
|
|
2014-07-16 21:26:51 +08:00
|
|
|
Clang diagnostics are treated in a similar way as check diagnostics. Clang
|
2016-11-10 06:31:07 +08:00
|
|
|
diagnostics are displayed by :program:`clang-tidy` and can be filtered out using
|
2014-07-16 21:26:51 +08:00
|
|
|
``-checks=`` option. However, the ``-checks=`` option does not affect
|
|
|
|
compilation arguments, so it can not turn on Clang warnings which are not
|
2016-01-14 01:36:41 +08:00
|
|
|
already turned on in build configuration. The ``-warnings-as-errors=`` option
|
|
|
|
upgrades any warnings emitted under the ``-checks=`` flag to errors (but it
|
|
|
|
does not enable any checks itself).
|
2014-07-16 21:26:51 +08:00
|
|
|
|
|
|
|
Clang diagnostics have check names starting with ``clang-diagnostic-``.
|
|
|
|
Diagnostics which have a corresponding warning option, are named
|
2016-08-10 09:55:51 +08:00
|
|
|
``clang-diagnostic-<warning-option>``, e.g. Clang warning controlled by
|
2014-07-16 21:26:51 +08:00
|
|
|
``-Wliteral-conversion`` will be reported with check name
|
|
|
|
``clang-diagnostic-literal-conversion``.
|
2014-02-26 00:46:13 +08:00
|
|
|
|
2014-07-11 02:59:25 +08:00
|
|
|
The ``-fix`` flag instructs :program:`clang-tidy` to fix found errors if
|
2014-02-26 00:46:13 +08:00
|
|
|
supported by corresponding checks.
|
|
|
|
|
|
|
|
An overview of all the command-line options:
|
|
|
|
|
2014-09-28 05:33:33 +08:00
|
|
|
.. code-block:: console
|
2014-02-26 00:46:13 +08:00
|
|
|
|
[clang-tidy] Store checks profiling info as JSON files
Summary:
Continuation of D46504.
Example output:
```
$ clang-tidy -enable-check-profile -store-check-profile=. -checks=-*,readability-function-size source.cpp
$ # Note that there won't be timings table printed to the console.
$ cat *.json
{
"file": "/path/to/source.cpp",
"timestamp": "2018-05-16 16:13:18.717446360",
"profile": {
"time.clang-tidy.readability-function-size.wall": 1.0421266555786133e+00,
"time.clang-tidy.readability-function-size.user": 9.2088400000005421e-01,
"time.clang-tidy.readability-function-size.sys": 1.2418899999999974e-01
}
}
```
There are two arguments that control profile storage:
* `-store-check-profile=<prefix>`
By default reports are printed in tabulated format to stderr. When this option
is passed, these per-TU profiles are instead stored as JSON.
If the prefix is not an absolute path, it is considered to be relative to the
directory from where you have run :program:`clang-tidy`. All `.` and `..`
patterns in the path are collapsed, and symlinks are resolved.
Example:
Let's suppose you have a source file named `example.cpp`, located in
`/source` directory.
* If you specify `-store-check-profile=/tmp`, then the profile will be saved
to `/tmp/<timestamp>-example.cpp.json`
* If you run :program:`clang-tidy` from within `/foo` directory, and specify
`-store-check-profile=.`, then the profile will still be saved to
`/foo/<timestamp>-example.cpp.json`
Reviewers: alexfh, sbenza, george.karpenkov, NoQ, aaron.ballman
Reviewed By: alexfh, george.karpenkov, aaron.ballman
Subscribers: Quuxplusone, JonasToth, aaron.ballman, llvm-commits, rja, Eugene.Zelenko, xazax.hun, mgrang, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D46602
llvm-svn: 334101
2018-06-06 23:07:51 +08:00
|
|
|
$ clang-tidy --help
|
2014-02-26 00:46:13 +08:00
|
|
|
USAGE: clang-tidy [options] <source0> [... <sourceN>]
|
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
|
2016-02-08 08:19:29 +08:00
|
|
|
Generic Options:
|
2014-02-26 00:46:13 +08:00
|
|
|
|
2019-07-02 02:55:10 +08:00
|
|
|
--help - Display available options (--help-hidden for more)
|
|
|
|
--help-list - Display list of available options (--help-list-hidden for more)
|
|
|
|
--version - Display the version of this program
|
2014-02-26 00:46:13 +08:00
|
|
|
|
|
|
|
clang-tidy options:
|
|
|
|
|
2019-07-02 02:55:10 +08:00
|
|
|
--checks=<string> -
|
|
|
|
Comma-separated list of globs with optional '-'
|
|
|
|
prefix. Globs are processed in order of
|
|
|
|
appearance in the list. Globs without '-'
|
|
|
|
prefix add checks with matching names to the
|
|
|
|
set, globs with the '-' prefix remove checks
|
|
|
|
with matching names from the set of enabled
|
|
|
|
checks. This option's value is appended to the
|
|
|
|
value of the 'Checks' option in .clang-tidy
|
|
|
|
file, if any.
|
|
|
|
--config=<string> -
|
|
|
|
Specifies a configuration in YAML/JSON format:
|
|
|
|
-config="{Checks: '*',
|
|
|
|
CheckOptions: [{key: x,
|
|
|
|
value: y}]}"
|
|
|
|
When the value is empty, clang-tidy will
|
|
|
|
attempt to find a file named .clang-tidy for
|
|
|
|
each source file in its parent directories.
|
|
|
|
--dump-config -
|
|
|
|
Dumps configuration in the YAML format to
|
|
|
|
stdout. This option can be used along with a
|
|
|
|
file name (and '--' if the file is outside of a
|
|
|
|
project with configured compilation database).
|
|
|
|
The configuration used for this file will be
|
|
|
|
printed.
|
|
|
|
Use along with -checks=* to include
|
|
|
|
configuration of all checks.
|
|
|
|
--enable-check-profile -
|
|
|
|
Enable per-check timing profiles, and print a
|
|
|
|
report to stderr.
|
|
|
|
--explain-config -
|
|
|
|
For each enabled check explains, where it is
|
|
|
|
enabled, i.e. in clang-tidy binary, command
|
|
|
|
line or a specific configuration file.
|
|
|
|
--export-fixes=<filename> -
|
|
|
|
YAML file to store suggested fixes in. The
|
|
|
|
stored fixes can be applied to the input source
|
|
|
|
code with clang-apply-replacements.
|
|
|
|
--extra-arg=<string> - Additional argument to append to the compiler command line
|
2019-12-24 20:06:24 +08:00
|
|
|
Can be used several times.
|
2019-07-02 02:55:10 +08:00
|
|
|
--extra-arg-before=<string> - Additional argument to prepend to the compiler command line
|
2019-12-24 20:06:24 +08:00
|
|
|
Can be used several times.
|
2019-07-02 02:55:10 +08:00
|
|
|
--fix -
|
|
|
|
Apply suggested fixes. Without -fix-errors
|
|
|
|
clang-tidy will bail out if any compilation
|
|
|
|
errors were found.
|
|
|
|
--fix-errors -
|
|
|
|
Apply suggested fixes even if compilation
|
|
|
|
errors were found. If compiler errors have
|
|
|
|
attached fix-its, clang-tidy will apply them as
|
|
|
|
well.
|
|
|
|
--format-style=<string> -
|
|
|
|
Style for formatting code around applied fixes:
|
|
|
|
- 'none' (default) turns off formatting
|
|
|
|
- 'file' (literally 'file', not a placeholder)
|
|
|
|
uses .clang-format file in the closest parent
|
|
|
|
directory
|
|
|
|
- '{ <json> }' specifies options inline, e.g.
|
|
|
|
-format-style='{BasedOnStyle: llvm, IndentWidth: 8}'
|
|
|
|
- 'llvm', 'google', 'webkit', 'mozilla'
|
|
|
|
See clang-format documentation for the up-to-date
|
|
|
|
information about formatting styles and options.
|
|
|
|
This option overrides the 'FormatStyle` option in
|
|
|
|
.clang-tidy file, if any.
|
|
|
|
--header-filter=<string> -
|
|
|
|
Regular expression matching the names of the
|
|
|
|
headers to output diagnostics from. Diagnostics
|
|
|
|
from the main file of each translation unit are
|
|
|
|
always displayed.
|
|
|
|
Can be used together with -line-filter.
|
|
|
|
This option overrides the 'HeaderFilterRegex'
|
|
|
|
option in .clang-tidy file, if any.
|
|
|
|
--line-filter=<string> -
|
|
|
|
List of files with line ranges to filter the
|
|
|
|
warnings. Can be used together with
|
|
|
|
-header-filter. The format of the list is a
|
|
|
|
JSON array of objects:
|
|
|
|
[
|
|
|
|
{"name":"file1.cpp","lines":[[1,3],[5,7]]},
|
|
|
|
{"name":"file2.h"}
|
|
|
|
]
|
|
|
|
--list-checks -
|
|
|
|
List all enabled checks and exit. Use with
|
|
|
|
-checks=* to list all available checks.
|
|
|
|
-p=<string> - Build path
|
|
|
|
--quiet -
|
|
|
|
Run clang-tidy in quiet mode. This suppresses
|
|
|
|
printing statistics about ignored warnings and
|
|
|
|
warnings treated as errors if the respective
|
|
|
|
options are specified.
|
|
|
|
--store-check-profile=<prefix> -
|
|
|
|
By default reports are printed in tabulated
|
|
|
|
format to stderr. When this option is passed,
|
|
|
|
these per-TU profiles are instead stored as JSON.
|
|
|
|
--system-headers - Display the errors from system headers.
|
|
|
|
--vfsoverlay=<filename> -
|
|
|
|
Overlay the virtual filesystem described by file
|
|
|
|
over the real file system.
|
|
|
|
--warnings-as-errors=<string> -
|
|
|
|
Upgrades warnings to errors. Same format as
|
|
|
|
'-checks'.
|
|
|
|
This option's value is appended to the value of
|
|
|
|
the 'WarningsAsErrors' option in .clang-tidy
|
|
|
|
file, if any.
|
2014-02-26 00:46:13 +08:00
|
|
|
|
|
|
|
-p <build-path> is used to read a compile command database.
|
|
|
|
|
2014-12-03 22:03:03 +08:00
|
|
|
For example, it can be a CMake build directory in which a file named
|
|
|
|
compile_commands.json exists (use -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
|
|
|
|
CMake option to get this output). When no build path is specified,
|
|
|
|
a search for compile_commands.json will be attempted through all
|
|
|
|
parent paths of the first input file . See:
|
2019-01-23 03:19:48 +08:00
|
|
|
https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html for an
|
2014-12-03 22:03:03 +08:00
|
|
|
example of setting up Clang Tooling on a source tree.
|
2014-02-26 00:46:13 +08:00
|
|
|
|
|
|
|
<source0> ... specify the paths of source files. These paths are
|
2014-12-03 22:03:03 +08:00
|
|
|
looked up in the compile command database. If the path of a file is
|
|
|
|
absolute, it needs to point into CMake's source tree. If the path is
|
|
|
|
relative, the current working directory needs to be in the CMake
|
|
|
|
source tree and the file must be in a subdirectory of the current
|
|
|
|
working directory. "./" prefixes in the relative files will be
|
|
|
|
automatically removed, but the rest of a relative path must be a
|
|
|
|
suffix of a path in the compile command database.
|
2014-02-26 00:46:13 +08:00
|
|
|
|
2016-02-08 08:19:29 +08:00
|
|
|
|
2014-09-28 05:25:26 +08:00
|
|
|
Configuration files:
|
|
|
|
clang-tidy attempts to read configuration for each source file from a
|
|
|
|
.clang-tidy file located in the closest parent directory of the source
|
2020-04-01 17:08:53 +08:00
|
|
|
file. If InheritParentConfig is true in a config file, the configuration file
|
|
|
|
in the parent directory (if any exists) will be taken and current config file
|
|
|
|
will be applied on top of the parent one. If any configuration options have
|
|
|
|
a corresponding command-line option, command-line option takes precedence.
|
|
|
|
The effective configuration can be inspected using -dump-config:
|
2014-12-03 22:03:03 +08:00
|
|
|
|
2017-04-06 22:27:00 +08:00
|
|
|
$ clang-tidy -dump-config
|
2014-12-03 22:03:03 +08:00
|
|
|
---
|
2020-04-01 17:08:53 +08:00
|
|
|
Checks: '-*,some-check'
|
|
|
|
WarningsAsErrors: ''
|
|
|
|
HeaderFilterRegex: ''
|
|
|
|
FormatStyle: none
|
|
|
|
InheritParentConfig: true
|
|
|
|
User: user
|
2016-02-08 08:19:29 +08:00
|
|
|
CheckOptions:
|
2014-12-03 22:03:03 +08:00
|
|
|
- key: some-check.SomeOption
|
|
|
|
value: 'some value'
|
|
|
|
...
|
2014-02-26 00:46:13 +08:00
|
|
|
|
2019-05-16 01:47:51 +08:00
|
|
|
.. _clang-tidy-nolint:
|
|
|
|
|
2018-10-24 00:48:16 +08:00
|
|
|
Suppressing Undesired Diagnostics
|
|
|
|
=================================
|
|
|
|
|
2019-01-22 20:59:34 +08:00
|
|
|
:program:`clang-tidy` diagnostics are intended to call out code that does not
|
|
|
|
adhere to a coding standard, or is otherwise problematic in some way. However,
|
2019-02-07 18:34:43 +08:00
|
|
|
if the code is known to be correct, it may be useful to silence the warning.
|
|
|
|
Some clang-tidy checks provide a check-specific way to silence the diagnostics,
|
2019-02-18 20:50:35 +08:00
|
|
|
e.g. `bugprone-use-after-move <checks/bugprone-use-after-move.html>`_ can be
|
2019-02-07 18:34:43 +08:00
|
|
|
silenced by re-initializing the variable after it has been moved out,
|
|
|
|
`bugprone-string-integer-assignment
|
2019-02-18 20:50:35 +08:00
|
|
|
<checks/bugprone-string-integer-assignment.html>`_ can be suppressed by
|
|
|
|
explicitly casting the integer to ``char``,
|
|
|
|
`readability-implicit-bool-conversion
|
|
|
|
<checks/readability-implicit-bool-conversion.html>`_ can also be suppressed by
|
|
|
|
using explicit casts, etc.
|
2019-02-07 18:34:43 +08:00
|
|
|
|
|
|
|
If a specific suppression mechanism is not available for a certain warning, or
|
|
|
|
its use is not desired for some reason, :program:`clang-tidy` has a generic
|
|
|
|
mechanism to suppress diagnostics using ``NOLINT`` or ``NOLINTNEXTLINE``
|
|
|
|
comments.
|
|
|
|
|
|
|
|
The ``NOLINT`` comment instructs :program:`clang-tidy` to ignore warnings on the
|
|
|
|
*same line* (it doesn't apply to a function, a block of code or any other
|
|
|
|
language construct, it applies to the line of code it is on). If introducing the
|
|
|
|
comment in the same line would change the formatting in undesired way, the
|
|
|
|
``NOLINTNEXTLINE`` comment allows to suppress clang-tidy warnings on the *next
|
|
|
|
line*.
|
|
|
|
|
|
|
|
Both comments can be followed by an optional list of check names in parentheses
|
|
|
|
(see below for the formal syntax).
|
|
|
|
|
|
|
|
For example:
|
2017-12-15 00:13:57 +08:00
|
|
|
|
|
|
|
.. code-block:: c++
|
|
|
|
|
2019-01-22 20:59:34 +08:00
|
|
|
class Foo {
|
2019-02-07 18:34:43 +08:00
|
|
|
// Suppress all the diagnostics for the line
|
2017-12-15 00:13:57 +08:00
|
|
|
Foo(int param); // NOLINT
|
|
|
|
|
2019-02-07 18:34:43 +08:00
|
|
|
// Consider explaining the motivation to suppress the warning.
|
|
|
|
Foo(char param); // NOLINT: Allow implicit conversion from `char`, because <some valid reason>.
|
|
|
|
|
|
|
|
// Silence only the specified checks for the line
|
2017-12-15 00:13:57 +08:00
|
|
|
Foo(double param); // NOLINT(google-explicit-constructor, google-runtime-int)
|
|
|
|
|
2019-02-07 18:34:43 +08:00
|
|
|
// Silence only the specified diagnostics for the next line
|
2017-12-15 00:13:57 +08:00
|
|
|
// NOLINTNEXTLINE(google-explicit-constructor, google-runtime-int)
|
2019-01-22 20:59:34 +08:00
|
|
|
Foo(bool param);
|
2017-12-15 00:13:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
The formal syntax of ``NOLINT``/``NOLINTNEXTLINE`` is the following:
|
|
|
|
|
|
|
|
.. parsed-literal::
|
|
|
|
|
|
|
|
lint-comment:
|
|
|
|
lint-command
|
|
|
|
lint-command lint-args
|
|
|
|
|
|
|
|
lint-args:
|
|
|
|
**(** check-name-list **)**
|
|
|
|
|
|
|
|
check-name-list:
|
|
|
|
*check-name*
|
|
|
|
check-name-list **,** *check-name*
|
|
|
|
|
|
|
|
lint-command:
|
|
|
|
**NOLINT**
|
|
|
|
**NOLINTNEXTLINE**
|
|
|
|
|
|
|
|
Note that whitespaces between ``NOLINT``/``NOLINTNEXTLINE`` and the opening
|
|
|
|
parenthesis are not allowed (in this case the comment will be treated just as
|
2019-01-22 20:59:34 +08:00
|
|
|
``NOLINT``/``NOLINTNEXTLINE``), whereas in check names list (inside the
|
|
|
|
parenthesis) whitespaces can be used and will be ignored.
|
2017-12-15 00:13:57 +08:00
|
|
|
|
2019-01-23 03:19:48 +08:00
|
|
|
.. _LibTooling: https://clang.llvm.org/docs/LibTooling.html
|
|
|
|
.. _How To Setup Tooling For LLVM: https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html
|