Skip to content

Commit 779a307

Browse files
authored
style: add editorconfig and related code style changes (#86)
1 parent 8c17549 commit 779a307

18 files changed

+182
-128
lines changed

.editorconfig

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
[*]
3+
4+
# Microsoft .NET properties
5+
csharp_new_line_before_members_in_object_initializers = false
6+
csharp_style_namespace_declarations = block_scoped:suggestion
7+
dotnet_sort_system_directives_first = true
8+
9+
# ReSharper properties
10+
resharper_align_multiline_calls_chain = true
11+
resharper_blank_lines_after_block_statements = 0
12+
resharper_blank_lines_after_control_transfer_statements = 1
13+
resharper_blank_lines_after_using_list = 0
14+
resharper_blank_lines_before_case = 1
15+
resharper_braces_for_for = required
16+
resharper_braces_for_foreach = required
17+
resharper_braces_for_ifelse = not_required
18+
resharper_braces_for_while = required
19+
resharper_braces_redundant = false
20+
resharper_csharp_blank_lines_around_single_line_invocable = 1
21+
resharper_csharp_empty_block_style = together
22+
resharper_csharp_max_line_length = 160
23+
resharper_csharp_wrap_arguments_style = chop_if_long
24+
resharper_default_value_when_type_evident = default_expression
25+
resharper_default_value_when_type_not_evident = default_expression
26+
resharper_instance_members_qualify_declared_in = base_class
27+
resharper_local_function_body = expression_body
28+
resharper_max_initializer_elements_on_line = 2
29+
resharper_method_or_operator_body = expression_body
30+
resharper_object_creation_when_type_evident = explicitly_typed
31+
resharper_outdent_binary_ops = true
32+
resharper_parentheses_redundancy_style = remove
33+
resharper_place_expr_method_on_single_line = true
34+
resharper_place_expr_property_on_single_line = true
35+
resharper_place_simple_embedded_statement_on_same_line = false
36+
resharper_place_simple_initializer_on_single_line = false
37+
resharper_wrap_array_initializer_style = chop_if_long
38+
resharper_wrap_object_and_collection_initializer_style = wrap_if_long

JsonFlatFileDataStore.Benchmark/Benchmarks/DynamicCollectionBenchmark.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
using BenchmarkDotNet.Attributes;
1+
using System.Linq;
2+
using System.Threading.Tasks;
3+
using BenchmarkDotNet.Attributes;
24
using BenchmarkDotNet.Engines;
35
using JsonFlatFileDataStore.Test;
4-
using System.Linq;
5-
using System.Threading.Tasks;
66

77
namespace JsonFlatFileDataStore.Benchmark
88
{

JsonFlatFileDataStore.Benchmark/Benchmarks/TypedCollectionBenchmark.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
using BenchmarkDotNet.Attributes;
1+
using System.Linq;
2+
using System.Threading.Tasks;
3+
using BenchmarkDotNet.Attributes;
24
using BenchmarkDotNet.Engines;
35
using JsonFlatFileDataStore.Test;
4-
using System.Linq;
5-
using System.Threading.Tasks;
66

77
namespace JsonFlatFileDataStore.Benchmark
88
{

JsonFlatFileDataStore.Benchmark/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ internal class Program
66
{
77
private static void Main(string[] args)
88
{
9-
var switcher = new BenchmarkSwitcher(new[] {
9+
var switcher = new BenchmarkSwitcher(new[]
10+
{
1011
typeof(TypedCollectionBenchmark),
1112
typeof(DynamicCollectionBenchmark),
1213
typeof(ObjectExtensionsBenchmark)

JsonFlatFileDataStore.Test/CollectionInsertBatchTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ public async Task InsertOneAsync_100Async()
7070
Assert.Equal(3, collection.Count);
7171

7272
var tasks = Enumerable.Range(0, 100)
73-
.AsParallel()
74-
.Select(i => collection.InsertOneAsync(new User { Id = i, Name = $"Teddy_{i}" }))
75-
.ToList();
73+
.AsParallel()
74+
.Select(i => collection.InsertOneAsync(new User { Id = i, Name = $"Teddy_{i}" }))
75+
.ToList();
7676

7777
await Task.WhenAll(tasks);
7878

JsonFlatFileDataStore.Test/CollectionModificationTests.cs

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
using Newtonsoft.Json;
2-
using Newtonsoft.Json.Linq;
3-
using System;
1+
using System;
42
using System.Collections.Generic;
53
using System.Dynamic;
64
using System.Linq;
75
using System.Threading.Tasks;
6+
using Newtonsoft.Json;
7+
using Newtonsoft.Json.Linq;
88
using Xunit;
99

1010
namespace JsonFlatFileDataStore.Test
@@ -225,8 +225,8 @@ public async Task UpdateOneAsync_TypedModel_InnerSimpleArray()
225225
Type = "filled",
226226
Fragments = new List<string>
227227
{
228-
Guid.NewGuid().ToString(),
229-
Guid.NewGuid().ToString()
228+
Guid.NewGuid().ToString(),
229+
Guid.NewGuid().ToString()
230230
}
231231
};
232232

@@ -276,8 +276,8 @@ public async Task UpdateOneAsync_TypedModel_InnerSimpleIntArray()
276276
Type = "filled",
277277
Fragments = new List<int>
278278
{
279-
2,
280-
3
279+
2,
280+
3
281281
}
282282
};
283283

@@ -360,7 +360,8 @@ public async Task UpdateManyAsync_DynamicUser()
360360
var collection = store.GetCollection("user");
361361
Assert.Equal(3, collection.Count);
362362

363-
var newUsers = new[] {
363+
var newUsers = new[]
364+
{
364365
new { id = 20, name = "A1", age = 55 },
365366
new { id = 21, name = "A2", age = 55 },
366367
new { id = 22, name = "A3", age = 55 }
@@ -500,7 +501,7 @@ public void ReplaceOne__Predicate_Id_TypedUser()
500501
var collection3 = store3.GetCollection<User>("user");
501502
var updated = collection3.Find(e => e.Id == newUser.Id).First();
502503
Assert.Equal("Theodor", updated.Name);
503-
504+
504505
collection3.ReplaceOne(newUser.Id, new User { Id = newUser.Id, Name = "Theodor_2" });
505506

506507
var store4 = new DataStore(newFilePath);
@@ -576,18 +577,20 @@ public void ReplaceOne_Upsert_DynamicWithInnerData()
576577

577578
var collection = store.GetCollection("sensor");
578579

579-
var success = collection.ReplaceOne(e => e.id == 11, JToken.Parse("{ 'id': 11, 'mac': 'F4:A5:74:89:16:57', 'data': { 'temperature': 20.5 } }"), true);
580+
var success = collection.ReplaceOne(e => e.id == 11,
581+
JToken.Parse("{ 'id': 11, 'mac': 'F4:A5:74:89:16:57', 'data': { 'temperature': 20.5 } }"),
582+
true);
580583
Assert.True(success);
581584

582585
UTHelpers.Down(newFilePath);
583586
}
584-
587+
585588
[Fact]
586589
public async Task ReplaceOne_Upsert_Custom_Id_Dynamic()
587590
{
588591
var newFilePath = UTHelpers.Up();
589592

590-
var store = new DataStore(newFilePath, keyProperty:"CustomId");
593+
var store = new DataStore(newFilePath, keyProperty: "CustomId");
591594

592595
var collection = store.GetCollection("questions");
593596

@@ -596,23 +599,23 @@ public async Task ReplaceOne_Upsert_Custom_Id_Dynamic()
596599
CustomId = "54ccb8f2-5f2c-4cfa-b525-f0871eca787c",
597600
Name = "First_Tester"
598601
};
599-
602+
600603
var itemTwo = new
601604
{
602605
CustomId = "ee314079-7d18-405b-9bb7-9248c672b3f5",
603606
Name = "Second_Tester"
604607
};
605-
608+
606609
var success = await collection.ReplaceOneAsync(item.CustomId, item, true);
607610
Assert.True(success);
608-
611+
609612
success = await collection.ReplaceOneAsync(itemTwo.CustomId, itemTwo, true);
610613
Assert.True(success);
611-
614+
612615
var fromDb = collection.AsQueryable().SingleOrDefault(e => e.CustomId == itemTwo.CustomId);
613616
Assert.NotNull(fromDb);
614617
Assert.Equal("Second_Tester", fromDb.Name);
615-
618+
616619
UTHelpers.Down(newFilePath);
617620
}
618621

@@ -864,8 +867,8 @@ public void UpdateOne_InnerCollection_FromAndToNull_Typed()
864867
var collection = store.GetCollection<Family>();
865868

866869
var family = collection
867-
.Find(p => p.Id == 4)
868-
.First();
870+
.Find(p => p.Id == 4)
871+
.First();
869872

870873
Assert.Null(family.Children[1].Friends);
871874

@@ -881,8 +884,8 @@ public void UpdateOne_InnerCollection_FromAndToNull_Typed()
881884
var collection2 = store2.GetCollection<Family>();
882885

883886
var family_updated = collection2
884-
.Find(p => p.Id == 4)
885-
.First();
887+
.Find(p => p.Id == 4)
888+
.First();
886889

887890
Assert.Equal(originalCount, family_updated.Children[1].Friends.Count);
888891
Assert.Null(family_updated.Children[0].Friends);
@@ -900,8 +903,8 @@ public void UpdateOne_InnerCollection_FromAndToNull_Dynamic()
900903
var collection = store.GetCollection("family");
901904

902905
var family = collection
903-
.Find(p => p.id == 4)
904-
.First();
906+
.Find(p => p.id == 4)
907+
.First();
905908

906909
Assert.Null(family.children[1].friends);
907910

@@ -917,15 +920,15 @@ public void UpdateOne_InnerCollection_FromAndToNull_Dynamic()
917920
var collection2 = store2.GetCollection<Family>();
918921

919922
var family_updated = collection2
920-
.Find(p => p.Id == 4)
921-
.First();
923+
.Find(p => p.Id == 4)
924+
.First();
922925

923926
Assert.Equal(origCount, family_updated.Children[1].Friends.Count);
924927
Assert.Null(family_updated.Children[0].Friends);
925928

926929
UTHelpers.Down(newFilePath);
927930
}
928-
931+
929932
[Fact]
930933
public async Task UpdateInnerFloatArray_DynamicWorld()
931934
{
@@ -936,19 +939,19 @@ public async Task UpdateInnerFloatArray_DynamicWorld()
936939
var collection = store.GetCollection("worlds");
937940
Assert.Equal(1, collection.Count);
938941

939-
var original = collection.Find(e=> e.id == 0).First();
942+
var original = collection.Find(e => e.id == 0).First();
940943
Assert.Equal(3.6640577, original.position[0]);
941944

942945
await collection.UpdateOneAsync(e => e.id == 0, new { cameraRotationX = 5.2 });
943-
946+
944947
var collection2 = store.GetCollection("worlds");
945-
var updated = collection2.Find(e=> e.id == 0).First();
948+
var updated = collection2.Find(e => e.id == 0).First();
946949
Assert.Equal(5.2, updated.cameraRotationX);
947-
948-
await collection.UpdateOneAsync(e => e.id == 0, new { position = new float[] { 10, 11, 12 } } );
949-
950+
951+
await collection.UpdateOneAsync(e => e.id == 0, new { position = new float[] { 10, 11, 12 } });
952+
950953
var collection3 = store.GetCollection("worlds");
951-
var updated2 = collection3.Find(e=> e.id == 0).First();
954+
var updated2 = collection3.Find(e => e.id == 0).First();
952955
Assert.Equal(10, updated2.position[0]);
953956
Assert.Equal(11, updated2.position[1]);
954957
Assert.Equal(12, updated2.position[2]);
@@ -969,13 +972,13 @@ public async Task UpdateInnerFloatArray_TypedWorld()
969972
var original = collection.Find(e => e.Id == 0).First();
970973
Assert.InRange(original.Position[0], 3.66, 3.67);
971974

972-
await collection.UpdateOneAsync(e => e.Id == 0, new {CameraRotationX = 5.2f});
975+
await collection.UpdateOneAsync(e => e.Id == 0, new { CameraRotationX = 5.2f });
973976

974977
var collection2 = store.GetCollection<World>("worlds");
975978
var updated = collection2.Find(e => e.Id == 0).First();
976979
Assert.InRange(updated.CameraRotationX, 5.19, 5.2);
977980

978-
await collection.UpdateOneAsync(e => e.Id == 0, new {Position = new float[] {10, 11, 12}});
981+
await collection.UpdateOneAsync(e => e.Id == 0, new { Position = new float[] { 10, 11, 12 } });
979982

980983
var collection3 = store.GetCollection<World>("worlds");
981984
var updated2 = collection3.Find(e => e.Id == 0).First();

JsonFlatFileDataStore.Test/CollectionQueryTests.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using Newtonsoft.Json.Linq;
2-
using System.Linq;
1+
using System.Linq;
2+
using Newtonsoft.Json.Linq;
33
using Xunit;
44

55
namespace JsonFlatFileDataStore.Test
@@ -14,16 +14,16 @@ public void FindAndAsQueryable_Linq()
1414
var store = new DataStore(newFilePath);
1515

1616
var itemDynamic = store.GetCollection("user")
17-
.AsQueryable()
18-
.Single(p => p.name == "Phil");
17+
.AsQueryable()
18+
.Single(p => p.name == "Phil");
1919

2020
var itemTyped1 = store.GetCollection<User>()
21-
.AsQueryable()
22-
.Single(p => p.Name == "Phil");
21+
.AsQueryable()
22+
.Single(p => p.Name == "Phil");
2323

2424
var itemTyped2 = store.GetCollection<User>()
25-
.Find(p => p.Name == "Phil")
26-
.First();
25+
.Find(p => p.Name == "Phil")
26+
.First();
2727

2828
Assert.Equal("Phil", itemDynamic.name);
2929
Assert.Equal("Phil", itemTyped1.Name);
@@ -41,9 +41,9 @@ public void GetNextIdValue_IntegerId()
4141

4242
var collection = store.GetCollection("user");
4343
var lastItem = collection
44-
.AsQueryable()
45-
.OrderBy(e => e.id)
46-
.Last();
44+
.AsQueryable()
45+
.OrderBy(e => e.id)
46+
.Last();
4747

4848
Assert.Equal(3, lastItem.id);
4949

@@ -175,12 +175,12 @@ public void AsQueryable_DynamicAndTypedComplicatedModel()
175175
var store = new DataStore(newFilePath);
176176

177177
var itemDynamic = store.GetCollection("family")
178-
.AsQueryable()
179-
.Single(p => p.id == 12);
178+
.AsQueryable()
179+
.Single(p => p.id == 12);
180180

181181
var itemTyped = store.GetCollection<Family>()
182-
.Find(p => p.Id == 12)
183-
.First();
182+
.Find(p => p.Id == 12)
183+
.First();
184184

185185
Assert.Equal("Naomi", itemDynamic.parents[0].name);
186186
Assert.Equal("Naomi", itemTyped.Parents[0].Name);

JsonFlatFileDataStore.Test/CopyPropertiesTests.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
using Newtonsoft.Json;
2-
using Newtonsoft.Json.Linq;
3-
using System.Collections.Generic;
1+
using System.Collections.Generic;
42
using System.Collections.ObjectModel;
53
using System.Dynamic;
4+
using Newtonsoft.Json;
5+
using Newtonsoft.Json.Linq;
66
using Xunit;
77

88
namespace JsonFlatFileDataStore.Test
@@ -75,8 +75,8 @@ public void CopyProperties_TypedFamily()
7575
{
7676
Parents = new List<Parent>
7777
{
78-
new Parent { Name = "Jim", Age = 52 },
79-
new Parent { Name = "Theodor", Age = 14 }
78+
new Parent { Name = "Jim", Age = 52 },
79+
new Parent { Name = "Theodor", Age = 14 }
8080
},
8181
Address = new Address { City = "Helsinki" }
8282
};
@@ -230,7 +230,7 @@ public void CopyProperties_TypedFamilyParents()
230230
{
231231
Parents = new List<Parent>
232232
{
233-
new Parent { Name = "Jim", Age = 52 }
233+
new Parent { Name = "Jim", Age = 52 }
234234
},
235235
Address = new Address { City = "Helsinki" }
236236
};
@@ -294,7 +294,8 @@ public void CopyProperties_DynamicEmptyWithInnerDictionary()
294294
dynamic sensor = new ExpandoObject();
295295
sensor.mac = "F4:A5:74:89:16:57";
296296
sensor.timestamp = null;
297-
sensor.data = new Dictionary<string, object> {
297+
sensor.data = new Dictionary<string, object>
298+
{
298299
{ "temperature", 24.3 },
299300
{ "identifier", null }
300301
};

0 commit comments

Comments
 (0)