Skip to content

Commit 2cdb843

Browse files
committed
[clang-tidy] Sort options in --dump-config
Sort printed options in --dump-config output. Fixes: #64153 Reviewed By: carlosgalvezp Differential Revision: https://reviews.llvm.org/D156452
1 parent 4b9eed9 commit 2cdb843

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

clang-tools-extra/clang-tidy/ClangTidyOptions.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/Support/MemoryBufferRef.h"
1717
#include "llvm/Support/Path.h"
1818
#include "llvm/Support/YAMLTraits.h"
19+
#include <algorithm>
1920
#include <optional>
2021
#include <utility>
2122

@@ -85,14 +86,21 @@ template <>
8586
void yamlize(IO &IO, ClangTidyOptions::OptionMap &Options, bool,
8687
EmptyContext &Ctx) {
8788
if (IO.outputting()) {
89+
// Ensure check options are sorted
90+
std::vector<std::pair<StringRef, StringRef>> SortedOptions;
91+
SortedOptions.reserve(Options.size());
92+
for (auto &Key : Options) {
93+
SortedOptions.emplace_back(Key.getKey(), Key.getValue().Value);
94+
}
95+
std::sort(SortedOptions.begin(), SortedOptions.end());
96+
8897
IO.beginMapping();
8998
// Only output as a map
90-
for (auto &Key : Options) {
91-
bool UseDefault;
92-
void *SaveInfo;
93-
IO.preflightKey(Key.getKey().data(), true, false, UseDefault, SaveInfo);
94-
StringRef S = Key.getValue().Value;
95-
IO.scalarString(S, needsQuotes(S));
99+
for (auto &Option : SortedOptions) {
100+
bool UseDefault = false;
101+
void *SaveInfo = nullptr;
102+
IO.preflightKey(Option.first.data(), true, false, UseDefault, SaveInfo);
103+
IO.scalarString(Option.second, needsQuotes(Option.second));
96104
IO.postflightKey(SaveInfo);
97105
}
98106
IO.endMapping();

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ Improvements to clang-tidy
111111
- Remove configuration option `AnalyzeTemporaryDestructors`, which was deprecated since
112112
:program:`clang-tidy` 16.
113113

114+
- Improved `--dump-config` to print check options in alphabetical order.
115+
114116
New checks
115117
^^^^^^^^^^
116118

clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@
5454
// RUN: %S/Inputs/config-files/4/44/- -- | FileCheck %s -check-prefix=CHECK-CHILD6
5555
// CHECK-CHILD6: Checks: {{.*-llvm-qualified-auto'? *$}}
5656
// CHECK-CHILD6-NOT: modernize-use-using.IgnoreMacros
57+
58+
// Validate that check options are printed in alphabetical order:
59+
// RUN: clang-tidy --checks="-*,readability-identifier-*" --dump-config | grep readability-identifier-naming | sort --check

0 commit comments

Comments
 (0)