7

I have the following directory structure

├── .clang-format

├── .clang-tidy

├── external

├── scripts

└── source

For my clang tidy execution I want to only include headers from the source folder and exclude ones from external. The following setting does not work for either match HeaderFilterRegex: '^(source)+(?!.*external).*' The format of the regex is correct

In the .clang-tidy file If I only include HeaderFilterRegex: '^(?!.*external).*' it excludes the external folder but doesn't include the source header files

and similarly if I only include this check HeaderFilterRegex: '(src/)' it doesn't exclude the external files.

Update

Ok this seems like it is related to the fact clang uses Posix ERE regex flavor (thanks @pablo285) and this does not support negative lookahead. I would have thought this was a fairly standard requirement for using clang-tidy, excluding certain folders from the analysis.

user2020
  • 217
  • 2
  • 12
  • You are using wrong regex flavour - you linked to PCRE but clang uses Posix ERE. – pablo285 Jun 18 '21 at 09:26
  • @pablo285 Oh I was not even aware of that, what specifically is the difference – user2020 Jun 18 '21 at 09:45
  • @pablo285 Is it even possible to do negative lookaheads using Posix – user2020 Jun 18 '21 at 10:10
  • I'm not an expert on regex unfortunately, I just happen to know this since I had a similar problem in the past. Try to post a question in `regex` tag. – pablo285 Jun 22 '21 at 14:55
  • See the Q&A at https://stackoverflow.com/a/75586089/1743580 for a workaround. – miguno Feb 28 '23 at 15:31
  • Does this answer your question? [clang-tidy: Exclude specific dir from analysis](https://stackoverflow.com/questions/74349432/clang-tidy-exclude-specific-dir-from-analysis) – miguno Feb 28 '23 at 15:31

0 Answers0