Skip to content

Commit f15e244

Browse files
authored
Add formatting rules (#1576)
1 parent 8d47d71 commit f15e244

File tree

334 files changed

+16688
-16631
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

334 files changed

+16688
-16631
lines changed

.editorconfig

+53-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,63 @@
33
# top-most EditorConfig file
44
root = true
55

6+
[*]
7+
indent_style = space
8+
69
# Code files
710
[*.{cs,csx}]
8-
9-
indent_style = space
1011
indent_size = 4
1112

13+
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/csharp-formatting-options
14+
15+
# New-line options
16+
# https://docs.microsoft.com/visualstudio/ide/editorconfig-formatting-conventions#new-line-options
17+
csharp_new_line_before_open_brace = all
18+
csharp_new_line_before_else = true
19+
csharp_new_line_before_catch = true
20+
csharp_new_line_before_finally = true
21+
csharp_new_line_before_members_in_object_initializers = false
22+
csharp_new_line_before_members_in_anonymous_types = true
23+
csharp_new_line_between_query_expression_clauses = true
24+
25+
# Indentation options
26+
# https://docs.microsoft.com/visualstudio/ide/editorconfig-formatting-conventions#indentation-options
27+
csharp_indent_case_contents = true
28+
csharp_indent_switch_labels = true
29+
csharp_indent_labels = flush_left
30+
csharp_indent_block_contents = true
31+
csharp_indent_braces = false
32+
csharp_indent_case_contents_when_block = false
33+
34+
# Spacing options
35+
# https://docs.microsoft.com/visualstudio/ide/editorconfig-formatting-conventions#spacing-options
36+
csharp_space_after_cast = false
37+
csharp_space_after_keywords_in_control_flow_statements = true
38+
csharp_space_before_colon_in_inheritance_clause = true
39+
csharp_space_after_colon_in_inheritance_clause = true
40+
csharp_space_around_binary_operators = before_and_after
41+
csharp_space_between_method_declaration_parameter_list_parentheses = false
42+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
43+
csharp_space_between_method_declaration_name_and_open_parenthesis = false
44+
csharp_space_between_method_call_parameter_list_parentheses = false
45+
csharp_space_between_method_call_empty_parameter_list_parentheses = false
46+
csharp_space_between_method_call_name_and_opening_parenthesis = false
47+
csharp_space_after_comma = true
48+
csharp_space_before_comma = false
49+
csharp_space_after_dot = false
50+
csharp_space_before_dot = false
51+
csharp_space_after_semicolon_in_for_statement = true
52+
csharp_space_before_semicolon_in_for_statement = false
53+
csharp_space_around_declaration_statements = false
54+
csharp_space_before_open_square_brackets = false
55+
csharp_space_between_empty_square_brackets = false
56+
csharp_space_between_square_brackets = false
57+
58+
# Wrap options
59+
# https://docs.microsoft.com/visualstudio/ide/editorconfig-formatting-conventions#wrap-options
60+
csharp_preserve_single_line_statements = false
61+
csharp_preserve_single_line_blocks = true
62+
1263
dotnet_sort_system_directives_first = true
1364

1465
csharp_style_namespace_declarations = file_scoped:suggestion

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,6 @@ ModelManifest.xml
242242
.paket/paket.exe
243243

244244
# FAKE - F# Make
245-
.fake/
245+
.fake/
246+
247+
.DS_Store

ChangeLog.md

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Fix analyzer [RCS1213](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1213) ([PR](https://github.com/dotnet/roslynator/pull/1586))
1313

14+
### Changed
15+
16+
- Update whitespace formatting rules ([PR](https://github.com/dotnet/roslynator/pull/1576))
17+
1418
## [4.12.9] - 2024-10-25
1519

1620
### Fixed

src/Analyzers.CodeFixes/CSharp/CodeFixes/AddExceptionToDocumentationCommentCodeFixProvider.cs

+21-21
Original file line numberDiff line numberDiff line change
@@ -34,33 +34,33 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
3434
switch (diagnostic.Id)
3535
{
3636
case DiagnosticIdentifiers.AddExceptionToDocumentationComment:
37+
{
38+
switch (node.Kind())
3739
{
38-
switch (node.Kind())
40+
case SyntaxKind.ThrowStatement:
3941
{
40-
case SyntaxKind.ThrowStatement:
41-
{
42-
CodeAction codeAction = CodeAction.Create(
43-
"Add exception to documentation comment",
44-
ct => AddExceptionElementToDocumentationCommentRefactoring.RefactorAsync(context.Document, (ThrowStatementSyntax)node, ct),
45-
GetEquivalenceKey(diagnostic));
42+
CodeAction codeAction = CodeAction.Create(
43+
"Add exception to documentation comment",
44+
ct => AddExceptionElementToDocumentationCommentRefactoring.RefactorAsync(context.Document, (ThrowStatementSyntax)node, ct),
45+
GetEquivalenceKey(diagnostic));
4646

47-
context.RegisterCodeFix(codeAction, diagnostic);
48-
break;
49-
}
50-
case SyntaxKind.ThrowExpression:
51-
{
52-
CodeAction codeAction = CodeAction.Create(
53-
"Add exception to documentation comment",
54-
ct => AddExceptionElementToDocumentationCommentRefactoring.RefactorAsync(context.Document, (ThrowExpressionSyntax)node, ct),
55-
GetEquivalenceKey(diagnostic));
56-
57-
context.RegisterCodeFix(codeAction, diagnostic);
58-
break;
59-
}
47+
context.RegisterCodeFix(codeAction, diagnostic);
48+
break;
6049
}
50+
case SyntaxKind.ThrowExpression:
51+
{
52+
CodeAction codeAction = CodeAction.Create(
53+
"Add exception to documentation comment",
54+
ct => AddExceptionElementToDocumentationCommentRefactoring.RefactorAsync(context.Document, (ThrowExpressionSyntax)node, ct),
55+
GetEquivalenceKey(diagnostic));
6156

62-
break;
57+
context.RegisterCodeFix(codeAction, diagnostic);
58+
break;
59+
}
6360
}
61+
62+
break;
63+
}
6464
}
6565
}
6666
}

src/Analyzers.CodeFixes/CSharp/CodeFixes/AssignmentExpressionCodeFixProvider.cs

+39-39
Original file line numberDiff line numberDiff line change
@@ -46,33 +46,33 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
4646
switch (diagnostic.Id)
4747
{
4848
case DiagnosticIdentifiers.UseUnaryOperatorInsteadOfAssignment:
49-
{
50-
string operatorText = UseUnaryOperatorInsteadOfAssignmentAnalyzer.GetOperatorText(assignment);
49+
{
50+
string operatorText = UseUnaryOperatorInsteadOfAssignmentAnalyzer.GetOperatorText(assignment);
5151

52-
CodeAction codeAction = CodeAction.Create(
53-
$"Use {operatorText} operator",
54-
ct => UseUnaryOperatorInsteadOfAssignmentAsync(document, assignment, ct),
55-
GetEquivalenceKey(diagnostic));
52+
CodeAction codeAction = CodeAction.Create(
53+
$"Use {operatorText} operator",
54+
ct => UseUnaryOperatorInsteadOfAssignmentAsync(document, assignment, ct),
55+
GetEquivalenceKey(diagnostic));
5656

57-
context.RegisterCodeFix(codeAction, diagnostic);
58-
break;
59-
}
57+
context.RegisterCodeFix(codeAction, diagnostic);
58+
break;
59+
}
6060
case DiagnosticIdentifiers.RemoveRedundantDelegateCreation:
61-
{
62-
CodeAction codeAction = CodeAction.Create(
63-
"Remove redundant delegate creation",
64-
ct =>
65-
{
66-
return RemoveRedundantDelegateCreationRefactoring.RefactorAsync(
67-
document,
68-
(ObjectCreationExpressionSyntax)assignment.Right,
69-
ct);
70-
},
71-
GetEquivalenceKey(diagnostic));
72-
73-
context.RegisterCodeFix(codeAction, diagnostic);
74-
break;
75-
}
61+
{
62+
CodeAction codeAction = CodeAction.Create(
63+
"Remove redundant delegate creation",
64+
ct =>
65+
{
66+
return RemoveRedundantDelegateCreationRefactoring.RefactorAsync(
67+
document,
68+
(ObjectCreationExpressionSyntax)assignment.Right,
69+
ct);
70+
},
71+
GetEquivalenceKey(diagnostic));
72+
73+
context.RegisterCodeFix(codeAction, diagnostic);
74+
break;
75+
}
7676
}
7777
}
7878
}
@@ -116,32 +116,32 @@ List<SyntaxTrivia> GetTrailingTrivia()
116116
{
117117
case SyntaxKind.AddAssignmentExpression:
118118
case SyntaxKind.SubtractAssignmentExpression:
119-
{
120-
trivia.AddRange(assignment.OperatorToken.GetAllTrivia());
119+
{
120+
trivia.AddRange(assignment.OperatorToken.GetAllTrivia());
121121

122-
if (right?.IsMissing == false)
123-
trivia.AddRange(right.GetLeadingAndTrailingTrivia());
122+
if (right?.IsMissing == false)
123+
trivia.AddRange(right.GetLeadingAndTrailingTrivia());
124124

125-
return trivia;
126-
}
125+
return trivia;
126+
}
127127
}
128128

129129
switch (right?.Kind())
130130
{
131131
case SyntaxKind.AddExpression:
132132
case SyntaxKind.SubtractExpression:
133-
{
134-
trivia.AddRange(assignment.OperatorToken.GetAllTrivia());
135-
136-
if (right?.IsMissing == false)
137-
{
138-
var binaryExpression = (BinaryExpressionSyntax)right;
133+
{
134+
trivia.AddRange(assignment.OperatorToken.GetAllTrivia());
139135

140-
trivia.AddRange(binaryExpression.DescendantTrivia());
141-
}
136+
if (right?.IsMissing == false)
137+
{
138+
var binaryExpression = (BinaryExpressionSyntax)right;
142139

143-
return trivia;
140+
trivia.AddRange(binaryExpression.DescendantTrivia());
144141
}
142+
143+
return trivia;
144+
}
145145
}
146146

147147
throw new InvalidOperationException();

src/Analyzers.CodeFixes/CSharp/CodeFixes/AvoidBoxingOfValueTypeCodeFixProvider.cs

+11-11
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
3636
switch (diagnostic.Id)
3737
{
3838
case DiagnosticIdentifiers.AvoidBoxingOfValueType:
39-
{
40-
CodeAction codeAction = CodeAction.Create(
41-
(expression.IsKind(SyntaxKind.CharacterLiteralExpression))
42-
? "Use string literal instead of character literal"
43-
: "Call 'ToString'",
44-
ct => RefactorAsync(context.Document, expression, ct),
45-
GetEquivalenceKey(diagnostic));
46-
47-
context.RegisterCodeFix(codeAction, diagnostic);
48-
break;
49-
}
39+
{
40+
CodeAction codeAction = CodeAction.Create(
41+
(expression.IsKind(SyntaxKind.CharacterLiteralExpression))
42+
? "Use string literal instead of character literal"
43+
: "Call 'ToString'",
44+
ct => RefactorAsync(context.Document, expression, ct),
45+
GetEquivalenceKey(diagnostic));
46+
47+
context.RegisterCodeFix(codeAction, diagnostic);
48+
break;
49+
}
5050
}
5151
}
5252
}

src/Analyzers.CodeFixes/CSharp/CodeFixes/AwaitExpressionCodeFixProvider.cs

+11-11
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,21 @@ private static Task<Document> AddCallToConfigureAwaitRefactorAsync(
6969
switch (expression.Kind())
7070
{
7171
case SyntaxKind.SimpleMemberAccessExpression:
72-
{
73-
var memberAccess = (MemberAccessExpressionSyntax)expression;
72+
{
73+
var memberAccess = (MemberAccessExpressionSyntax)expression;
7474

75-
leading = memberAccess.OperatorToken.LeadingTrivia;
76-
break;
77-
}
75+
leading = memberAccess.OperatorToken.LeadingTrivia;
76+
break;
77+
}
7878
case SyntaxKind.InvocationExpression:
79-
{
80-
var invocation = (InvocationExpressionSyntax)expression;
79+
{
80+
var invocation = (InvocationExpressionSyntax)expression;
8181

82-
SimpleMemberInvocationExpressionInfo invocationInfo = SyntaxInfo.SimpleMemberInvocationExpressionInfo(invocation);
82+
SimpleMemberInvocationExpressionInfo invocationInfo = SyntaxInfo.SimpleMemberInvocationExpressionInfo(invocation);
8383

84-
leading = invocationInfo.OperatorToken.LeadingTrivia;
85-
break;
86-
}
84+
leading = invocationInfo.OperatorToken.LeadingTrivia;
85+
break;
86+
}
8787
}
8888

8989
SyntaxTrivia last = leading.LastOrDefault();

src/Analyzers.CodeFixes/CSharp/CodeFixes/BaseArgumentListCodeFixProvider.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
4040
switch (diagnostic.Id)
4141
{
4242
case DiagnosticIdentifiers.OrderNamedArguments:
43-
{
44-
CodeAction codeAction = CodeAction.Create(
45-
"Order arguments",
46-
ct => OrderNamedArgumentsAsync(document, baseArgumentList, ct),
47-
GetEquivalenceKey(diagnostic));
48-
49-
context.RegisterCodeFix(codeAction, diagnostic);
50-
break;
51-
}
43+
{
44+
CodeAction codeAction = CodeAction.Create(
45+
"Order arguments",
46+
ct => OrderNamedArgumentsAsync(document, baseArgumentList, ct),
47+
GetEquivalenceKey(diagnostic));
48+
49+
context.RegisterCodeFix(codeAction, diagnostic);
50+
break;
51+
}
5252
}
5353
}
5454

0 commit comments

Comments
 (0)