HomePhabricator

Add support for `NOLINTBEGIN` ... `NOLINTEND` comments

Authored by salman-javed-nz on Sep 28 2021, 4:52 AM.

Description

Add support for NOLINTBEGIN ... NOLINTEND comments

Add support for NOLINTBEGIN ... NOLINTEND comments to suppress
clang-tidy warnings over multiple lines. All lines between the "begin"
and "end" markers are suppressed.

Example:

NOLINTBEGIN(some-check)
<Code with warnings to be suppressed, line 1>
<Code with warnings to be suppressed, line 2>
<Code with warnings to be suppressed, line 3>
NOLINTEND(some-check)
Follows similar syntax as the NOLINT and NOLINTNEXTLINE comments
that are already implemented, i.e. allows multiple checks to be provided
in parentheses; suppresses all checks if the parentheses are omitted,
etc.

If the comments are misused, e.g. using a NOLINTBEGIN but not
terminating it with a NOLINTEND, a clang-tidy-nolint diagnostic
message pointing to the misuse is generated.

As part of implementing this feature, the following bugs were fixed in
existing code:

IsNOLINTFound(): IsNOLINTFound("NOLINT", Str) returns true when Str is
"NOLINTNEXTLINE". This is because the textual search finds NOLINT as
the stem of NOLINTNEXTLINE.

LineIsMarkedWithNOLINT(): NOLINTNEXTLINEs on the very first line of a
file are ignored. This is due to rsplit('\n\').second returning a blank
string when there are no more newline chars to split on.

Event Timeline

saghir added a subscriber: saghir.Sep 28 2021, 9:34 AM

Hi,
One of the tests added in this change is failing on PowerPC buildbots. One such bot is https://lab.llvm.org/buildbot/#/builders/121/builds/11903. Please revert and let us know how we can help you figure out what needs to be done to investigate/fix this on the PPC bots.
Thanks!

Hi,
One of the tests added in this change is failing on PowerPC buildbots. One such bot is https://lab.llvm.org/buildbot/#/builders/121/builds/11903. Please revert and let us know how we can help you figure out what needs to be done to investigate/fix this on the PPC bots.
Thanks!

Hi @saghir.

Commit has been reverted for now. I think I have a solution for the failing test - see https://reviews.llvm.org/differential/diff/375685/. Failure seems to be due to clang-tidy's diagnostic messages on the PowerPC build appearing in a different order to what I expected. Please let me know if you see any problems with my proposed fix.

Thanks