Exclude specific headers from clang-tidy

大兔子大兔子 提交于 2020-01-04 02:04:27

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/56124739/exclude-specific-headers-from-clang-tidy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!