PiotrZSL created this revision. PiotrZSL added reviewers: njames93, carlosgalvezp. Herald added subscribers: mgrang, xazax.hun. Herald added a project: All. PiotrZSL requested review of this revision. Herald added a project: clang-tools-extra. Herald added a subscriber: cfe-commits.
Sort printed options in --dump-config output. Fixes: #64153 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D156452 Files: clang-tools-extra/clang-tidy/ClangTidyOptions.cpp clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp Index: clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp +++ 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 Index: clang-tools-extra/docs/ReleaseNotes.rst =================================================================== --- clang-tools-extra/docs/ReleaseNotes.rst +++ 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 ^^^^^^^^^^ Index: clang-tools-extra/clang-tidy/ClangTidyOptions.cpp =================================================================== --- clang-tools-extra/clang-tidy/ClangTidyOptions.cpp +++ 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 <algorithm> #include <optional> #include <utility> @@ -85,14 +86,20 @@ void yamlize(IO &IO, ClangTidyOptions::OptionMap &Options, bool, EmptyContext &Ctx) { if (IO.outputting()) { + std::vector<std::pair<StringRef, StringRef>> 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();
Index: clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp +++ 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 Index: clang-tools-extra/docs/ReleaseNotes.rst =================================================================== --- clang-tools-extra/docs/ReleaseNotes.rst +++ 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 ^^^^^^^^^^ Index: clang-tools-extra/clang-tidy/ClangTidyOptions.cpp =================================================================== --- clang-tools-extra/clang-tidy/ClangTidyOptions.cpp +++ 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 <algorithm> #include <optional> #include <utility> @@ -85,14 +86,20 @@ void yamlize(IO &IO, ClangTidyOptions::OptionMap &Options, bool, EmptyContext &Ctx) { if (IO.outputting()) { + std::vector<std::pair<StringRef, StringRef>> 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();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits