14 Commits

Author SHA1 Message Date
Justin Cady
cc54129b98
Add option to exclude headers from clang-tidy analysis (#91400)
This is a renewed attempt to land @toddlipcon's D34654. The comments on
that patch indicate a broad desire for some ability to ignore headers.

After considering various options, including migrating to std::regex, I
believe this is the best path forward. It's intuitive to have separate
regexes for including headers versus excluding them, and this approach
has the added benefit of being completely opt-in. No existing configs
will break, regardless of existing HeaderFilterRegex values.

This functionality is useful for improving performance when analyzing a
targeted subset of code, as well as in cases where some collection of
headers cannot be modified (third party source, for example).
2024-05-14 08:48:04 -04:00
Hans Wennborg
9c8b0d4ef6 Use FileCheck in new clang-tidy/infrastructure/config-files.cpp tests
The test was failing spuriously on some machines [1]. Converting from
grep to FileCheck makes it easier to see what's happening, and also grep
is discouraged in tests [2].

Also drop the negative test: checking for the expected output is better.

 1. https://crbug.com/338535754
 2. https://llvm.org/docs/TestingGuide.html#:~:text=.%20%5BThe-,usage%20of%20grep,-in%20RUN%20lines
2024-05-03 15:09:58 +02:00
ealcdan
c52b18d1e4
[clang-tidy] Avoid overflow when dumping unsigned integer values (#85060)
Some options take the maximum unsigned integer value as default, but
they are being dumped to a string as integers. This makes -dump-config
write invalid '-1' values for these options. This change fixes this
issue by using utostr if the option is unsigned.

Fixes #60217
2024-04-23 13:03:09 +02:00
Felix
7a73da4c85 [clang-tidy] Add support for optional parameters in config.
If a parameter value is either 'none', 'null', 'false', '-1'
or '', we will in that case use the default value.

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D159436
2023-10-09 19:58:44 +00:00
Piotr Zegar
3d9a64f7d4 [clang-tidy] Sort options in --dump-config
Sort printed options in --dump-config output.

Fixes: #64153

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D156452
2023-07-27 20:07:52 +00:00
Piotr Zegar
a8eb7415a4 Revert "[clang-tidy] Sort options in --dump-config"
This reverts commit 2cdb843767529b2be641b93e43d70837900345c1.
2023-07-27 19:27:25 +00:00
Piotr Zegar
2cdb843767 [clang-tidy] Sort options in --dump-config
Sort printed options in --dump-config output.

Fixes: #64153

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D156452
2023-07-27 17:50:59 +00:00
Nathan James
fbf611ed2a
[clang-tidy] Extend spelling for CheckOptions
The current way to specify CheckOptions is pretty verbose and unintuitive.
Given that the options are a dictionary it makes much more sense to treat them as such in the config files.
Example:
```
CheckOptions: {SomeCheck.Option: true, SomeCheck.OtherOption: 'ignore'}
# Or
CheckOptions:
  SomeCheck.Option: true
  SomeCheck.OtherOption: 'ignore'
```

This change will still handle the old syntax with no issue, ensuring we don't screw up users current config files.

The only observable differences are support for the new syntax and `-dump=config` will emit using the new syntax.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D128337
2022-06-23 19:59:31 +01:00
Nathan James
45a720a864
[clang-tidy] Use StringMap for ClangTidyOptions::OptionsMap
Ordering of options isn't important so an `llvm::StringMap` is a much better container for this purpose.

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D84868
2020-07-30 10:31:13 +01:00
Nathan James
fcf0f75a59
[clang-tidy] OptionsView::store specialized on bool
Following on fcf7cc268fe and 672207c319a which granted checks the ability to read boolean configuration arguments as `true` or `false`.
This enables storing the options back to the configuration file using `true` and `false`.
This is in line with how clang-format dumps boolean options in its style config.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D83053
2020-07-14 22:19:37 +01:00
Nathan James
4836188ad9
[clang-tidy] Extend InheritParentConfig to CommandLineConfig
Extend the `InheritParentConfig` support introduced in D75184 for the command line option `--config`.
The current behaviour of `--config` is to when set, disable looking for `.clang-tidy` configuration files.
This new behaviour lets you set `InheritParentConfig` to true in the command line to then look for `.clang-tidy` configuration files to be merged with what's been specified on the command line.

Reviewed By: DmitryPolukhin

Differential Revision: https://reviews.llvm.org/D81949
2020-06-19 12:02:19 +01:00
Nico Weber
99e4061bd8 Try to fix clang-tidy/infrastructure/config-files.cpp on Win after cb1ee34e9d32fc.
See also r267736.
2020-04-15 13:38:03 -04:00
Dmitry Polukhin
cb1ee34e9d [clang-tidy] Optional inheritance of file configs from parent directories
Summary:
Without this patch clang-tidy stops finding file configs on the nearest
.clang-tidy file. In some cases it is not very convenient because it
results in common parts duplication into every child .clang-tidy file.
This diff adds optional config inheritance from the parent directories
config files.

Test Plan:

Added test cases in existing config test.

Reviewers: alexfh, gribozavr2, klimek, hokein

Subscribers: njames93, arphaman, xazax.hun, aheejin, cfe-commits

Tags: #clang, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D75184
2020-04-15 06:41:31 -07:00
Dmitri Gribenko
885c559369 [ClangTidy] Separate tests for infrastructure and checkers
Summary:
This change moves tests for checkers and infrastructure into separate
directories, making it easier to find infrastructure tests. Tests for
checkers are already easy to find because they are named after the
checker. Tests for infrastructure were difficult to find because they
were outnumbered by tests for checkers. Now they are in a separate
directory.

Reviewers: jfb, jdoerfert, lebedev.ri

Subscribers: srhines, nemanjai, aheejin, kbarton, christof, mgrang, arphaman, jfb, lebedev.ri, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D68807

llvm-svn: 374540
2019-10-11 12:05:42 +00:00