Skip to content

Commit 6250fcb

Browse files
authored
feat: spacing and formatting rules (coding standards) (#666)
* add .editorconfig * dotnet-format testproject.sln * fix style errors * complete: spacing and formatting rules * dotnet-format after merge
1 parent 1e650bb commit 6250fcb

File tree

112 files changed

+3624
-1418
lines changed

Some content is hidden

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

112 files changed

+3624
-1418
lines changed

.editorconfig

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
6+
[*.cs]
7+
# spacing rules
8+
end_of_line = lf
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
indent_style = space
12+
indent_size = 4
13+
14+
# formatting rules
15+
dotnet_style_qualification_for_field = false:error
16+
dotnet_style_qualification_for_property = false:error
17+
dotnet_style_qualification_for_method = false:error
18+
dotnet_style_qualification_for_event = false:error
19+
dotnet_style_predefined_type_for_locals_parameters_members = true:error
20+
dotnet_style_predefined_type_for_member_access = true:error
21+
dotnet_style_require_accessibility_modifiers = always:error
22+
csharp_style_var_when_type_is_apparent = true:error
23+
csharp_prefer_braces = true:error
24+
csharp_using_directive_placement = outside_namespace:error
25+
26+
# naming rules

com.unity.multiplayer.mlapi/Editor/CodeGen/CodeGenHelpers.cs

Lines changed: 128 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ public static uint Hash(this MethodDefinition methodDefinition)
5353

5454
public static bool IsSubclassOf(this TypeDefinition typeDefinition, string ClassTypeFullName)
5555
{
56-
if (!typeDefinition.IsClass) return false;
56+
if (!typeDefinition.IsClass)
57+
{
58+
return false;
59+
}
5760

5861
var baseTypeRef = typeDefinition.BaseType;
5962
while (baseTypeRef != null)
@@ -78,7 +81,10 @@ public static bool IsSubclassOf(this TypeDefinition typeDefinition, string Class
7881

7982
public static bool HasInterface(this TypeReference typeReference, string InterfaceTypeFullName)
8083
{
81-
if (typeReference.IsArray) return false;
84+
if (typeReference.IsArray)
85+
{
86+
return false;
87+
}
8288

8389
try
8490
{
@@ -97,45 +103,139 @@ public static bool IsSerializable(this TypeReference typeReference)
97103
var typeSystem = typeReference.Module.TypeSystem;
98104

99105
// C# primitives
100-
if (typeReference == typeSystem.Boolean) return true;
101-
if (typeReference == typeSystem.Char) return true;
102-
if (typeReference == typeSystem.SByte) return true;
103-
if (typeReference == typeSystem.Byte) return true;
104-
if (typeReference == typeSystem.Int16) return true;
105-
if (typeReference == typeSystem.UInt16) return true;
106-
if (typeReference == typeSystem.Int32) return true;
107-
if (typeReference == typeSystem.UInt32) return true;
108-
if (typeReference == typeSystem.Int64) return true;
109-
if (typeReference == typeSystem.UInt64) return true;
110-
if (typeReference == typeSystem.Single) return true;
111-
if (typeReference == typeSystem.Double) return true;
112-
if (typeReference == typeSystem.String) return true;
106+
if (typeReference == typeSystem.Boolean)
107+
{
108+
return true;
109+
}
110+
111+
if (typeReference == typeSystem.Char)
112+
{
113+
return true;
114+
}
115+
116+
if (typeReference == typeSystem.SByte)
117+
{
118+
return true;
119+
}
120+
121+
if (typeReference == typeSystem.Byte)
122+
{
123+
return true;
124+
}
125+
126+
if (typeReference == typeSystem.Int16)
127+
{
128+
return true;
129+
}
130+
131+
if (typeReference == typeSystem.UInt16)
132+
{
133+
return true;
134+
}
135+
136+
if (typeReference == typeSystem.Int32)
137+
{
138+
return true;
139+
}
140+
141+
if (typeReference == typeSystem.UInt32)
142+
{
143+
return true;
144+
}
145+
146+
if (typeReference == typeSystem.Int64)
147+
{
148+
return true;
149+
}
150+
151+
if (typeReference == typeSystem.UInt64)
152+
{
153+
return true;
154+
}
155+
156+
if (typeReference == typeSystem.Single)
157+
{
158+
return true;
159+
}
160+
161+
if (typeReference == typeSystem.Double)
162+
{
163+
return true;
164+
}
165+
166+
if (typeReference == typeSystem.String)
167+
{
168+
return true;
169+
}
113170

114171
// Unity primitives
115-
if (typeReference.FullName == UnityColor_FullName) return true;
116-
if (typeReference.FullName == UnityColor32_FullName) return true;
117-
if (typeReference.FullName == UnityVector2_FullName) return true;
118-
if (typeReference.FullName == UnityVector3_FullName) return true;
119-
if (typeReference.FullName == UnityVector4_FullName) return true;
120-
if (typeReference.FullName == UnityQuaternion_FullName) return true;
121-
if (typeReference.FullName == UnityRay_FullName) return true;
122-
if (typeReference.FullName == UnityRay2D_FullName) return true;
172+
if (typeReference.FullName == UnityColor_FullName)
173+
{
174+
return true;
175+
}
176+
177+
if (typeReference.FullName == UnityColor32_FullName)
178+
{
179+
return true;
180+
}
181+
182+
if (typeReference.FullName == UnityVector2_FullName)
183+
{
184+
return true;
185+
}
186+
187+
if (typeReference.FullName == UnityVector3_FullName)
188+
{
189+
return true;
190+
}
191+
192+
if (typeReference.FullName == UnityVector4_FullName)
193+
{
194+
return true;
195+
}
196+
197+
if (typeReference.FullName == UnityQuaternion_FullName)
198+
{
199+
return true;
200+
}
201+
202+
if (typeReference.FullName == UnityRay_FullName)
203+
{
204+
return true;
205+
}
206+
207+
if (typeReference.FullName == UnityRay2D_FullName)
208+
{
209+
return true;
210+
}
123211

124212
// Enum
125-
if (typeReference.GetEnumAsInt() != null) return true;
213+
if (typeReference.GetEnumAsInt() != null)
214+
{
215+
return true;
216+
}
126217

127218
// INetworkSerializable
128-
if (typeReference.HasInterface(INetworkSerializable_FullName)) return true;
219+
if (typeReference.HasInterface(INetworkSerializable_FullName))
220+
{
221+
return true;
222+
}
129223

130224
// Static array
131-
if (typeReference.IsArray) return typeReference.GetElementType().IsSerializable();
225+
if (typeReference.IsArray)
226+
{
227+
return typeReference.GetElementType().IsSerializable();
228+
}
132229

133230
return false;
134231
}
135232

136233
public static TypeReference GetEnumAsInt(this TypeReference typeReference)
137234
{
138-
if (typeReference.IsArray) return null;
235+
if (typeReference.IsArray)
236+
{
237+
return null;
238+
}
139239

140240
try
141241
{
@@ -193,4 +293,4 @@ public static AssemblyDefinition AssemblyDefinitionFor(ICompiledAssembly compile
193293
return assemblyDefinition;
194294
}
195295
}
196-
}
296+
}

com.unity.multiplayer.mlapi/Editor/CodeGen/ILPostProcessCompiledAssembly.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ public InMemoryAssembly InMemoryAssembly
3939
}
4040
}
4141
}
42-
#endif
42+
#endif

com.unity.multiplayer.mlapi/Editor/CodeGen/ILPostProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ public abstract class ILPostProcessor
1010
public abstract ILPostProcessor GetInstance();
1111
}
1212
}
13-
#endif
13+
#endif

com.unity.multiplayer.mlapi/Editor/CodeGen/ILPostProcessorProgram.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,10 @@ void WriteAssembly(InMemoryAssembly inMemoryAssembly, string outputPath, string
208208
foreach (var i in s_ILPostProcessors)
209209
{
210210
var result = i.Process(targetCompiledAssembly);
211-
if (result == null) continue;
211+
if (result == null)
212+
{
213+
continue;
214+
}
212215

213216
if (result.Diagnostics.Count > 0)
214217
{

0 commit comments

Comments
 (0)