[PATCH] D81467: [clang-format] Microsoft style fixes for C# properties
Jonathan B Coe via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 9 06:33:16 PDT 2020
jbcoe created this revision.
jbcoe added reviewers: krasimir, MyDeveloperDay.
jbcoe added a project: clang-format.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
krasimir accepted this revision.
krasimir added a comment.
This revision is now accepted and ready to land.
Thank you!
There should be no line break before the opening brace for Microsoft style property accessors when the accessor is a simple `{ get; set }`.
https://docs.microsoft.com/en-us/dotnet/csharp/properties
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D81467
Files:
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTestCSharp.cpp
Index: clang/unittests/Format/FormatTestCSharp.cpp
===================================================================
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -245,13 +245,11 @@
"}");
verifyFormat("[TestMethod]\n"
- "public string Host\n"
- "{ set; get; }");
+ "public string Host { set; get; }");
verifyFormat("[TestMethod(\"start\", HelpText = \"Starts the server "
"listening on provided host\")]\n"
- "public string Host\n"
- "{ set; get; }");
+ "public string Host { set; get; }");
verifyFormat(
"[DllImport(\"Hello\", EntryPoint = \"hello_world\")]\n"
@@ -710,13 +708,6 @@
Style.BreakBeforeBraces = FormatStyle::BS_Custom;
Style.BraceWrapping.AfterFunction = true;
- verifyFormat(R"(//
-public class SaleItem {
- public decimal Price
- { get; set; }
-})",
- Style);
-
verifyFormat(R"(//
class TimePeriod {
public double Hours
@@ -730,6 +721,17 @@
}
})",
Style);
+
+ // Microsoft style trivial property accessors have no line break before the
+ // opening brace.
+ auto MicrosoftStyle = getMicrosoftStyle(FormatStyle::LK_CSharp);
+ verifyFormat(R"(//
+public class SaleItem
+{
+ public decimal Price { get; set; }
+})",
+ MicrosoftStyle);
+
}
TEST_F(FormatTestCSharp, CSharpSpaces) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1542,7 +1542,7 @@
// Try to parse the property accessor:
// https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/properties
Tokens->setPosition(StoredPosition);
- if (Style.BraceWrapping.AfterFunction == true)
+ if (!IsTrivialPropertyAccessor && Style.BraceWrapping.AfterFunction == true)
addUnwrappedLine();
nextToken();
do {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81467.269517.patch
Type: text/x-patch
Size: 2055 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200609/85d75889/attachment.bin>
More information about the cfe-commits
mailing list