[clang] clang-format: Add IncludeSortKey option (PR #137840)

via cfe-commits cfe-commits at lists.llvm.org
Thu May 1 04:56:31 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp,h -- clang/include/clang/Format/Format.h clang/include/clang/Tooling/Inclusions/IncludeStyle.h clang/lib/Format/Format.cpp clang/lib/Tooling/Inclusions/IncludeStyle.cpp clang/unittests/Format/SortIncludesTest.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/include/clang/Tooling/Inclusions/IncludeStyle.h b/clang/include/clang/Tooling/Inclusions/IncludeStyle.h
index 8df8f54e7..6699a667c 100644
--- a/clang/include/clang/Tooling/Inclusions/IncludeStyle.h
+++ b/clang/include/clang/Tooling/Inclusions/IncludeStyle.h
@@ -170,7 +170,8 @@ struct IncludeStyle {
   enum IncludeSortKeyDiscriminator : int8_t {
     /// Includes are sorted alphabetically by their full path.
     ISK_Path,
-    /// Includes are sorted alphabetically by their full path without file extension.
+    /// Includes are sorted alphabetically by their full path without file
+    /// extension.
     ISK_Stem,
   };
 
@@ -209,9 +210,9 @@ struct ScalarEnumerationTraits<
 template <>
 struct ScalarEnumerationTraits<
     clang::tooling::IncludeStyle::IncludeSortKeyDiscriminator> {
-  static void enumeration(
-      IO &IO,
-      clang::tooling::IncludeStyle::IncludeSortKeyDiscriminator &Value);
+  static void
+  enumeration(IO &IO,
+              clang::tooling::IncludeStyle::IncludeSortKeyDiscriminator &Value);
 };
 
 } // namespace yaml
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 75e654a0a..fafd0432a 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3223,7 +3223,8 @@ static void sortCppIncludes(const FormatStyle &Style,
     stable_sort(Indices, [&](unsigned LHSI, unsigned RHSI) {
       SmallString<128> LHSStem = Includes[LHSI].Filename;
       SmallString<128> RHSStem = Includes[RHSI].Filename;
-      if (Style.IncludeStyle.IncludeSortKey == tooling::IncludeStyle::ISK_Stem) {
+      if (Style.IncludeStyle.IncludeSortKey ==
+          tooling::IncludeStyle::ISK_Stem) {
         llvm::sys::path::replace_extension(LHSStem, "");
         llvm::sys::path::replace_extension(RHSStem, "");
       }
@@ -3236,7 +3237,8 @@ static void sortCppIncludes(const FormatStyle &Style,
     stable_sort(Indices, [&](unsigned LHSI, unsigned RHSI) {
       SmallString<128> LHSStem = Includes[LHSI].Filename;
       SmallString<128> RHSStem = Includes[RHSI].Filename;
-      if (Style.IncludeStyle.IncludeSortKey == tooling::IncludeStyle::ISK_Stem) {
+      if (Style.IncludeStyle.IncludeSortKey ==
+          tooling::IncludeStyle::ISK_Stem) {
         llvm::sys::path::replace_extension(LHSStem, "");
         llvm::sys::path::replace_extension(RHSStem, "");
       }

``````````

</details>


https://github.com/llvm/llvm-project/pull/137840


More information about the cfe-commits mailing list