This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Validate clang-tidy Checks in clangd config.
ClosedPublic

Authored by njames93 on Dec 8 2020, 11:45 AM.

Details

Summary

Add instrumentation in ConfigCompile to validate that items in ClangTidy:[Add|Remove] correspond to actual clang-tidy checks.
If they don't a warning will be presented to the user.

This is especially useful for catching typos in the glob items.

Diff Detail

Event Timeline

njames93 created this revision.Dec 8 2020, 11:45 AM
njames93 requested review of this revision.Dec 8 2020, 11:45 AM
njames93 updated this revision to Diff 310352.Dec 8 2020, 2:38 PM

Made GlobList::specifies const.
Made check validation function static and only taking a StringRef. This will make it easier to refactor out at a later date if this functionality wants to be used elsewhere.

Thanks for doing this!
I wonder a simpler version would reach the 80/20 point... if we were to validate only that entries *without wildcards* matched a check name, I think we'd catch most of the typos, and it'd just be a simple set lookup.
(bugprone-* is quadratically less likely to have a typo than a list of checks, because it's shorter and also large globs just don't appear as many times)

clang-tools-extra/clangd/ConfigCompile.cpp
359

if you kept the ClangTidyCheckFactories alive forever, you can just use the StringRefs from its keys, right?

njames93 updated this revision to Diff 311094.Dec 10 2020, 7:22 PM

Dont check for globs coverage instead use a fast set based approach that only matches tidy checks exactly.

Thanks! Just some organization nits.

clang-tools-extra/clangd/ConfigCompile.cpp
26

This is a pretty weird place to depend on clang-tidy.
Can we move the "is this a clang-tidy check name" function to somewhere more clang-tidy related, like TidyProvider.h or even clang-tidy/ClangTidyModuleRegistry.h? ("isRegisteredCheck")

353

naming nits:

  • prefer positive over negative names
  • "glob" is confusing here as we don't actually handle globs
  • outside of the clang-tidy namespace, "check" needs a "tidy" qualifier

What about isTidyCheckName, and move the * test into the caller? Then the semantics of the function are really clear without having to read the body or comment.

363

message could be clearer - "clang-tidy check '{0}' was not found"

njames93 marked 2 inline comments as done.Dec 15 2020, 9:03 AM
njames93 added inline comments.
clang-tools-extra/clangd/ConfigCompile.cpp
26

Moving to ClangTidyModuleRegistry.h will still require this include.
Moving the function to TidyProvider.h may have a case, but as TidyProvider doesn't use the function I'm not sure it belongs in there.

njames93 updated this revision to Diff 311926.Dec 15 2020, 9:03 AM

Address some comments

sammccall added inline comments.Dec 15 2020, 9:16 AM
clang-tools-extra/clangd/ConfigCompile.cpp
26

Yeah, the include is unfortunate but I think it's an improvement over having the implementation details in the code.

TidyProvider.h - we could rename the header to Tidy.h if you think it's important - I can live with the naming discrepancy but think we should group clang-tidy-config related stuff.

51

nit: if this is in the clangd code, it should be in the clangd namespace (isRegisteredTidyCheck or so).

56

these asserts seem to violate principle-of-least-surprise - why can't isRegisteredCheck("-* ") just return false?

njames93 marked 4 inline comments as done.Dec 15 2020, 9:42 AM
njames93 added inline comments.
clang-tools-extra/clangd/ConfigCompile.cpp
26

That sounds like a refactor that shouldn't live in this patch.

56

The reason for this pre condition was because I wanted to assert that the first non whitespace item was not a -. But there are better ways around that.

njames93 updated this revision to Diff 311948.Dec 15 2020, 9:42 AM
njames93 marked 2 inline comments as done.

Address comments

sammccall accepted this revision.Dec 15 2020, 10:00 AM
This revision is now accepted and ready to land.Dec 15 2020, 10:00 AM
This revision was landed with ongoing or failed builds.Dec 15 2020, 1:11 PM
This revision was automatically updated to reflect the committed changes.