Skip to content

Commit 3d2654a

Browse files
committed
Normalize formatting and add editorconfig
1 parent 5ef590e commit 3d2654a

33 files changed

+275
-146
lines changed

.editorconfig

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Rules in this file were initially inferred by Visual Studio IntelliCode from the C:\Users\matv8981.AVWORLD\source\fNbt codebase based on best match to current usage at 8/10/2021
2+
# You can modify the rules from these initially generated values to suit your own policies
3+
# You can learn more about editorconfig here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference
4+
[*.cs]
5+
6+
7+
#Core editorconfig formatting - indentation
8+
9+
#use soft tabs (spaces) for indentation
10+
indent_style = space
11+
12+
#Formatting - indentation options
13+
14+
#indent switch case contents.
15+
csharp_indent_case_contents = true
16+
#indent switch labels
17+
csharp_indent_switch_labels = true
18+
19+
#Formatting - new line options
20+
csharp_new_line_before_open_brace = false
21+
csharp_new_line_before_else = false
22+
csharp_new_line_before_members_in_object_initializers = false
23+
csharp_new_line_before_members_in_anonymous_types = false
24+
csharp_new_line_before_catch = false
25+
csharp_new_line_before_finally = false
26+
27+
#Formatting - organize using options
28+
29+
#sort System.* using directives alphabetically, and place them before other usings
30+
dotnet_sort_system_directives_first = true
31+
32+
#Formatting - spacing options
33+
34+
#require NO space between a cast and the value
35+
csharp_space_after_cast = false
36+
#require a space before the colon for bases or interfaces in a type declaration
37+
csharp_space_after_colon_in_inheritance_clause = true
38+
#require a space after a keyword in a control flow statement such as a for loop
39+
csharp_space_after_keywords_in_control_flow_statements = true
40+
#require a space before the colon for bases or interfaces in a type declaration
41+
csharp_space_before_colon_in_inheritance_clause = true
42+
#remove space within empty argument list parentheses
43+
csharp_space_between_method_call_empty_parameter_list_parentheses = false
44+
#remove space between method call name and opening parenthesis
45+
csharp_space_between_method_call_name_and_opening_parenthesis = false
46+
#do not place space characters after the opening parenthesis and before the closing parenthesis of a method call
47+
csharp_space_between_method_call_parameter_list_parentheses = false
48+
#remove space within empty parameter list parentheses for a method declaration
49+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
50+
#place a space character after the opening parenthesis and before the closing parenthesis of a method declaration parameter list.
51+
csharp_space_between_method_declaration_parameter_list_parentheses = false
52+
53+
#Formatting - wrapping options
54+
55+
#leave code block on separate lines
56+
csharp_preserve_single_line_blocks = true
57+
#leave statements and member declarations on the same line
58+
csharp_preserve_single_line_statements = true
59+
60+
#Style - Code block preferences
61+
62+
#prefer curly braces even for one line of code
63+
csharp_prefer_braces = true:suggestion
64+
65+
#Style - expression bodied member options
66+
67+
#prefer block bodies for accessors
68+
csharp_style_expression_bodied_accessors = false:suggestion
69+
#prefer block bodies for constructors
70+
csharp_style_expression_bodied_constructors = false:suggestion
71+
#prefer block bodies for indexers
72+
csharp_style_expression_bodied_indexers = false:suggestion
73+
#prefer block bodies for methods
74+
csharp_style_expression_bodied_methods = false:suggestion
75+
#prefer block bodies for properties
76+
csharp_style_expression_bodied_properties = false:suggestion
77+
78+
#Style - expression level options
79+
80+
#prefer out variables to be declared before the method call
81+
csharp_style_inlined_variable_declaration = false:suggestion
82+
#prefer the type name for member access expressions, instead of the language keyword
83+
dotnet_style_predefined_type_for_member_access = false:suggestion
84+
85+
#Style - Expression-level preferences
86+
87+
#prefer objects to be initialized using object initializers when possible
88+
dotnet_style_object_initializer = true:suggestion
89+
90+
#Style - implicit and explicit types
91+
92+
#prefer explicit type over var in all cases, unless overridden by another code style rule
93+
csharp_style_var_elsewhere = false:suggestion
94+
#prefer explicit type over var to declare variables with built-in system types such as int
95+
csharp_style_var_for_built_in_types = false:suggestion
96+
#prefer var when the type is already mentioned on the right-hand side of a declaration expression
97+
csharp_style_var_when_type_is_apparent =false:suggestion
98+
99+
#Style - language keyword and framework type options
100+
101+
#prefer the language keyword for local variables, method parameters, and class members, instead of the type name, for types that have a keyword to represent them
102+
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
103+
104+
#Style - modifier options
105+
106+
#prefer accessibility modifiers to be declared except for public interface members. This will currently not differ from always and will act as future proofing for if C# adds default interface methods.
107+
dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion
108+
109+
#Style - Modifier preferences
110+
111+
#when this rule is set to a list of modifiers, prefer the specified ordering.
112+
csharp_preferred_modifier_order = public,internal,private,override,static,readonly,sealed,abstract,new,virtual,unsafe:suggestion
113+
114+
#Style - Pattern matching
115+
116+
#prefer is expression with type casts instead of pattern matching
117+
csharp_style_pattern_matching_over_as_with_null_check = false:suggestion
118+
119+
#Style - qualification options
120+
121+
#prefer fields not to be prefaced with this. or Me. in Visual Basic
122+
dotnet_style_qualification_for_field = false:suggestion
123+
#prefer methods not to be prefaced with this. or Me. in Visual Basic
124+
dotnet_style_qualification_for_method = false:suggestion
125+
#prefer properties not to be prefaced with this. or Me. in Visual Basic
126+
dotnet_style_qualification_for_property = false:suggestion
127+
128+
[*.{cs,vb}]
129+
dotnet_style_predefined_type_for_locals_parameters_members=true:warning

fNbt.Test/ListTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,15 +336,15 @@ public void SerializingEmpty() {
336336
}
337337
});
338338
byte[] buffer = testFile.SaveToBuffer(NbtCompression.None);
339-
339+
340340
testFile.LoadFromBuffer(buffer, 0, buffer.Length, NbtCompression.None);
341341

342342
NbtList list1 = testFile.RootTag.Get<NbtList>("emptyList");
343-
Assert.AreEqual(list1.Count,0);
343+
Assert.AreEqual(list1.Count, 0);
344344
Assert.AreEqual(list1.ListType, NbtTagType.End);
345345

346346
NbtList list2 = testFile.RootTag.Get<NbtList>("listyList");
347-
Assert.AreEqual(list2.Count,1);
347+
Assert.AreEqual(list2.Count, 1);
348348
Assert.AreEqual(list2.ListType, NbtTagType.List);
349349
Assert.AreEqual(list2.Get<NbtList>(0).Count, 0);
350350
Assert.AreEqual(list2.Get<NbtList>(0).ListType, NbtTagType.End);

fNbt.Test/MiscTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ public void CopyConstructorTest() {
5858
Assert.AreNotSame(intArrTag.Value, intArrTagClone.Value);
5959
CollectionAssert.AreEqual(intArrTag.Value, intArrTagClone.Value);
6060
Assert.Throws<ArgumentNullException>(() => new NbtIntArray((NbtIntArray)null));
61-
61+
6262
NbtLongArray longArrTag = new NbtLongArray("longArrTag", new long[] { 1, 2, 3, 4 });
63-
NbtLongArray longArrTagClone = (NbtLongArray) longArrTag.Clone();
63+
NbtLongArray longArrTagClone = (NbtLongArray)longArrTag.Clone();
6464
Assert.AreNotSame(longArrTag, longArrTagClone);
6565
Assert.AreEqual(longArrTag.Name, longArrTagClone.Name);
6666
Assert.AreNotSame(longArrTag.Value, longArrTagClone.Value);

fNbt.Test/NbtFileTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ public void GlobalsTest() {
272272
[Test]
273273
public void HugeNbtFileTest() {
274274
// Tests writing byte arrays that exceed the max NbtBinaryWriter chunk size
275-
byte[] val = new byte[5*1024*1024];
275+
byte[] val = new byte[5 * 1024 * 1024];
276276
NbtCompound root = new NbtCompound("root") {
277277
new NbtByteArray("payload1") {
278278
Value = val

fNbt.Test/NbtReaderTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public void CacheTagValuesTest() {
6969
CollectionAssert.AreEqual(new[] { 20, 21, 22 }, (int[])reader.ReadValue());
7070
CollectionAssert.AreEqual(new[] { 20, 21, 22 }, (int[])reader.ReadValue());
7171
Assert.IsTrue(reader.ReadToFollowing());
72-
CollectionAssert.AreEqual(new long[] { 200, 210, 220 }, (long[]) reader.ReadValue());
73-
CollectionAssert.AreEqual(new long[] { 200, 210, 220 }, (long[]) reader.ReadValue());
72+
CollectionAssert.AreEqual(new long[] { 200, 210, 220 }, (long[])reader.ReadValue());
73+
CollectionAssert.AreEqual(new long[] { 200, 210, 220 }, (long[])reader.ReadValue());
7474
Assert.IsTrue(reader.ReadToFollowing()); // string
7575
Assert.AreEqual("123", reader.ReadValue());
7676
Assert.AreEqual("123", reader.ReadValue());
@@ -224,7 +224,7 @@ public void PropertiesTest() {
224224
Assert.AreEqual("root", reader.ParentName);
225225
Assert.AreEqual(NbtTagType.Compound, reader.ParentTagType);
226226
Assert.AreEqual(0, reader.ParentTagLength);
227-
Assert.AreEqual(1024*1024, reader.TagLength);
227+
Assert.AreEqual(1024 * 1024, reader.TagLength);
228228
Assert.AreEqual(19, reader.TagsRead);
229229
}
230230

@@ -441,7 +441,7 @@ public void ReadListAsArray() {
441441
Assert.Throws<InvalidOperationException>(() => reader.ReadListAsArray<NbtCompound>());
442442

443443
// skip to the end of the stream
444-
while (reader.ReadToFollowing()) {}
444+
while (reader.ReadToFollowing()) { }
445445
Assert.Throws<EndOfStreamException>(() => reader.ReadListAsArray<int>());
446446
}
447447

@@ -489,7 +489,7 @@ public void ReadValueTest() {
489489
Assert.IsTrue(reader.ReadToFollowing()); // intArray
490490
CollectionAssert.AreEqual(new[] { 20, 21, 22 }, (int[])reader.ReadValue());
491491
Assert.IsTrue(reader.ReadToFollowing()); // longArray
492-
CollectionAssert.AreEqual(new long[] { 200, 210, 220 }, (long[]) reader.ReadValue());
492+
CollectionAssert.AreEqual(new long[] { 200, 210, 220 }, (long[])reader.ReadValue());
493493
Assert.IsTrue(reader.ReadToFollowing()); // string
494494
Assert.AreEqual("123", reader.ReadValue());
495495

@@ -737,7 +737,7 @@ public void PartialReadTest() {
737737
TestFiles.AssertNbtSmallFile(PartialReadTestInternal(TestFiles.MakeSmallFile()));
738738
TestFiles.AssertNbtBigFile(PartialReadTestInternal(new NbtFile(TestFiles.Big)));
739739
}
740-
740+
741741

742742
[Test]
743743
public void PartialBatchReadTest() {
@@ -803,7 +803,7 @@ static void TryReadBadFile(byte[] data) {
803803
using (MemoryStream ms = new MemoryStream(data)) {
804804
NbtReader reader = new NbtReader(ms);
805805
try {
806-
while (reader.ReadToFollowing()) {}
806+
while (reader.ReadToFollowing()) { }
807807
} catch (Exception) {
808808
Assert.IsTrue(reader.IsInErrorState);
809809
throw;

fNbt.Test/NbtWriterTest.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void HugeNbtWriterTest() {
4545
// Tests writing byte arrays that exceed the max NbtBinaryWriter chunk size
4646
using (BufferedStream bs = new BufferedStream(Stream.Null)) {
4747
NbtWriter writer = new NbtWriter(bs, "root");
48-
writer.WriteByteArray("payload4", new byte[5*1024*1024]);
48+
writer.WriteByteArray("payload4", new byte[5 * 1024 * 1024]);
4949
writer.EndCompound();
5050
writer.Finish();
5151
}
@@ -54,7 +54,7 @@ public void HugeNbtWriterTest() {
5454

5555
[Test]
5656
public void ByteArrayFromStream() {
57-
var data = new byte[64*1024];
57+
var data = new byte[64 * 1024];
5858
for (int i = 0; i < data.Length; i++) {
5959
data[i] = unchecked((byte)i);
6060
}
@@ -121,7 +121,8 @@ public void CompoundListTest() {
121121
using (var ms = new MemoryStream()) {
122122
var writer = new NbtWriter(ms, "Test");
123123
{
124-
writer.BeginCompound("EmptyCompy"); {}
124+
writer.BeginCompound("EmptyCompy");
125+
{ }
125126
writer.EndCompound();
126127

127128
writer.BeginCompound("OuterNestedCompy");
@@ -160,11 +161,14 @@ public void CompoundListTest() {
160161

161162
writer.BeginList("ListOfEmptyLists", NbtTagType.List, 3);
162163
{
163-
writer.BeginList(NbtTagType.List, 0); {}
164+
writer.BeginList(NbtTagType.List, 0);
165+
{ }
164166
writer.EndList();
165-
writer.BeginList(NbtTagType.List, 0); {}
167+
writer.BeginList(NbtTagType.List, 0);
168+
{ }
166169
writer.EndList();
167-
writer.BeginList(NbtTagType.List, 0); {}
170+
writer.BeginList(NbtTagType.List, 0);
171+
{ }
168172
writer.EndList();
169173
}
170174
writer.EndList();
@@ -504,7 +508,7 @@ public void MissingNameTest() {
504508
static string GenRandomUnicodeString(Random rand) {
505509
// String length is limited by number of bytes, not characters.
506510
// Most bytes per char in UTF8 is 4, so max string length is therefore short.MaxValue/4
507-
int len = rand.Next(8, short.MaxValue/4);
511+
int len = rand.Next(8, short.MaxValue / 4);
508512
StringBuilder sb = new StringBuilder();
509513

510514
// Generate one char at a time until we filled up the StringBuilder

fNbt.Test/PartialReadStream.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public override long Length {
6262

6363
public override long Position {
6464
get { return baseStream.Position; }
65-
set { baseStream.Position= value; }
65+
set { baseStream.Position = value; }
6666
}
6767
}
6868
}

fNbt.Test/TestFiles.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public static void AssertNbtBigFile(NbtFile file) {
284284

285285
// Values are: the first 1000 values of (n*n*255+n*7)%100, starting with n=0 (0, 62, 34, 16, 8, ...)
286286
for (int n = 0; n < 1000; n++) {
287-
Assert.AreEqual((n*n*255 + n*7)%100, ((NbtByteArray)node)[n]);
287+
Assert.AreEqual((n * n * 255 + n * 7) % 100, ((NbtByteArray)node)[n]);
288288
}
289289

290290
Assert.IsInstanceOf<NbtDouble>(root["doubleTest"]);
@@ -377,7 +377,7 @@ public static void AssertValueTest(NbtFile file) {
377377
node = root["intArray"];
378378
Assert.AreEqual("intArray", node.Name);
379379
CollectionAssert.AreEqual(new[] { 20, 21, 22 }, node.IntArrayValue);
380-
380+
381381
Assert.IsInstanceOf<NbtLongArray>(root["longArray"]);
382382
node = root["longArray"];
383383
Assert.AreEqual("longArray", node.Name);

fNbt.sln

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.27703.2035
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31515.178
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{83C41F58-F6F7-46F2-85C3-CDD69E7FBEE6}"
77
ProjectSection(SolutionItems) = preProject
@@ -10,9 +10,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{83C41F58-F
1010
README.md = README.md
1111
EndProjectSection
1212
EndProject
13-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "fNbt", "fNbt\fNbt.csproj", "{4488498D-976D-4DA3-BF72-109531AF0488}"
13+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "fNbt", "fNbt\fNbt.csproj", "{4488498D-976D-4DA3-BF72-109531AF0488}"
1414
EndProject
15-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "fNbt.Test", "fNbt.Test\fNbt.Test.csproj", "{8DD93C35-682E-4C62-9012-EF15C80FFFEA}"
15+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "fNbt.Test", "fNbt.Test\fNbt.Test.csproj", "{8DD93C35-682E-4C62-9012-EF15C80FFFEA}"
16+
EndProject
17+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{11566ECB-1DEE-478C-9B9A-9FEC0DCA4637}"
18+
ProjectSection(SolutionItems) = preProject
19+
.editorconfig = .editorconfig
20+
EndProjectSection
1621
EndProject
1722
Global
1823
GlobalSection(SolutionConfigurationPlatforms) = preSolution

fNbt/ByteCountingStream.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ internal class ByteCountingStream : Stream {
88
readonly Stream baseStream;
99

1010
// These are necessary to avoid counting bytes twice if ReadByte/WriteByte call Read/Write internally.
11-
bool readingOneByte, writingOneByte;
11+
bool readingOneByte;
12+
bool writingOneByte;
1213

1314
// These are necessary to avoid counting bytes twice if Read/Write call ReadByte/WriteByte internally.
14-
bool readingManyBytes, writingManyBytes;
15+
bool readingManyBytes;
16+
bool writingManyBytes;
1517

1618

1719
public ByteCountingStream([NotNull] Stream stream) {

0 commit comments

Comments
 (0)