[PATCH] D67843: DisableFormat also now disables SortIncludes

Sam Maier via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 20 10:41:22 PDT 2019


SamMaier created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
SamMaier added a reviewer: thakis.

Previously, in order to have clang-format //not// format something, you had to give both:

  SortIncludes: false
  DisableFormat: true

This is confusing to users, who would expect that DisableFormat does what it says, and prevents clang-format from editing any files it applies to. See https://stackoverflow.com/questions/55833838/clang-format-still-formatting-with-disableformat-true for example.


Repository:
  rC Clang

https://reviews.llvm.org/D67843

Files:
  clang/lib/Format/Format.cpp
  clang/test/Format/disable-format.cpp


Index: clang/test/Format/disable-format.cpp
===================================================================
--- clang/test/Format/disable-format.cpp
+++ clang/test/Format/disable-format.cpp
@@ -1,5 +1,9 @@
 // RUN: grep -Ev "// *[A-Z-]+:" %s | clang-format -style=none \
 // RUN:   | FileCheck -strict-whitespace %s

-// CHECK: int   i;
+// CHECK: #include <b>
+// CHECK-NEXT: #include <a>
+// CHECK-NEXT: int   i;
+#include <b>
+#include <a>
 int   i;
Index: clang/lib/Format/Format.cpp
===================================================================
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1062,8 +1062,6 @@
 FormatStyle getNoStyle() {
   FormatStyle NoStyle = getLLVMStyle();
   NoStyle.DisableFormat = true;
-  NoStyle.SortIncludes = false;
-  NoStyle.SortUsingDeclarations = false;
   return NoStyle;
 }

@@ -2130,7 +2128,7 @@
                                    ArrayRef<tooling::Range> Ranges,
                                    StringRef FileName, unsigned *Cursor) {
   tooling::Replacements Replaces;
-  if (!Style.SortIncludes)
+  if (!Style.SortIncludes || Style.DisableFormat)
     return Replaces;
   if (isLikelyXml(Code))
     return Replaces;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67843.221059.patch
Type: text/x-patch
Size: 1197 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190920/c1d337a0/attachment.bin>


More information about the cfe-commits mailing list