This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Add `-verify-config` command line argument
ClosedPublic

Authored by njames93 on Jun 9 2022, 2:49 PM.

Details

Summary

Adds a -verify-config command line argument, that when specified will verify the Checks and CheckOptions fields in the config files:

  • A warning will be raised for any check that doesn't correspond to a registered check, a suggestion will also be emitted for close misses.
  • A warning will be raised for any check glob(containing *) that doesn't match any registered check.
  • A warning will be raised for any CheckOption that isn't read by any registered check, a suggestion will also be emitted for close misses.

This can be useful if debuging why a certain check isn't enabled, or the options are being handled as you expect them to be.

Diff Detail

Event Timeline

njames93 created this revision.Jun 9 2022, 2:49 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 9 2022, 2:49 PM
njames93 requested review of this revision.Jun 9 2022, 2:49 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 9 2022, 2:49 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

This sounds like great functionality, surely saving a lot of headaches! Any reason why we wouldn't want this active by default? I'd personally even go one step further and make it hard errors - warnings are easy to miss and ignore - but I can see how it can be problematic for some people.

This sounds like great functionality, surely saving a lot of headaches! Any reason why we wouldn't want this active by default? I'd personally even go one step further and make it hard errors - warnings are easy to miss and ignore - but I can see how it can be problematic for some people.

I choose not to as I'd imagine it could would result in duplicated warnings when batch processing using run_clang_tidy over a large project.
Also if there's any edge cases, maybe with the static analyser, I wouldn't want those diagnostics triggering by default with no way to silence them.
I wouldn't be opposed to the possibility of making on by default after its had some time in the wild.

njames93 edited the summary of this revision. (Show Details)Jun 18 2022, 7:03 AM

Thanks for this, it seems like an interesting feature!

clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
263
436

Building check glob instead?

450

Unknown check instead?

575

Unknown check option instead?

clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
13

It's unfortunate that warning: appears in the middle of the diagnostic as opposed to at the start. I wonder if this can be reworked to say: warning: Unknown check 'whatever'; did you mean 'whatever'? [-verify-config] or something?

Also, no test coverage for the error case and for the unknown check case where there's no closest match worth talking about.

njames93 marked 4 inline comments as done.Jun 22 2022, 2:46 AM
njames93 added inline comments.
clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
263

:)

clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
13

Warning appearing in the middle is kind of by design as when clang emits diagnostics, the source location is the first thing emitted, then the type(warning|error). In this case command-line option '-config' is the "source location"

Also, no test coverage for the error case.

I'm not 100% on that, there is no checking when the check glob is actually built and I haven't figured out how to break it.

njames93 updated this revision to Diff 438953.Jun 22 2022, 2:46 AM
njames93 marked an inline comment as done.

Address reviewer comments.

aaron.ballman added inline comments.Jun 22 2022, 4:05 AM
clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
13

then the type(warning|error). In this case command-line option '-config' is the "source location"

Ah, thanks for explaining your logic. FWIW, Clang uses a different style for that (<command line>): https://godbolt.org/z/f1rdsbjqe Perhaps we should follow suit? (In fact, we could use the diagnostic engine for this instead of emitting to the error stream ourselves?)

njames93 added inline comments.Jun 22 2022, 5:11 AM
clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
13

The issue is, we don't have the actual source information right now to print better error messages.

aaron.ballman accepted this revision.Jun 22 2022, 6:00 AM

LGTM!

clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
13

After some off-list discussion (thanks @njames93!) I'm retracting my concerns here for the moment because there are larger issues with the diagnostics engine to be solved first.

This revision is now accepted and ready to land.Jun 22 2022, 6:00 AM

Before this lands @sammccall @kadircet Do you have any concerns about this API for getting the options not building a static instance here?

This revision was automatically updated to reflect the committed changes.