From 68d5652380b7bd4738f53b252d3677166c367f47 Mon Sep 17 00:00:00 2001 From: Alexander Kornienko Date: Thu, 7 Feb 2019 10:34:43 +0000 Subject: [PATCH] [clang-tidy] Expand and clarify the NOLINT documentation a bit. llvm-svn: 353382 --- clang-tools-extra/docs/clang-tidy/index.rst | 43 +++++++++++++++------ 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/clang-tools-extra/docs/clang-tidy/index.rst b/clang-tools-extra/docs/clang-tidy/index.rst index 720c581d463e..1cbd8dc58eb0 100644 --- a/clang-tools-extra/docs/clang-tidy/index.rst +++ b/clang-tools-extra/docs/clang-tidy/index.rst @@ -262,25 +262,46 @@ Suppressing Undesired Diagnostics :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, -if it is known that the code is correct, the check-specific ways to silence the -diagnostics could be used, if they are available (e.g. bugprone-use-after-move -can be silenced by re-initializing the variable after it has been moved out, -bugprone-string-integer-assignment can be suppressed by explicitly casting the -integer to ``char``, readability-implicit-bool-conversion can also be suppressed -by using explicit casts, etc.). If they are not available or if changing the -semantics of the code is not desired, the ``NOLINT`` or ``NOLINTNEXTLINE`` -comments can be used instead. For example: +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, +e.g. `bugprone-use-after-move `_ can be +silenced by re-initializing the variable after it has been moved out, +`bugprone-string-integer-assignment +`_ can be suppressed by explicitly +casting the integer to ``char``, `readability-implicit-bool-conversion +`_ can also be suppressed by using +explicit casts, etc. + +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: .. code-block:: c++ class Foo { - // Silent all the diagnostics for the line + // Suppress all the diagnostics for the line Foo(int param); // NOLINT - // Silent only the specified checks for the line + // Consider explaining the motivation to suppress the warning. + Foo(char param); // NOLINT: Allow implicit conversion from `char`, because . + + // Silence only the specified checks for the line Foo(double param); // NOLINT(google-explicit-constructor, google-runtime-int) - // Silent only the specified diagnostics for the next line + // Silence only the specified diagnostics for the next line // NOLINTNEXTLINE(google-explicit-constructor, google-runtime-int) Foo(bool param); };