Skip to content

Various code cleanups in preparation of auto-formatting the codebase #960

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 61 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
af6b52d
Replaced null checks with argument guard
Feb 15, 2021
b9fd0ad
Added curlies on single-statement branches and loops
Feb 15, 2021
a082081
Normalize blank lines around SaveChangesAsync in tests
Feb 15, 2021
c87a996
use const
Feb 15, 2021
92eb963
Move types into matching files
Feb 15, 2021
952bcc5
Adapt namespaces to match with directory structure
Feb 15, 2021
36ea3fd
Fixed inconsistencies in naming conventions
Feb 15, 2021
2c26e60
Remove redundant parenthesis
Feb 15, 2021
4089e2c
Fixed culture-specific string comparisons
Feb 15, 2021
feaffab
Use newer syntax for dictionary initializers
Feb 17, 2021
e97cad2
Various additional cleanups
Feb 15, 2021
bf2cc20
Manual code cleanups in preparation for reformat
Feb 15, 2021
c564f9a
Extract variable on errors in tests to reduce assertion line length
Feb 17, 2021
b3aaae6
Hide decimal precision from tests
Feb 17, 2021
33cb16d
Rewrite ResponseStatusCode tests using Theory
Feb 17, 2021
3a7a0bc
Fixed naming inconsistencies in tests
Feb 17, 2021
b7d3f05
Replace FindAsync usage for consistency with other tests
Feb 17, 2021
9b9ba14
Added formatter directives on fakers
Feb 17, 2021
b93a8d5
Added formatter directives on DbContext types
Feb 17, 2021
01ffbb8
Added FirstWithIdAsync / FirstWithIdOrDefaultAsync to reduce line len…
Feb 18, 2021
f95b8e6
Added formatting directives on long database queries in tests
Feb 17, 2021
a1800d9
Reduced line length for links assertions
Feb 18, 2021
2091d07
Variable naming consistency
Feb 18, 2021
4fbadc6
Break up long strings to steer formatter
Feb 17, 2021
6a9174c
Extract constant
Feb 19, 2021
d0bfb0b
cleanup method
Feb 22, 2021
2adff3c
Fixed naming conventions
Feb 19, 2021
9b544c8
Additional cleanup based on suggestions from https://docs.microsoft.c…
Feb 19, 2021
72f3630
Use helpers to prevent multiple line breaks in array and list initial…
Feb 23, 2021
5a8ff06
Corrected link rendering for hosting inside an IIS application vdir (…
Feb 23, 2021
de03aba
Update version from 4.0.3 to 4.0.4
Feb 23, 2021
2ca3086
Marked types/members sealed/internal where non-breaking
Feb 24, 2021
7ca1aa2
Removed redundancies in code
Feb 24, 2021
f394102
remove unused tuple elements
Feb 25, 2021
66c8e9c
Fixed spelling in comments
Feb 25, 2021
1792982
Added formatter directive to ErrorDocumentTests to prevent array chop
Feb 25, 2021
accf050
Added [UsedImplicitly] on DbContext classes to suppress suggestions l…
Feb 24, 2021
b5383af
Added [UsedImplicitly] on resource services, repositories, definition…
Feb 24, 2021
61bf587
Added [UsedImplicitly] on models
Feb 24, 2021
3fdcf85
Use discard in empty property setters
Feb 24, 2021
af9738d
Added missing setter
Feb 24, 2021
3b66bf7
Addressed possible NullReferenceException warnings
Feb 24, 2021
874ee0f
Marked assertion methods as such, to suppress warning 'parameter is o…
Feb 24, 2021
d0b3114
Addressed possible multiple enumeration warnings
Feb 24, 2021
ea9b2e5
Suppressed warnings on non-readonly member access in GetHashCode, bec…
Feb 25, 2021
379dbcf
extra: UsedImplicitly on models
Feb 25, 2021
2a3274d
Added [PublicAPI] on exposed types to suppress warnings like 'type/me…
Feb 25, 2021
7f1b533
Cleanup Startups
Feb 25, 2021
4ae214c
BenchmarkDotNet runners cannot be sealed
Feb 25, 2021
e855311
Suppress cases of unused TResource type parameter, because we registe…
Feb 25, 2021
d23df0e
Additional cleanup and annotations based on warnings and suggestions
Feb 25, 2021
e638822
AV1755: Async method name should end with [Task]Async
Feb 27, 2021
af6955c
AV1739: Use underscores for unused lambda parameters
Feb 27, 2021
324fe4a
AV1568: Parameter value is overwritten in method body
Feb 27, 2021
c5dd918
AV1535: Block scope in case clauses
Feb 27, 2021
f7b0e2b
AV1522: Multiple assignments in single statement
Feb 27, 2021
4011ec6
AV1532: Avoid nested loops
Mar 2, 2021
a0bf005
AV1010: Member hides inherited member
Mar 2, 2021
14468b5
AV1130: Use collection interface as return type
Mar 2, 2021
6a3e910
Fixed: Without the [CustomAssertion] attribute, Fluent Assertions wou…
Mar 3, 2021
0fa7142
Merge branch 'master' into coding-guidelines-4
Mar 3, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
14 changes: 2 additions & 12 deletions benchmarks/BenchmarkResource.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using JetBrains.Annotations;
using JsonApiDotNetCore.Resources;
using JsonApiDotNetCore.Resources.Annotations;

namespace Benchmarks
{
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
public sealed class BenchmarkResource : Identifiable
{
[Attr(PublicName = BenchmarkResourcePublicNames.NameAttr)]
Expand All @@ -11,16 +13,4 @@ public sealed class BenchmarkResource : Identifiable
[HasOne]
public SubResource Child { get; set; }
}

public class SubResource : Identifiable
{
[Attr]
public string Value { get; set; }
}

internal static class BenchmarkResourcePublicNames
{
public const string NameAttr = "full-name";
public const string Type = "simple-types";
}
}
8 changes: 8 additions & 0 deletions benchmarks/BenchmarkResourcePublicNames.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Benchmarks
{
internal static class BenchmarkResourcePublicNames
{
public const string NameAttr = "full-name";
public const string Type = "simple-types";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Benchmarks.LinkBuilder
{
// ReSharper disable once ClassCanBeSealed.Global
[MarkdownExporter, SimpleJob(launchCount: 3, warmupCount: 10, targetCount: 20), MemoryDiagnoser]
public class LinkBuilderGetNamespaceFromPathBenchmarks
{
Expand All @@ -17,7 +18,7 @@ public class LinkBuilderGetNamespaceFromPathBenchmarks
[Benchmark]
public void UsingReadOnlySpan() => GetNamespaceFromPathUsingReadOnlySpan(RequestPath, ResourceName);

public static string GetNamespaceFromPathUsingStringSplit(string path, string resourceName)
private static void GetNamespaceFromPathUsingStringSplit(string path, string resourceName)
{
StringBuilder namespaceBuilder = new StringBuilder(path.Length);
string[] segments = path.Split('/');
Expand All @@ -33,10 +34,10 @@ public static string GetNamespaceFromPathUsingStringSplit(string path, string re
namespaceBuilder.Append(segments[index]);
}

return namespaceBuilder.ToString();
_ = namespaceBuilder.ToString();
}

public static string GetNamespaceFromPathUsingReadOnlySpan(string path, string resourceName)
private static void GetNamespaceFromPathUsingReadOnlySpan(string path, string resourceName)
{
ReadOnlySpan<char> resourceNameSpan = resourceName.AsSpan();
ReadOnlySpan<char> pathSpan = path.AsSpan();
Expand All @@ -57,14 +58,12 @@ public static string GetNamespaceFromPathUsingReadOnlySpan(string path, string r
bool hasDelimiterAfterSegment = pathSpan.Length >= lastCharacterIndex + 1 && pathSpan[lastCharacterIndex].Equals(PathDelimiter);
if (isAtEnd || hasDelimiterAfterSegment)
{
return pathSpan.Slice(0, index).ToString();
_ = pathSpan.Slice(0, index).ToString();
}
}
}
}
}

return string.Empty;
}
}
}
2 changes: 1 addition & 1 deletion benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Benchmarks
{
internal class Program
internal static class Program
{
private static void Main(string[] args)
{
Expand Down
25 changes: 13 additions & 12 deletions benchmarks/Query/QueryParserBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using BenchmarkDotNet.Attributes;
using JsonApiDotNetCore;
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Middleware;
using JsonApiDotNetCore.QueryStrings;
Expand All @@ -13,6 +13,7 @@

namespace Benchmarks.Query
{
// ReSharper disable once ClassCanBeSealed.Global
[MarkdownExporter, SimpleJob(launchCount: 3, warmupCount: 10, targetCount: 20), MemoryDiagnoser]
public class QueryParserBenchmarks
{
Expand Down Expand Up @@ -43,11 +44,8 @@ private static QueryStringReader CreateQueryParameterDiscoveryForSort(IResourceG
JsonApiRequest request, IJsonApiOptions options, FakeRequestQueryStringAccessor queryStringAccessor)
{
var sortReader = new SortQueryStringParameterReader(request, resourceGraph);

var readers = new List<IQueryStringParameterReader>
{
sortReader
};

var readers = sortReader.AsEnumerable();

return new QueryStringReader(options, queryStringAccessor, readers, NullLoggerFactory.Instance);
}
Expand All @@ -65,10 +63,7 @@ private static QueryStringReader CreateQueryParameterDiscoveryForAll(IResourceGr
var defaultsReader = new DefaultsQueryStringParameterReader(options);
var nullsReader = new NullsQueryStringParameterReader(options);

var readers = new List<IQueryStringParameterReader>
{
includeReader, filterReader, sortReader, sparseFieldSetReader, paginationReader, defaultsReader, nullsReader
};
var readers = ArrayFactory.Create<IQueryStringParameterReader>(includeReader, filterReader, sortReader, sparseFieldSetReader, paginationReader, defaultsReader, nullsReader);

return new QueryStringReader(options, queryStringAccessor, readers, NullLoggerFactory.Instance);
}
Expand All @@ -94,15 +89,21 @@ public void DescendingSort()
[Benchmark]
public void ComplexQuery() => Run(100, () =>
{
var queryString = $"?filter[{BenchmarkResourcePublicNames.NameAttr}]=abc,eq:abc&sort=-{BenchmarkResourcePublicNames.NameAttr}&include=child&page[size]=1&fields[{BenchmarkResourcePublicNames.Type}]={BenchmarkResourcePublicNames.NameAttr}";
const string resourceName = BenchmarkResourcePublicNames.Type;
const string attrName = BenchmarkResourcePublicNames.NameAttr;

var queryString = $"?filter[{attrName}]=abc,eq:abc&sort=-{attrName}&include=child&page[size]=1&fields[{resourceName}]={attrName}";

_queryStringAccessor.SetQueryString(queryString);
_queryStringReaderForAll.ReadAll(null);
});

private void Run(int iterations, Action action) {
private void Run(int iterations, Action action)
{
for (int i = 0; i < iterations; i++)
{
action();
}
}

private sealed class FakeRequestQueryStringAccessor : IRequestQueryStringAccessor
Expand Down
11 changes: 6 additions & 5 deletions benchmarks/Serialization/JsonApiDeserializerBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Benchmarks.Serialization
{
// ReSharper disable once ClassCanBeSealed.Global
[MarkdownExporter]
public class JsonApiDeserializerBenchmarks
{
Expand All @@ -23,10 +24,7 @@ public class JsonApiDeserializerBenchmarks
Id = "1",
Attributes = new Dictionary<string, object>
{
{
"name",
Guid.NewGuid().ToString()
}
["name"] = Guid.NewGuid().ToString()
}
}
});
Expand All @@ -39,7 +37,10 @@ public JsonApiDeserializerBenchmarks()
IResourceGraph resourceGraph = DependencyFactory.CreateResourceGraph(options);
var targetedFields = new TargetedFields();
var request = new JsonApiRequest();
_jsonApiDeserializer = new RequestDeserializer(resourceGraph, new ResourceFactory(new ServiceContainer()), targetedFields, new HttpContextAccessor(), request, options);
var resourceFactory = new ResourceFactory(new ServiceContainer());
var httpContextAccessor = new HttpContextAccessor();

_jsonApiDeserializer = new RequestDeserializer(resourceGraph, resourceFactory, targetedFields, httpContextAccessor, request, options);
}

[Benchmark]
Expand Down
5 changes: 3 additions & 2 deletions benchmarks/Serialization/JsonApiSerializerBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@

namespace Benchmarks.Serialization
{
// ReSharper disable once ClassCanBeSealed.Global
[MarkdownExporter]
public class JsonApiSerializerBenchmarks
{
private static readonly BenchmarkResource _content = new BenchmarkResource
private static readonly BenchmarkResource Content = new BenchmarkResource
{
Id = 123,
Name = Guid.NewGuid().ToString()
Expand Down Expand Up @@ -53,6 +54,6 @@ private static FieldsToSerialize CreateFieldsToSerialize(IResourceGraph resource
}

[Benchmark]
public object SerializeSimpleObject() => _jsonApiSerializer.Serialize(_content);
public object SerializeSimpleObject() => _jsonApiSerializer.Serialize(Content);
}
}
13 changes: 13 additions & 0 deletions benchmarks/SubResource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using JetBrains.Annotations;
using JsonApiDotNetCore.Resources;
using JsonApiDotNetCore.Resources.Annotations;

namespace Benchmarks
{
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
public sealed class SubResource : Identifiable
{
[Attr]
public string Value { get; set; }
}
}
2 changes: 2 additions & 0 deletions src/Examples/GettingStarted/Data/SampleDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using GettingStarted.Models;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;

namespace GettingStarted.Data
{
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
public class SampleDbContext : DbContext
{
public DbSet<Book> Books { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions src/Examples/GettingStarted/Models/Book.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using JetBrains.Annotations;
using JsonApiDotNetCore.Resources;
using JsonApiDotNetCore.Resources.Annotations;

namespace GettingStarted.Models
{
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
public sealed class Book : Identifiable
{
[Attr]
Expand Down
2 changes: 2 additions & 0 deletions src/Examples/GettingStarted/Models/Person.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Collections.Generic;
using JetBrains.Annotations;
using JsonApiDotNetCore.Resources;
using JsonApiDotNetCore.Resources.Annotations;

namespace GettingStarted.Models
{
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
public sealed class Person : Identifiable
{
[Attr]
Expand Down
4 changes: 2 additions & 2 deletions src/Examples/GettingStarted/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

namespace GettingStarted
{
public class Program
internal static class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
private static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
Expand Down
2 changes: 2 additions & 0 deletions src/Examples/GettingStarted/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using GettingStarted.Data;
using GettingStarted.Models;
using JetBrains.Annotations;
using JsonApiDotNetCore.Configuration;
using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore;
Expand Down Expand Up @@ -27,6 +28,7 @@ public void ConfigureServices(IServiceCollection services)
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
[UsedImplicitly]
public void Configure(IApplicationBuilder app, SampleDbContext context)
{
context.Database.EnsureDeleted();
Expand Down
6 changes: 5 additions & 1 deletion src/Examples/JsonApiDotNetCoreExample/Data/AppDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using JetBrains.Annotations;
using JsonApiDotNetCoreExample.Models;
using Microsoft.EntityFrameworkCore;

// @formatter:wrap_chained_method_calls chop_always

namespace JsonApiDotNetCoreExample.Data
{
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
public sealed class AppDbContext : DbContext
{
public DbSet<TodoItem> TodoItems { get; set; }
Expand Down Expand Up @@ -37,7 +41,7 @@ protected override void OnModelCreating(ModelBuilder builder)
.OnDelete(DeleteBehavior.Cascade);

builder.Entity<TodoItem>()
.HasMany(t => t.ChildrenTodos)
.HasMany(t => t.ChildTodoItems)
.WithOne(t => t.ParentTodo);

builder.Entity<Passport>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;
using JetBrains.Annotations;
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Errors;
using JsonApiDotNetCore.Hooks.Internal.Execution;
Expand All @@ -10,7 +11,8 @@

namespace JsonApiDotNetCoreExample.Definitions
{
public class ArticleHooksDefinition : ResourceHooksDefinition<Article>
[UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)]
public sealed class ArticleHooksDefinition : ResourceHooksDefinition<Article>
{
public ArticleHooksDefinition(IResourceGraph resourceGraph) : base(resourceGraph) { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ protected void DisallowLocked(IEnumerable<T> resources)
{
throw new JsonApiException(new Error(HttpStatusCode.Forbidden)
{
Title = $"You are not allowed to update fields or relationships of locked resource of type '{_resourceGraph.GetResourceContext<T>().PublicName}'."
Title = "You are not allowed to update fields or relationships of " +
$"locked resource of type '{_resourceGraph.GetResourceContext<T>().PublicName}'."
});
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;
using JetBrains.Annotations;
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Errors;
using JsonApiDotNetCore.Hooks.Internal.Execution;
Expand All @@ -9,7 +10,8 @@

namespace JsonApiDotNetCoreExample.Definitions
{
public class PassportHooksDefinition : LockableHooksDefinition<Passport>
[UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)]
public sealed class PassportHooksDefinition : LockableHooksDefinition<Passport>
{
public PassportHooksDefinition(IResourceGraph resourceGraph) : base(resourceGraph)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Hooks.Internal.Execution;
using JsonApiDotNetCoreExample.Models;

namespace JsonApiDotNetCoreExample.Definitions
{
public class PersonHooksDefinition : LockableHooksDefinition<Person>
[UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)]
public sealed class PersonHooksDefinition : LockableHooksDefinition<Person>
{
public PersonHooksDefinition(IResourceGraph resourceGraph) : base(resourceGraph) { }

Expand Down
Loading