[PATCH] D156452: [clang-tidy] Sort options in --dump-config

Piotr Zegar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 27 10:38:32 PDT 2023


PiotrZSL updated this revision to Diff 544852.
PiotrZSL marked an inline comment as done.
PiotrZSL added a comment.

Review comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156452/new/

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,6 @@
 // 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
+
+// Validate that check options are printed in alphabetical order:
+// RUN: clang-tidy --checks="-*,readability-identifier-*" --dump-config | grep readability-identifier-naming | sort --check
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,21 @@
 void yamlize(IO &IO, ClangTidyOptions::OptionMap &Options, bool,
              EmptyContext &Ctx) {
   if (IO.outputting()) {
+    // Ensure check options are sorted
+    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();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156452.544852.patch
Type: text/x-patch
Size: 2650 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230727/254a3320/attachment-0001.bin>


More information about the cfe-commits mailing list