Skip to content

Commit 9ef8276

Browse files
authored
C#: Add .editorconfig file (#4129)
1 parent 28d3343 commit 9ef8276

23 files changed

+265
-42
lines changed

csharp/.editorconfig

+213
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
# Taken as is from https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2019
2+
# Customizations are added at the bottom of the file.
3+
4+
# Remove the line below if you want to inherit .editorconfig settings from higher directories
5+
root = true
6+
7+
# C# files
8+
[*.cs]
9+
10+
#### Core EditorConfig Options ####
11+
12+
# Indentation and spacing
13+
indent_size = 4
14+
indent_style = space
15+
tab_width = 4
16+
17+
# New line preferences
18+
end_of_line = crlf
19+
insert_final_newline = false
20+
21+
#### .NET Coding Conventions ####
22+
23+
# Organize usings
24+
dotnet_separate_import_directive_groups = false
25+
dotnet_sort_system_directives_first = false
26+
27+
# this. and Me. preferences
28+
dotnet_style_qualification_for_event = false:silent
29+
dotnet_style_qualification_for_field = false:silent
30+
dotnet_style_qualification_for_method = false:silent
31+
dotnet_style_qualification_for_property = false:silent
32+
33+
# Language keywords vs BCL types preferences
34+
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
35+
dotnet_style_predefined_type_for_member_access = true:silent
36+
37+
# Parentheses preferences
38+
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
39+
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
40+
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
41+
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
42+
43+
# Modifier preferences
44+
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
45+
46+
# Expression-level preferences
47+
dotnet_style_coalesce_expression = true:suggestion
48+
dotnet_style_collection_initializer = true:suggestion
49+
dotnet_style_explicit_tuple_names = true:suggestion
50+
dotnet_style_null_propagation = true:suggestion
51+
dotnet_style_object_initializer = true:suggestion
52+
dotnet_style_prefer_auto_properties = true:silent
53+
dotnet_style_prefer_compound_assignment = true:suggestion
54+
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
55+
dotnet_style_prefer_conditional_expression_over_return = true:silent
56+
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
57+
dotnet_style_prefer_inferred_tuple_names = true:suggestion
58+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
59+
dotnet_style_prefer_simplified_interpolation = true:suggestion
60+
61+
# Field preferences
62+
dotnet_style_readonly_field = true:suggestion
63+
64+
# Parameter preferences
65+
dotnet_code_quality_unused_parameters = all:suggestion
66+
67+
#### C# Coding Conventions ####
68+
69+
# var preferences
70+
csharp_style_var_elsewhere = false:silent
71+
csharp_style_var_for_built_in_types = false:silent
72+
csharp_style_var_when_type_is_apparent = false:silent
73+
74+
# Expression-bodied members
75+
csharp_style_expression_bodied_accessors = true:silent
76+
csharp_style_expression_bodied_constructors = false:silent
77+
csharp_style_expression_bodied_indexers = true:silent
78+
csharp_style_expression_bodied_lambdas = true:silent
79+
csharp_style_expression_bodied_local_functions = false:silent
80+
csharp_style_expression_bodied_methods = false:silent
81+
csharp_style_expression_bodied_operators = false:silent
82+
csharp_style_expression_bodied_properties = true:silent
83+
84+
# Pattern matching preferences
85+
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
86+
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
87+
csharp_style_prefer_switch_expression = true:suggestion
88+
89+
# Null-checking preferences
90+
csharp_style_conditional_delegate_call = true:suggestion
91+
92+
# Modifier preferences
93+
csharp_prefer_static_local_function = true:suggestion
94+
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:silent
95+
96+
# Code-block preferences
97+
csharp_prefer_braces = true:silent
98+
csharp_prefer_simple_using_statement = true:suggestion
99+
100+
# Expression-level preferences
101+
csharp_prefer_simple_default_expression = true:suggestion
102+
csharp_style_deconstructed_variable_declaration = true:suggestion
103+
csharp_style_inlined_variable_declaration = true:suggestion
104+
csharp_style_pattern_local_over_anonymous_function = true:suggestion
105+
csharp_style_prefer_index_operator = true:suggestion
106+
csharp_style_prefer_range_operator = true:suggestion
107+
csharp_style_throw_expression = true:suggestion
108+
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
109+
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
110+
111+
# 'using' directive preferences
112+
csharp_using_directive_placement = outside_namespace:silent
113+
114+
#### C# Formatting Rules ####
115+
116+
# New line preferences
117+
csharp_new_line_before_catch = true
118+
csharp_new_line_before_else = true
119+
csharp_new_line_before_finally = true
120+
csharp_new_line_before_members_in_anonymous_types = true
121+
csharp_new_line_before_members_in_object_initializers = true
122+
csharp_new_line_before_open_brace = all
123+
csharp_new_line_between_query_expression_clauses = true
124+
125+
# Indentation preferences
126+
csharp_indent_block_contents = true
127+
csharp_indent_braces = false
128+
csharp_indent_case_contents = true
129+
csharp_indent_case_contents_when_block = true
130+
csharp_indent_labels = one_less_than_current
131+
csharp_indent_switch_labels = true
132+
133+
# Space preferences
134+
csharp_space_after_cast = false
135+
csharp_space_after_colon_in_inheritance_clause = true
136+
csharp_space_after_comma = true
137+
csharp_space_after_dot = false
138+
csharp_space_after_keywords_in_control_flow_statements = true
139+
csharp_space_after_semicolon_in_for_statement = true
140+
csharp_space_around_binary_operators = before_and_after
141+
csharp_space_around_declaration_statements = false
142+
csharp_space_before_colon_in_inheritance_clause = true
143+
csharp_space_before_comma = false
144+
csharp_space_before_dot = false
145+
csharp_space_before_open_square_brackets = false
146+
csharp_space_before_semicolon_in_for_statement = false
147+
csharp_space_between_empty_square_brackets = false
148+
csharp_space_between_method_call_empty_parameter_list_parentheses = false
149+
csharp_space_between_method_call_name_and_opening_parenthesis = false
150+
csharp_space_between_method_call_parameter_list_parentheses = false
151+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
152+
csharp_space_between_method_declaration_name_and_open_parenthesis = false
153+
csharp_space_between_method_declaration_parameter_list_parentheses = false
154+
csharp_space_between_parentheses = false
155+
csharp_space_between_square_brackets = false
156+
157+
# Wrapping preferences
158+
csharp_preserve_single_line_blocks = true
159+
csharp_preserve_single_line_statements = true
160+
161+
#### Naming styles ####
162+
163+
# Naming rules
164+
165+
dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
166+
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
167+
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
168+
169+
dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
170+
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
171+
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
172+
173+
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
174+
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
175+
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
176+
177+
# Symbol specifications
178+
179+
dotnet_naming_symbols.interface.applicable_kinds = interface
180+
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
181+
dotnet_naming_symbols.interface.required_modifiers =
182+
183+
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
184+
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
185+
dotnet_naming_symbols.types.required_modifiers =
186+
187+
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
188+
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
189+
dotnet_naming_symbols.non_field_members.required_modifiers =
190+
191+
# Naming styles
192+
193+
dotnet_naming_style.pascal_case.required_prefix =
194+
dotnet_naming_style.pascal_case.required_suffix =
195+
dotnet_naming_style.pascal_case.word_separator =
196+
dotnet_naming_style.pascal_case.capitalization = pascal_case
197+
198+
dotnet_naming_style.begins_with_i.required_prefix = I
199+
dotnet_naming_style.begins_with_i.required_suffix =
200+
dotnet_naming_style.begins_with_i.word_separator =
201+
dotnet_naming_style.begins_with_i.capitalization = pascal_case
202+
203+
#
204+
# Customizations
205+
#
206+
207+
# IDE0055: Fix formatting
208+
dotnet_diagnostic.IDE0055.severity = warning
209+
210+
[extractor/Semmle.Extraction/Tuples.cs,
211+
extractor/Semmle.Extraction.CSharp/Tuples.cs,
212+
extractor/Semmle.Extraction.CIL/Tuples.cs]
213+
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = none

csharp/.vscode/settings.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,11 @@
33
"dotnet-test-explorer.testProjectPath": "**/*Tests.@(csproj|vbproj|fsproj)",
44
"dotnet-test-explorer.testArguments": "/property:GenerateTargetFrameworkAttribute=false",
55
"csharp.supressBuildAssetsNotification": true,
6-
"csharp.suppressDotnetRestoreNotification": true
6+
"csharp.suppressDotnetRestoreNotification": true,
7+
"[csharp]": {
8+
"editor.defaultFormatter": "ms-dotnettools.csharp"
9+
},
10+
"omnisharp.enableMsBuildLoadProjectsOnDemand": true,
11+
"omnisharp.enableEditorConfigSupport": true,
12+
"omnisharp.enableRoslynAnalyzers": true,
713
}

csharp/extractor/Semmle.Extraction.CIL/Entities/Method.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ public override void WriteId(TextWriter trapFile)
501501
unboundMethod.WriteId(trapFile);
502502
trapFile.Write('<');
503503
int index = 0;
504-
foreach(var param in typeParams)
504+
foreach (var param in typeParams)
505505
{
506506
trapFile.WriteSeparator(",", ref index);
507507
trapFile.WriteSubId(param);

csharp/extractor/Semmle.Extraction.CIL/Entities/Property.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public override void WriteId(TextWriter trapFile)
3838
trapFile.Write('.');
3939
trapFile.Write(cx.GetString(pd.Name));
4040
trapFile.Write("(");
41-
int index=0;
41+
int index = 0;
4242
var signature = pd.DecodeSignature(new SignatureDecoder(), gc);
4343
foreach (var param in signature.ParameterTypes)
4444
{

csharp/extractor/Semmle.Extraction.CIL/Entities/Type.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ public ConstructedType(Context cx, Type unboundType, IEnumerable<Type> typeArgum
771771

772772
public override bool Equals(object obj)
773773
{
774-
if(obj is ConstructedType t && Equals(unboundGenericType, t.unboundGenericType) && Equals(containingType, t.containingType))
774+
if (obj is ConstructedType t && Equals(unboundGenericType, t.unboundGenericType) && Equals(containingType, t.containingType))
775775
{
776776
if (thisTypeArguments is null) return t.thisTypeArguments is null;
777777
if (!(t.thisTypeArguments is null)) return thisTypeArguments.SequenceEqual(t.thisTypeArguments);
@@ -1208,7 +1208,7 @@ public void WriteId(TextWriter trapFile, GenericContext gc)
12081208
{
12091209
elementType.WriteId(trapFile, gc);
12101210
trapFile.Write('[');
1211-
for (int i=1; i<shape.Rank; ++i)
1211+
for (int i = 1; i < shape.Rank; ++i)
12121212
trapFile.Write(',');
12131213
trapFile.Write(']');
12141214
}
@@ -1254,7 +1254,7 @@ public void WriteId(TextWriter trapFile, GenericContext gc)
12541254
genericType.WriteId(trapFile, gc);
12551255
trapFile.Write('<');
12561256
int index = 0;
1257-
foreach(var arg in typeArguments)
1257+
foreach (var arg in typeArguments)
12581258
{
12591259
trapFile.WriteSeparator(",", ref index);
12601260
arg.WriteId(trapFile, gc);
@@ -1451,8 +1451,7 @@ Type ISignatureTypeProvider<Type, GenericContext>.GetGenericTypeParameter(Generi
14511451
genericContext.GetGenericTypeParameter(index);
14521452

14531453
Type ISignatureTypeProvider<Type, GenericContext>.GetModifiedType(Type modifier, Type unmodifiedType, bool isRequired) =>
1454-
// !! Not implemented properly
1455-
unmodifiedType;
1454+
unmodifiedType; // !! Not implemented properly
14561455

14571456
Type ISignatureTypeProvider<Type, GenericContext>.GetPinnedType(Type elementType) =>
14581457
cx.Populate(new PointerType(cx, elementType));

csharp/extractor/Semmle.Extraction.CSharp/Entities/Compilation.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,28 @@ protected override void Populate(TextWriter trapFile)
2626

2727
// Arguments
2828
int index = 0;
29-
foreach(var arg in args)
29+
foreach (var arg in args)
3030
{
3131
trapFile.compilation_args(this, index++, arg);
3232
}
3333

3434
// Files
3535
index = 0;
36-
foreach(var file in cx.Compilation.SyntaxTrees.Select(tree => Extraction.Entities.File.Create(cx, tree.FilePath)))
36+
foreach (var file in cx.Compilation.SyntaxTrees.Select(tree => Extraction.Entities.File.Create(cx, tree.FilePath)))
3737
{
3838
trapFile.compilation_compiling_files(this, index++, file);
3939
}
4040

4141
// References
4242
index = 0;
43-
foreach(var file in cx.Compilation.References.OfType<PortableExecutableReference>().Select(r => Extraction.Entities.File.Create(cx, r.FilePath)))
43+
foreach (var file in cx.Compilation.References.OfType<PortableExecutableReference>().Select(r => Extraction.Entities.File.Create(cx, r.FilePath)))
4444
{
4545
trapFile.compilation_referencing_files(this, index++, file);
4646
}
4747

4848
// Diagnostics
4949
index = 0;
50-
foreach(var diag in cx.Compilation.GetDiagnostics().Select(d => new Diagnostic(cx, d)))
50+
foreach (var diag in cx.Compilation.GetDiagnostics().Select(d => new Diagnostic(cx, d)))
5151
{
5252
trapFile.diagnostic_for(diag, this, 0, index++);
5353
}
@@ -57,7 +57,7 @@ public void PopulatePerformance(PerformanceMetrics p)
5757
{
5858
var trapFile = cx.TrapWriter.Writer;
5959
int index = 0;
60-
foreach(float metric in p.Metrics)
60+
foreach (float metric in p.Metrics)
6161
{
6262
trapFile.compilation_time(this, -1, index++, metric);
6363
}

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expression.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected sealed override void Populate(TextWriter trapFile)
5353
trapFile.type_nullability(this, n);
5454
}
5555

56-
if(Info.FlowState != NullableFlowState.None)
56+
if (Info.FlowState != NullableFlowState.None)
5757
{
5858
trapFile.expr_flowstate(this, (int)Info.FlowState);
5959
}
@@ -292,7 +292,7 @@ abstract class Expression<SyntaxNode> : Expression
292292
protected Expression(ExpressionNodeInfo info)
293293
: base(info)
294294
{
295-
Syntax = (SyntaxNode)info.Node;
295+
Syntax = (SyntaxNode)info.Node;
296296
}
297297

298298
/// <summary>
@@ -307,7 +307,7 @@ protected Expression(ExpressionNodeInfo info)
307307

308308
protected new Expression TryPopulate()
309309
{
310-
cx.Try(Syntax, null, ()=>PopulateExpression(cx.TrapWriter.Writer));
310+
cx.Try(Syntax, null, () => PopulateExpression(cx.TrapWriter.Writer));
311311
return this;
312312
}
313313
}

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/ImplicitCast.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public ImplicitCast(ExpressionNodeInfo info)
2222
}
2323

2424
public ImplicitCast(ExpressionNodeInfo info, IMethodSymbol method)
25-
: base(new ExpressionInfo(info.Context, Entities.Type.Create(info.Context, info.ConvertedType), info.Location, ExprKind.OPERATOR_INVOCATION, info.Parent, info.Child, true, info.ExprValue) )
25+
: base(new ExpressionInfo(info.Context, Entities.Type.Create(info.Context, info.ConvertedType), info.Location, ExprKind.OPERATOR_INVOCATION, info.Parent, info.Child, true, info.ExprValue))
2626
{
2727
Expr = Factory.Create(info.SetParent(this, 0));
2828

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Lambda.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ void VisitParameter(ParameterSyntax p)
5050
public static Lambda Create(ExpressionNodeInfo info, SimpleLambdaExpressionSyntax node) => new Lambda(info, node);
5151

5252
Lambda(ExpressionNodeInfo info, AnonymousMethodExpressionSyntax node) :
53-
this(info.SetKind(ExprKind.ANONYMOUS_METHOD), node.Body, node.ParameterList == null ? Enumerable.Empty<ParameterSyntax>() : node.ParameterList.Parameters) { }
53+
this(info.SetKind(ExprKind.ANONYMOUS_METHOD), node.Body, node.ParameterList == null ? Enumerable.Empty<ParameterSyntax>() : node.ParameterList.Parameters)
54+
{ }
5455

5556
public static Lambda Create(ExpressionNodeInfo info, AnonymousMethodExpressionSyntax node) => new Lambda(info, node);
5657
}

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Literal.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
99
{
1010
class Literal : Expression<LiteralExpressionSyntax>
1111
{
12-
Literal(ExpressionNodeInfo info) : base(info.SetKind(GetKind(info)) ) { }
12+
Literal(ExpressionNodeInfo info) : base(info.SetKind(GetKind(info))) { }
1313

1414
public static Expression Create(ExpressionNodeInfo info) => new Literal(info).TryPopulate();
1515

1616
protected override void PopulateExpression(TextWriter trapFile) { }
1717

1818
static ExprKind GetKind(ExpressionNodeInfo info)
1919
{
20-
switch(info.Node.Kind())
20+
switch (info.Node.Kind())
2121
{
2222
case SyntaxKind.DefaultLiteralExpression:
2323
return ExprKind.DEFAULT;

0 commit comments

Comments
 (0)