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;
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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits