[PATCH] D108560: [clang-tidy] Add support for NOLINTBEGIN ... NOLINTEND comments to suppress clang-tidy warnings over multiple lines

Salman Javed via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Sep 18 08:13:33 PDT 2021


salman-javed-nz updated this revision to Diff 373416.
salman-javed-nz marked 2 inline comments as done.
salman-javed-nz added a comment.

`shouldSuppressDiagnostic()`:

- Changed to take a container of diagnostics as an argument. If it finds any stray `NOLINTBEGIN`/`NOLINTEND` markers, it creates a diagnostic regarding the stray marker and places it in the container.

`HandleDiagnostic()`:

- Emits any diagnostics returned by `shouldSuppressDiagnostic()`.

New unit tests:

- `test\clang-tidy\infrastructure\nolintbeginend-begin-without-end.cpp`
- `test\clang-tidy\infrastructure\nolintbeginend-end-without-begin.cpp`.
- `test\clang-tidy\infrastructure\nolintbeginend-mismatched-delims.cpp`.

`IsNOLINTFound()`:

- Bug fix. `IsNOLINTFound("NOLINT", Str)` returns true when `Str` is `"NOLINTNEXTLINE"`. This is because the text search finds `"NOLINT"` as a substring of `"NOLINTNEXTLINE"`.
- Added test case in `test\clang-tidy\infrastructure\nolint.cpp`.

`LineIsMarkedWithNOLINT()`:

- Bug fix. `NOLINTNEXTLINE`s 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.
- Added test case in `test\clang-tidy\infrastructure\nolintnextline.cpp`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108560/new/

https://reviews.llvm.org/D108560

Files:
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/index.rst
  clang-tools-extra/test/clang-tidy/infrastructure/Inputs/nolintbeginend/error_in_include.inc
  clang-tools-extra/test/clang-tidy/infrastructure/Inputs/nolintbeginend/nolint_in_include.inc
  clang-tools-extra/test/clang-tidy/infrastructure/nolint.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-without-end.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-end-without-begin.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-delims.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/nolintnextline.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108560.373416.patch
Type: text/x-patch
Size: 27677 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210918/303647a5/attachment-0001.bin>


More information about the cfe-commits mailing list