13

I have several projects with many headers that I want to parse, but there are several headers which I do not want to parse with clang-tidy

My folder hierarchy is as follows

A\
|
|-B\
| |
| |-C\
| | |
| | └-coco.h
| └-D\
└-E\

My projects are inside C and D folders and I want them to parse all headers under B so my solution was HeaderFilterRegex: 'B/*' There are many headers that i want to include so I can't name each one.

however inside C and D folders there are several headers which I would like to exclude (for example coco.h).

I tried putting NO_LINT in the cpp that includes coco.h and that didn't help,

How Can I do this?

Thanks

Quimby
  • 17,735
  • 4
  • 35
  • 55
S BI
  • 351
  • 1
  • 2
  • 12

3 Answers3

5

I found a workaround that fits my purpose (I have a limited list of files that I want to filter out and they have unique names)

I use the line-filter and add all the files that i want to filter out. In the line range I put a line that doesn't exist, this way it filters the file out. In the end of the line filter I add .h and .cpp so it will filter in the rest of the files.

E.g.lets say i want to filter out only coco.cpp

-line-filter=[{"name":"coco.cpp","lines":[[9999999,9999999]]},{"name":".h"},{"name":".cpp"}]

One thing to note, and why i thought it didn't work is the following: the line-filter only works after it does the analysis and header-filter only works on includes.

In coco.cpp I had a line (call to template) which caused a warning but the warning showed on a header which was supposed to be filtered out by header-filter.

It wasn't filtered out because the warning was due to the cpp but the actual warning showed on the header so the line-filter didn't help until I put this specific header in line-filter as well.

Not very intuitive.

pablo285
  • 2,460
  • 4
  • 14
  • 38
S BI
  • 351
  • 1
  • 2
  • 12
1

It's possible (although admittedly clumsy) to use the header-filter option for this.

If you rename the files you don't want processed to have a different suffix than the other header files (let's say .h_nolint instead of .h) you can then use the header filter to match only *.h files like this:

 -header-filter=\.h$

(clang-tidy uses POSIX ERE)

Of course this comes at a cost of having to rename all the respective header references in the code in addition to renaming the files but a decent IDE should be able to handle it.

pablo285
  • 2,460
  • 4
  • 14
  • 38
0

From the name of the option, it seems that you need to enter a regex , in which case your syntax has an error. Maybe

HeaderFilterRegex: 'B/' is all you need, or maybe HeaderFilterRegex: B/.*\.hpp$' if you want to be really specific about filtering out ONLY hpp files

Dharman
  • 30,962
  • 25
  • 85
  • 135
mystery_doctor
  • 404
  • 2
  • 11