Skip to content

Commit 438058e

Browse files
author
git apple-llvm automerger
committed
Merge commit '0ed2945a5969' from llvm.org/main into next
2 parents 63f6dc3 + 0ed2945 commit 438058e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

clang/lib/Format/Format.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3547,7 +3547,8 @@ tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code,
35473547
return sortJavaScriptImports(Style, Code, Ranges, FileName);
35483548
if (Style.Language == FormatStyle::LanguageKind::LK_Java)
35493549
return sortJavaImports(Style, Code, Ranges, FileName, Replaces);
3550-
sortCppIncludes(Style, Code, Ranges, FileName, Replaces, Cursor);
3550+
if (Style.isCpp())
3551+
sortCppIncludes(Style, Code, Ranges, FileName, Replaces, Cursor);
35513552
return Replaces;
35523553
}
35533554

clang/unittests/Format/SortIncludesTest.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,15 @@ TEST_F(SortIncludesTest, DoNotSortLikelyXml) {
10851085
"input.h", 0));
10861086
}
10871087

1088+
TEST_F(SortIncludesTest, DoNotSortCSharp) {
1089+
constexpr StringRef Code{"const string expectedDataStruct = @\"\n"
1090+
" #include <b.h>\n"
1091+
" #include <a.h>\n"
1092+
" \";"};
1093+
FmtStyle.Language = FormatStyle::LK_CSharp;
1094+
EXPECT_TRUE(sortIncludes(FmtStyle, Code, GetCodeRange(Code), "a.cs").empty());
1095+
}
1096+
10881097
TEST_F(SortIncludesTest, DoNotOutputReplacementsForSortedBlocksWithRegrouping) {
10891098
Style.IncludeBlocks = Style.IBS_Regroup;
10901099
StringRef Code = "#include \"b.h\"\n"

0 commit comments

Comments
 (0)