Skip to content

Code cleanup #691

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 74 commits into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
e89c2d1
Fixed: XML comment is not placed on a valid language element
Feb 14, 2020
8fb115f
Fixed: Convert to method group
Feb 14, 2020
4100e7d
Fixed: Use null propagation
Feb 14, 2020
8c70342
Fixed: Use string interpolation expression
Feb 14, 2020
b04cadd
Fixed: Use lambda expression
Feb 14, 2020
56d200b
Fixed: Convert to compound assignment
Feb 14, 2020
a2a0f5a
Fixed: Convert to 'using' declaration
Feb 14, 2020
2f23e13
Fixed: Use 'await using'
Feb 14, 2020
53c0a08
Fixed: Convert to '?:' expression
Feb 14, 2020
fd932c0
Fixed: Merge conditional expression
Feb 14, 2020
2e17fe7
Fixed: Use object initializer
Feb 14, 2020
5db43f6
Fixed: Qualifier is redundant
Feb 14, 2020
fd783ef
Fixed: Using directive is not required by the code and can be safely …
Feb 14, 2020
340d34d
Fixed: Redundant explicit array type specification
Feb 14, 2020
a2617d1
Fixed: Type argument specification is redundant
Feb 14, 2020
87773a4
Fixed: Comparison with true is redundant
Feb 14, 2020
b6a9956
Fixed: Redundant string interpolation
Feb 14, 2020
2e8aa9f
Fixed: Conditional access qualifier expression is known to be not null
Feb 14, 2020
ec1974a
Fixed: Empty object or collection initializer list is redundant
Feb 14, 2020
143139b
Fixed: Redundant explicit array creation in argument of 'params' para…
Feb 14, 2020
3258c0f
Fixed: Type cast is redundant
Feb 14, 2020
3d12105
Fixed: The parameter {name} has the same default value
Feb 14, 2020
50f8c1a
Fixed: Empty argument list is redundant
Feb 14, 2020
ea572a1
Fixed: Expression is always null
Feb 14, 2020
889ea3d
Fixed: Value assigned is not used in any execution path
Feb 14, 2020
b7cb5be
Fixed: Redundant 'IEnumerable.Cast<T>' call
Feb 14, 2020
6fce99d
Fixed: '??' right operand is always null
Feb 14, 2020
aaad695
Fixed: Redundant 'Object.ToString()' call
Feb 14, 2020
dc1a2b1
Fixed: Qualifier 'base.' is redundant
Feb 14, 2020
09ea66e
Fixed: The field is always assigned before being used and can be conv…
Feb 14, 2020
dc2dc11
Fixed: Merge cast with type check
Feb 14, 2020
c065f8a
Fixed: Replace with single call to First(..)
Feb 17, 2020
b84797b
Fixed: Replace 'Enumerable.Count()' invocation with collection count …
Feb 17, 2020
67ae0e8
Fixed: Use format specifier
Feb 17, 2020
6c8c20c
Fixed: Field is assigned but its value is never used
Feb 17, 2020
77d93d4
Fixed: Field can be made readonly
Feb 17, 2020
56e81b2
Fixed: Redundant method override
Feb 17, 2020
0685677
Fixed: Method is never used
Feb 17, 2020
2124c2c
Fixed: Base interface is redundant
Feb 17, 2020
89df3a8
Fixed: Field is never used
Feb 17, 2020
46bafaa
Fixed: Local variable is never used
Feb 17, 2020
0127ee4
Fixed: Method return value is never used
Feb 17, 2020
705882e
Fixed: Constructor is never used
Feb 17, 2020
8b1d50a
Fixed: shared instance is never used
Feb 17, 2020
ddc43d6
Fixed: Parameter is never used
Feb 17, 2020
e654fb1
Fixed: Method is never used
Feb 17, 2020
a2fe29c
Fixed: Initializing field/property by default value is redundant
Feb 17, 2020
d1a6203
Fixed: Redundant base constructor call
Feb 17, 2020
631871e
Fixed: parameter hides outer local variable with the same name
Feb 17, 2020
9d1fd2e
Fixed: Cannot resolve symbol 'dynamic'
Feb 17, 2020
428a182
Fixed: Possible unintended reference comparison
Feb 17, 2020
2c0321a
Fixed: Co-variant array conversion can cause run-time exception on wr…
Feb 17, 2020
87fb6ff
Fixed: Return value of pure method is not used
Feb 17, 2020
17134f8
Fixed: Auto-property can be made get-only
Feb 17, 2020
dbf8cbf
Fixed: Inconsistent body style: use expression-bodied property
Feb 17, 2020
243f82f
Fixed: Empty statement is redundant
Feb 17, 2020
d4938d5
Fixed: Local variable can be declared in inner scope
Feb 17, 2020
b9d70e8
Fixed: Join declaration and assignment
Feb 17, 2020
4d83cc3
Fixed: Convert constructor to protected in abstract class
Feb 17, 2020
51dd093
Fixed: Replace with single call to FirstOrDefault/Count
Feb 17, 2020
bea8731
Fixed: Use single deconstruction declaration
Feb 17, 2020
995e114
Fixed: Removed unused using directives
Feb 17, 2020
9a1e4b3
Fixed a few obvious naming violations
Feb 17, 2020
6964ca3
Fixed: Virtual member that is never overridden
Feb 17, 2020
f0d7c4f
Removed DefaultPageSize/RequestedPageSize from IPageService because w…
Feb 17, 2020
a50ab4d
Fixed: Initializing property by default value is redundant
Feb 17, 2020
e874f42
Reduced accessibility for some non-public types/members
Feb 17, 2020
9a3ae13
Fixed: missing checkbox in Solution Configuration Manager
Feb 17, 2020
1771ebd
Made non-public (and a few public) types sealed
Feb 17, 2020
e96260f
Fixed: Inconsistent modifiers style
Feb 17, 2020
f20d1e9
Removed reference to xunit from benchmarks project, so that 'dotnet t…
Feb 17, 2020
dd10241
Empty commit to retry cibuild
Feb 17, 2020
d5bdb8b
Merge branch 'master' into code-cleanup
maurei Mar 24, 2020
7284204
Update IQueryableExtensions.cs
maurei Mar 24, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions JsonApiDotnetCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Global
{DF0FCFB2-CB12-44BA-BBB5-1BE0BCFCD14C}.Debug|x86.ActiveCfg = Debug|Any CPU
{DF0FCFB2-CB12-44BA-BBB5-1BE0BCFCD14C}.Debug|x86.Build.0 = Debug|Any CPU
{DF0FCFB2-CB12-44BA-BBB5-1BE0BCFCD14C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DF0FCFB2-CB12-44BA-BBB5-1BE0BCFCD14C}.Release|Any CPU.Build.0 = Release|Any CPU
{DF0FCFB2-CB12-44BA-BBB5-1BE0BCFCD14C}.Release|x64.ActiveCfg = Release|Any CPU
{DF0FCFB2-CB12-44BA-BBB5-1BE0BCFCD14C}.Release|x64.Build.0 = Release|Any CPU
{DF0FCFB2-CB12-44BA-BBB5-1BE0BCFCD14C}.Release|x86.ActiveCfg = Release|Any CPU
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/BenchmarkResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Benchmarks
{
public class BenchmarkResource : Identifiable
public sealed class BenchmarkResource : Identifiable
{
[Attr(BenchmarkResourcePublicNames.NameAttr)]
public string Name { get; set; }
Expand All @@ -17,7 +17,7 @@ public class SubResource : Identifiable
public string Value { get; set; }
}

public static class BenchmarkResourcePublicNames
internal static class BenchmarkResourcePublicNames
{
public const string NameAttr = "full-name";
public const string Type = "simple-types";
Expand Down
1 change: 0 additions & 1 deletion benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.0" />
<PackageReference Include="moq" Version="$(MoqVersion)" />
<PackageReference Include="xunit" Version="$(xUnitVersion)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../src/JsonApiDotNetCore/JsonApiDotNetCore.csproj" />
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

namespace Benchmarks
{
class Program
internal class Program
{
static void Main(string[] args)
private static void Main(string[] args)
{
var switcher = new BenchmarkSwitcher(new[]
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace GettingStarted
{
public class ArticlesController : JsonApiController<Article>
public sealed class ArticlesController : JsonApiController<Article>
{
public ArticlesController(
IJsonApiOptions jsonApiOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace GettingStarted
{
public class PeopleController : JsonApiController<Person>
public sealed class PeopleController : JsonApiController<Person>
{
public PeopleController(
IJsonApiOptions jsonApiOptions,
Expand Down
4 changes: 2 additions & 2 deletions src/Examples/GettingStarted/Models/Article.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace GettingStarted.Models
{
public class Article : Identifiable
public sealed class Article : Identifiable
{
[Attr]
public string Title { get; set; }
[HasOne]
public Person Author { get; set; }
public int AuthorId { get; set; }
}
}
}
4 changes: 2 additions & 2 deletions src/Examples/GettingStarted/Models/Person.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

namespace GettingStarted.Models
{
public class Person : Identifiable
public sealed class Person : Identifiable
{
[Attr]
public string Name { get; set; }
[HasMany]
public List<Article> Articles { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace GettingStarted.ResourceDefinitionExample
{
public class Model : Identifiable
public sealed class Model : Identifiable
{
[Attr]
public string DoNotExpose { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Collections.Generic;
using JsonApiDotNetCore.Internal.Contracts;
using JsonApiDotNetCore.Models;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace GettingStarted.ResourceDefinitionExample
{
public class ModelsController : JsonApiController<Model>
public sealed class ModelsController : JsonApiController<Model>
{
public ModelsController(
IJsonApiOptions jsonApiOptions,
Expand Down
2 changes: 1 addition & 1 deletion src/Examples/GettingStarted/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace GettingStarted
{
public class Startup
public sealed class Startup
{
public void ConfigureServices(IServiceCollection services)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace JsonApiDotNetCoreExample.Controllers
{
public class ArticlesController : JsonApiController<Article>
public sealed class ArticlesController : JsonApiController<Article>
{
public ArticlesController(
IJsonApiOptions jsonApiOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace JsonApiDotNetCoreExample.Controllers
{
public class KebabCasedModelsController : JsonApiController<KebabCasedModel>
public sealed class KebabCasedModelsController : JsonApiController<KebabCasedModel>
{
public KebabCasedModelsController(
IJsonApiOptions jsonApiOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace JsonApiDotNetCoreExample.Controllers
{
public class PassportsController : JsonApiController<Passport>
public sealed class PassportsController : JsonApiController<Passport>
{
public PassportsController(
IJsonApiOptions jsonApiOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace JsonApiDotNetCoreExample.Controllers
{
public class PeopleController : JsonApiController<Person>
public sealed class PeopleController : JsonApiController<Person>
{
public PeopleController(
IJsonApiOptions jsonApiOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace JsonApiDotNetCoreExample.Controllers
{
public class PersonRolesController : JsonApiController<PersonRole>
public sealed class PersonRolesController : JsonApiController<PersonRole>
{
public PersonRolesController(
IJsonApiOptions jsonApiOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace JsonApiDotNetCoreExample.Controllers
{
public class TagsController : JsonApiController<Tag>
public sealed class TagsController : JsonApiController<Tag>
{
public TagsController(
IJsonApiOptions jsonApiOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class TestValuesController : ControllerBase
[HttpGet]
public IActionResult Get()
{
var result = new string[] { "value" };
var result = new[] { "value" };
return Ok(result);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

namespace JsonApiDotNetCoreExample.Controllers
{
public class TodoCollectionsController : JsonApiController<TodoItemCollection, Guid>
public sealed class TodoCollectionsController : JsonApiController<TodoItemCollection, Guid>
{
readonly IDbContextResolver _dbResolver;
private readonly IDbContextResolver _dbResolver;

public TodoCollectionsController(
IJsonApiOptions jsonApiOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace JsonApiDotNetCoreExample.Controllers
{
public class TodoItemsController : JsonApiController<TodoItem>
public sealed class TodoItemsController : JsonApiController<TodoItem>
{
public TodoItemsController(
IJsonApiOptions jsonApiOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,28 @@ public CustomJsonApiController(
IJsonApiOptions options,
IResourceService<T, int> resourceService,
ILoggerFactory loggerFactory)
: base(options, resourceService, loggerFactory)
: base(options, resourceService)
{
}
}

public class CustomJsonApiController<T, TId>
: ControllerBase where T : class, IIdentifiable<TId>
{
private readonly ILogger _logger;
private readonly IJsonApiOptions _options;
private readonly IResourceService<T, TId> _resourceService;

protected IActionResult Forbidden()
private IActionResult Forbidden()
{
return new StatusCodeResult(403);
}

public CustomJsonApiController(
IJsonApiOptions options,
IResourceService<T, TId> resourceService,
ILoggerFactory loggerFactory)
IResourceService<T, TId> resourceService)
{
_options = options;
_resourceService = resourceService;
_logger = loggerFactory.CreateLogger<JsonApiController<T, TId>>();
}

public CustomJsonApiController(
Expand All @@ -62,14 +59,14 @@ public CustomJsonApiController(
}

[HttpGet]
public virtual async Task<IActionResult> GetAsync()
public async Task<IActionResult> GetAsync()
{
var entities = await _resourceService.GetAsync();
return Ok(entities);
}

[HttpGet("{id}")]
public virtual async Task<IActionResult> GetAsync(TId id)
public async Task<IActionResult> GetAsync(TId id)
{
var entity = await _resourceService.GetAsync(id);

Expand All @@ -80,7 +77,7 @@ public virtual async Task<IActionResult> GetAsync(TId id)
}

[HttpGet("{id}/relationships/{relationshipName}")]
public virtual async Task<IActionResult> GetRelationshipsAsync(TId id, string relationshipName)
public async Task<IActionResult> GetRelationshipsAsync(TId id, string relationshipName)
{
var relationship = _resourceService.GetRelationshipAsync(id, relationshipName);
if (relationship == null)
Expand All @@ -90,14 +87,14 @@ public virtual async Task<IActionResult> GetRelationshipsAsync(TId id, string re
}

[HttpGet("{id}/{relationshipName}")]
public virtual async Task<IActionResult> GetRelationshipAsync(TId id, string relationshipName)
public async Task<IActionResult> GetRelationshipAsync(TId id, string relationshipName)
{
var relationship = await _resourceService.GetRelationshipAsync(id, relationshipName);
return Ok(relationship);
}

[HttpPost]
public virtual async Task<IActionResult> PostAsync([FromBody] T entity)
public async Task<IActionResult> PostAsync([FromBody] T entity)
{
if (entity == null)
return UnprocessableEntity();
Expand All @@ -111,7 +108,7 @@ public virtual async Task<IActionResult> PostAsync([FromBody] T entity)
}

[HttpPatch("{id}")]
public virtual async Task<IActionResult> PatchAsync(TId id, [FromBody] T entity)
public async Task<IActionResult> PatchAsync(TId id, [FromBody] T entity)
{
if (entity == null)
return UnprocessableEntity();
Expand All @@ -125,14 +122,14 @@ public virtual async Task<IActionResult> PatchAsync(TId id, [FromBody] T entity)
}

[HttpPatch("{id}/relationships/{relationshipName}")]
public virtual async Task<IActionResult> PatchRelationshipsAsync(TId id, string relationshipName, [FromBody] List<ResourceObject> relationships)
public async Task<IActionResult> PatchRelationshipsAsync(TId id, string relationshipName, [FromBody] List<ResourceObject> relationships)
{
await _resourceService.UpdateRelationshipsAsync(id, relationshipName, relationships);
return Ok();
}

[HttpDelete("{id}")]
public virtual async Task<IActionResult> DeleteAsync(TId id)
public async Task<IActionResult> DeleteAsync(TId id)
{
var wasDeleted = await _resourceService.DeleteAsync(id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace JsonApiDotNetCoreExample.Controllers
{
public class UsersController : JsonApiController<User>
public sealed class UsersController : JsonApiController<User>
{
public UsersController(
IJsonApiOptions jsonApiOptions,
Expand All @@ -16,7 +16,7 @@ public UsersController(
{ }
}

public class SuperUsersController : JsonApiController<SuperUser>
public sealed class SuperUsersController : JsonApiController<SuperUser>
{
public SuperUsersController(
IJsonApiOptions jsonApiOptions,
Expand Down
2 changes: 1 addition & 1 deletion src/Examples/JsonApiDotNetCoreExample/Data/AppDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace JsonApiDotNetCoreExample.Data
{
public class AppDbContext : DbContext
public sealed class AppDbContext : DbContext
{
public DbSet<TodoItem> TodoItems { get; set; }
public DbSet<Passport> Passports { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/Examples/JsonApiDotNetCoreExample/Models/Article.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace JsonApiDotNetCoreExample.Models
{
public class Article : Identifiable
public sealed class Article : Identifiable
{
[Attr]
public string Name { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions src/Examples/JsonApiDotNetCoreExample/Models/ArticleTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace JsonApiDotNetCoreExample.Models
{
public class ArticleTag
public sealed class ArticleTag
{
public int ArticleId { get; set; }
public Article Article { get; set; }
Expand All @@ -24,4 +24,4 @@ public class IdentifiableArticleTag : Identifiable

public string SomeMetaData { get; set; }
}
}
}
2 changes: 1 addition & 1 deletion src/Examples/JsonApiDotNetCoreExample/Models/Author.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace JsonApiDotNetCoreExample.Models
{
public class Author : Identifiable
public sealed class Author : Identifiable
{
[Attr]
public string Name { get; set; }
Expand Down
10 changes: 5 additions & 5 deletions src/Examples/JsonApiDotNetCoreExample/Models/Passport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace JsonApiDotNetCoreExample.Models
{
public class Passport : Identifiable
public sealed class Passport : Identifiable
{
public virtual int? SocialSecurityNumber { get; set; }
public virtual bool IsLocked { get; set; }
public int? SocialSecurityNumber { get; set; }
public bool IsLocked { get; set; }

[HasOne]
public virtual Person Person { get; set; }
public Person Person { get; set; }
}
}
}
Loading