-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[clang-tidy] use local config #120004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang-tidy] use local config #120004
Conversation
follow up patch for llvm#119948.
@llvm/pr-subscribers-clang-tidy @llvm/pr-subscribers-clang-tools-extra Author: Congcong Cai (HerrCai0907) Changesfollow up patch for #119948. Full diff: https://github.com/llvm/llvm-project/pull/120004.diff 11 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
index 5e7a0e65690b7a..7638bbc103d16d 100644
--- a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
@@ -57,10 +57,9 @@ struct MissingIncludeInfo {
IncludeCleanerCheck::IncludeCleanerCheck(StringRef Name,
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
- IgnoreHeaders(utils::options::parseStringList(
- Options.getLocalOrGlobal("IgnoreHeaders", ""))),
- DeduplicateFindings(
- Options.getLocalOrGlobal("DeduplicateFindings", true)) {
+ IgnoreHeaders(
+ utils::options::parseStringList(Options.get("IgnoreHeaders", ""))),
+ DeduplicateFindings(Options.get("DeduplicateFindings", true)) {
for (const auto &Header : IgnoreHeaders) {
if (!llvm::Regex{Header}.isValid())
configurationDiag("Invalid ignore headers regex '%0'") << Header;
diff --git a/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.h b/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.h
index 1c526577b403f6..0c5ead860c161a 100644
--- a/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.h
@@ -26,7 +26,7 @@ class InconsistentDeclarationParameterNameCheck : public ClangTidyCheck {
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)),
- Strict(Options.getLocalOrGlobal("Strict", false)) {}
+ Strict(Options.get("Strict", false)) {}
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 6803842106791b..9e588913675039 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -115,6 +115,10 @@ Improvements to clang-tidy
- Improved :program:`run-clang-tidy.py` script. Fixed minor shutdown noise
happening on certain platforms when interrupting the script.
+- Removed :program:`clang-tidy`'s global options for most of checks. All options
+ are changed to local options except `IncludeStyle`, `StrictMode` and
+ `IgnoreMacros`.
+
New checks
^^^^^^^^^^
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-strict.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-strict.cpp
index c25d25ac5738fb..38d91f39846478 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-strict.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment-strict.cpp
@@ -1,5 +1,5 @@
// RUN: %check_clang_tidy %s bugprone-argument-comment %t -- \
-// RUN: -config="{CheckOptions: {StrictMode: true}}" --
+// RUN: -config="{CheckOptions: {bugprone-argument-comment.StrictMode: true}}" --
void f(int _with_underscores_);
void g(int x_);
diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-const-cast.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-const-cast.cpp
index be70e3ba356991..a775334260e35c 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-const-cast.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-const-cast.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -check-suffix=STRICT %s cppcoreguidelines-pro-type-const-cast %t -- -config="{CheckOptions: {StrictMode: true}}"
+// RUN: %check_clang_tidy -check-suffix=STRICT %s cppcoreguidelines-pro-type-const-cast %t -- -config="{CheckOptions: {cppcoreguidelines-pro-type-const-cast.StrictMode: true}}"
// RUN: %check_clang_tidy -check-suffix=NSTRICT %s cppcoreguidelines-pro-type-const-cast %t
namespace Const {
diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-static-cast-downcast.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-static-cast-downcast.cpp
index 11179b7d2d19b8..a3c73a960974ba 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-static-cast-downcast.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-static-cast-downcast.cpp
@@ -1,5 +1,5 @@
// RUN: %check_clang_tidy -check-suffixes=NSTRICT,STRICT %s cppcoreguidelines-pro-type-static-cast-downcast %t
-// RUN: %check_clang_tidy -check-suffix=NSTRICT %s cppcoreguidelines-pro-type-static-cast-downcast %t -- -config="{CheckOptions: {StrictMode: false}}"
+// RUN: %check_clang_tidy -check-suffix=NSTRICT %s cppcoreguidelines-pro-type-static-cast-downcast %t -- -config="{CheckOptions: {cppcoreguidelines-pro-type-static-cast-downcast.StrictMode: false}}"
class Base {
};
diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-parameters-strict.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-parameters-strict.cpp
index f8385c1a17e7bb..319cefa1c68f10 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-parameters-strict.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-parameters-strict.cpp
@@ -1,5 +1,5 @@
// RUN: %check_clang_tidy %s misc-unused-parameters %t -- \
-// RUN: -config="{CheckOptions: {StrictMode: true}}" --
+// RUN: -config="{CheckOptions: {misc-unused-parameters.StrictMode: true}}" --
// Warn on empty function bodies in StrictMode.
namespace strict_mode {
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp
index 42fb3382e4a936..0a5a63eba2596a 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp
@@ -1,12 +1,12 @@
// RUN: %check_clang_tidy \
// RUN: -std=c++20 %s modernize-use-std-format %t -- \
-// RUN: -config="{CheckOptions: {StrictMode: true}}" \
+// RUN: -config="{CheckOptions: {modernize-use-std-format.StrictMode: true}}" \
// RUN: -- -isystem %clang_tidy_headers \
// RUN: -DPRI_CMDLINE_MACRO="\"s\"" \
// RUN: -D__PRI_CMDLINE_MACRO="\"s\""
// RUN: %check_clang_tidy \
// RUN: -std=c++20 %s modernize-use-std-format %t -- \
-// RUN: -config="{CheckOptions: {StrictMode: false}}" \
+// RUN: -config="{CheckOptions: {modernize-use-std-format.StrictMode: false}}" \
// RUN: -- -isystem %clang_tidy_headers \
// RUN: -DPRI_CMDLINE_MACRO="\"s\"" \
// RUN: -D__PRI_CMDLINE_MACRO="\"s\""
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-absl.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-absl.cpp
index 95c32837e4447b..83fbd2e7500c5b 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-absl.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-absl.cpp
@@ -1,10 +1,10 @@
// RUN: %check_clang_tidy \
// RUN: -std=c++23 %s modernize-use-std-print %t -- \
-// RUN: -config="{CheckOptions: {StrictMode: true}}" \
+// RUN: -config="{CheckOptions: {modernize-use-std-print.StrictMode: true}}" \
// RUN: -- -isystem %clang_tidy_headers
// RUN: %check_clang_tidy \
// RUN: -std=c++23 %s modernize-use-std-print %t -- \
-// RUN: -config="{CheckOptions: {StrictMode: false}}" \
+// RUN: -config="{CheckOptions: {modernize-use-std-print.StrictMode: false}}" \
// RUN: -- -isystem %clang_tidy_headers
#include <cstdio>
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp
index f11fc408fcb9c8..5da995d9d6e830 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp
@@ -1,12 +1,12 @@
// RUN: %check_clang_tidy -check-suffixes=,STRICT \
// RUN: -std=c++23 %s modernize-use-std-print %t -- \
-// RUN: -config="{CheckOptions: {StrictMode: true}}" \
+// RUN: -config="{CheckOptions: {modernize-use-std-print.StrictMode: true}}" \
// RUN: -- -isystem %clang_tidy_headers -fexceptions \
// RUN: -DPRI_CMDLINE_MACRO="\"s\"" \
// RUN: -D__PRI_CMDLINE_MACRO="\"s\""
// RUN: %check_clang_tidy -check-suffixes=,NOTSTRICT \
// RUN: -std=c++23 %s modernize-use-std-print %t -- \
-// RUN: -config="{CheckOptions: {StrictMode: false}}" \
+// RUN: -config="{CheckOptions: {modernize-use-std-print.StrictMode: false}}" \
// RUN: -- -isystem %clang_tidy_headers -fexceptions \
// RUN: -DPRI_CMDLINE_MACRO="\"s\"" \
// RUN: -D__PRI_CMDLINE_MACRO="\"s\""
diff --git a/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp b/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
index d400cf6fe2d576..3d6ec995e443d4 100644
--- a/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
+++ b/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
@@ -71,10 +71,12 @@ TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
std::vector<ClangTidyError> Errors;
ClangTidyOptions Opts;
- Opts.CheckOptions["IgnoreHeaders"] = llvm::StringRef{llvm::formatv(
- "bar.h;{0};{1};vector;<list>;",
- llvm::Regex::escape(appendPathFileSystemIndependent({"foo", "qux.h"})),
- llvm::Regex::escape(appendPathFileSystemIndependent({"baz", "qux"})))};
+ Opts.CheckOptions["test-check-0.IgnoreHeaders"] = llvm::StringRef{
+ llvm::formatv("bar.h;{0};{1};vector;<list>;",
+ llvm::Regex::escape(
+ appendPathFileSystemIndependent({"foo", "qux.h"})),
+ llvm::Regex::escape(
+ appendPathFileSystemIndependent({"baz", "qux"})))};
EXPECT_EQ(
PostCode,
runCheckOnCode<IncludeCleanerCheck>(
@@ -139,7 +141,7 @@ int BarResult2 = $diag2^bar();)");
{
std::vector<ClangTidyError> Errors;
ClangTidyOptions Opts;
- Opts.CheckOptions.insert({"DeduplicateFindings", "false"});
+ Opts.CheckOptions["test-check-0.DeduplicateFindings"] = "false";
runCheckOnCode<IncludeCleanerCheck>(Code.code(), &Errors, "file.cpp", {},
Opts,
{{"baz.h", R"(#pragma once
@@ -170,7 +172,7 @@ std::vector x;
)";
ClangTidyOptions Opts;
- Opts.CheckOptions["IgnoreHeaders"] = llvm::StringRef{
+ Opts.CheckOptions["test-check-0.IgnoreHeaders"] = llvm::StringRef{
"public.h;<vector>;baz.h;" +
llvm::Regex::escape(appendPathFileSystemIndependent({"foo", "qux.h"}))};
std::vector<ClangTidyError> Errors;
|
clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.h
Show resolved
Hide resolved
@@ -115,6 +115,10 @@ Improvements to clang-tidy | |||
- Improved :program:`run-clang-tidy.py` script. Fixed minor shutdown noise | |||
happening on certain platforms when interrupting the script. | |||
|
|||
- Removed :program:`clang-tidy`'s global options for most of checks. All options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically we are explicit about which options and which checks have been affected. It's rather verbose and painful, but currently this release note doesn't really tell much to the users.
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-const-cast.cpp
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM except the release notes, I think it would be more helpful to the users if we listed the changes explicitly.
1098c99
to
be5732f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
follow up patch for #119948.