[PATCH] D101628: [Format] Don't sort includes if DisableFormat is true
Nathan James via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 4 11:04:34 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rG61dc0f2b593d: [Format] Don't sort includes if DisableFormat is true (authored by njames93).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D101628/new/
https://reviews.llvm.org/D101628
Files:
clang/lib/Format/Format.cpp
clang/unittests/Format/SortIncludesTest.cpp
Index: clang/unittests/Format/SortIncludesTest.cpp
===================================================================
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -9,6 +9,7 @@
#include "FormatTestUtils.h"
#include "clang/Format/Format.h"
#include "llvm/ADT/None.h"
+#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Debug.h"
#include "gtest/gtest.h"
@@ -1034,6 +1035,16 @@
EXPECT_EQ(Expected, sort(Code, "a.cpp", 1));
}
+TEST_F(SortIncludesTest, DisableFormatDisablesIncludeSorting) {
+ StringRef Sorted = "#include <a.h>\n"
+ "#include <b.h>\n";
+ StringRef Unsorted = "#include <b.h>\n"
+ "#include <a.h>\n";
+ EXPECT_EQ(Sorted, sort(Unsorted));
+ FmtStyle.DisableFormat = true;
+ EXPECT_EQ(Unsorted, sort(Unsorted, "input.cpp", 0));
+}
+
} // end namespace
} // end namespace format
} // end namespace clang
Index: clang/lib/Format/Format.cpp
===================================================================
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2605,7 +2605,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: D101628.342804.patch
Type: text/x-patch
Size: 1452 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210504/8c7d7b9b/attachment.bin>
More information about the cfe-commits
mailing list