diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp --- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp @@ -16,6 +16,7 @@ #include "llvm/Support/MemoryBufferRef.h" #include "llvm/Support/Path.h" #include "llvm/Support/YAMLTraits.h" +#include #include #include @@ -85,14 +86,20 @@ void yamlize(IO &IO, ClangTidyOptions::OptionMap &Options, bool, EmptyContext &Ctx) { if (IO.outputting()) { + std::vector> SortedOptions; + SortedOptions.reserve(Options.size()); + for (auto &Key : Options) { + SortedOptions.emplace_back(Key.getKey(), Key.getValue().Value); + } + std::sort(SortedOptions.begin(), SortedOptions.end()); + IO.beginMapping(); // Only output as a map - for (auto &Key : Options) { - bool UseDefault; - void *SaveInfo; - IO.preflightKey(Key.getKey().data(), true, false, UseDefault, SaveInfo); - StringRef S = Key.getValue().Value; - IO.scalarString(S, needsQuotes(S)); + for (auto &Option : SortedOptions) { + bool UseDefault = false; + void *SaveInfo = nullptr; + IO.preflightKey(Option.first.data(), true, false, UseDefault, SaveInfo); + IO.scalarString(Option.second, needsQuotes(Option.second)); IO.postflightKey(SaveInfo); } IO.endMapping(); diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -111,6 +111,8 @@ - Remove configuration option `AnalyzeTemporaryDestructors`, which was deprecated since :program:`clang-tidy` 16. +- Improved `--dump-config` to print check options in alphabetical order. + New checks ^^^^^^^^^^ diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp --- a/clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp +++ b/clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp @@ -54,3 +54,5 @@ // RUN: %S/Inputs/config-files/4/44/- -- | FileCheck %s -check-prefix=CHECK-CHILD6 // CHECK-CHILD6: Checks: {{.*-llvm-qualified-auto'? *$}} // CHECK-CHILD6-NOT: modernize-use-using.IgnoreMacros + +// RUN: clang-tidy --checks="-*,readability-identifier-*" --dump-config | grep readability-identifier-naming | sort -c