I'm working on a C++ project that has some large sections of code that are autogenerated, and I don't want to be linted. Is there something akin to the //NOLINT
comment that can be applied to multiple lines? Like the following:
// BEGINNOLINT
bad-code;
// ENDNOLINT
All I could find online was a suggestion that this should be implemented. Is there any way to avoid having to write // NOLINT
on the end of every single line?
clang-tidy 14 introduced this feature:
// NOLINTBEGIN
...
// NOLINTEND
Note, if you want to disable a specific warning, the end-comment must match the begin-comment:
// NOLINTBEGIN(check-name)
...
// NOLINTEND(check-name)
Unfortunately there is no direct way to do this, clang-tidy only supports //NOLINT
and //NOLINTNEXTLINE
.
I don't know how much control you have about that code generation...you could generate it in one line, that could help you a lot as c++ doesn't care about whitespace.
A crude but effective solution is to use a text-manipulation tool like sed:
$ sed -i -re '/^\/\/BEGIN_NOLINT/,/^\/\/END_NOLINT/{s/$/\/\/NOLINT/}' *.cpp
This would add //NOLINT
at the end of every line between //BEGIN_NOLINT
and //END_NOLINT
comments (which can be probably generated).
You can also run clang-tidy with parameter
-line-filter='[{"name":"test.cpp","lines":[[1,10],[12,100]]}]'
Line 11 will be skipped in this example. This is however difficult to maintain as you need to update the filter every time you add/remove lines in the file. Maybe it would be a good idea to generate code into separate files if possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With