Skip to content

Commit

Permalink
Update formatting rules to place call to base in primary constructor …
Browse files Browse the repository at this point in the history
…on separate line
  • Loading branch information
bkoelman committed Sep 26, 2024
1 parent 9648cde commit 51d2e49
Show file tree
Hide file tree
Showing 101 changed files with 264 additions and 175 deletions.
1 change: 1 addition & 0 deletions JsonApiDotNetCore.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ JsonApiDotNetCore.ArgumentGuard.NotNull($EXPR$);</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_ACCESSORHOLDER_ATTRIBUTE_ON_SAME_LINE_EX/@EntryValue">NEVER</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_CONSTRUCTOR_INITIALIZER_ON_SAME_LINE/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_FIELD_ATTRIBUTE_ON_SAME_LINE_EX/@EntryValue">NEVER</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_PRIMARY_CONSTRUCTOR_INITIALIZER_ON_SAME_LINE/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_ACCESSOR_ON_SINGLE_LINE/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_ANONYMOUSMETHOD_ON_SINGLE_LINE/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_EMBEDDED_STATEMENT_ON_SAME_LINE/@EntryValue">NEVER</s:String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ namespace DapperExample.Controllers;

public sealed class OperationsController(
IJsonApiOptions options, IResourceGraph resourceGraph, ILoggerFactory loggerFactory, IOperationsProcessor processor, IJsonApiRequest request,
ITargetedFields targetedFields, IAtomicOperationFilter operationFilter) : JsonApiOperationsController(options, resourceGraph, loggerFactory, processor,
request, targetedFields, operationFilter);
ITargetedFields targetedFields, IAtomicOperationFilter operationFilter)
: JsonApiOperationsController(options, resourceGraph, loggerFactory, processor, request, targetedFields, operationFilter);
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

namespace DapperExample.TranslationToSql.Builders;

internal sealed class DeleteOneToOneStatementBuilder(IDataModelService dataModelService) : StatementBuilder(dataModelService)
internal sealed class DeleteOneToOneStatementBuilder(IDataModelService dataModelService)
: StatementBuilder(dataModelService)
{
public DeleteNode Build(ResourceType resourceType, string whereColumnName, object? whereValue)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

namespace DapperExample.TranslationToSql.Builders;

internal sealed class DeleteResourceStatementBuilder(IDataModelService dataModelService) : StatementBuilder(dataModelService)
internal sealed class DeleteResourceStatementBuilder(IDataModelService dataModelService)
: StatementBuilder(dataModelService)
{
public DeleteNode Build(ResourceType resourceType, params object[] idValues)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

namespace DapperExample.TranslationToSql.Builders;

internal sealed class InsertStatementBuilder(IDataModelService dataModelService) : StatementBuilder(dataModelService)
internal sealed class InsertStatementBuilder(IDataModelService dataModelService)
: StatementBuilder(dataModelService)
{
public InsertNode Build(ResourceType resourceType, IReadOnlyDictionary<string, object?> columnsToSet)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

namespace DapperExample.TranslationToSql.Builders;

internal sealed class UpdateClearOneToOneStatementBuilder(IDataModelService dataModelService) : StatementBuilder(dataModelService)
internal sealed class UpdateClearOneToOneStatementBuilder(IDataModelService dataModelService)
: StatementBuilder(dataModelService)
{
public UpdateNode Build(ResourceType resourceType, string setColumnName, string whereColumnName, object? whereValue)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

namespace DapperExample.TranslationToSql.Builders;

internal sealed class UpdateResourceStatementBuilder(IDataModelService dataModelService) : StatementBuilder(dataModelService)
internal sealed class UpdateResourceStatementBuilder(IDataModelService dataModelService)
: StatementBuilder(dataModelService)
{
public UpdateNode Build(ResourceType resourceType, IReadOnlyDictionary<string, object?> columnsToUpdate, params object[] idValues)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace DapperExample.TranslationToSql.DataModel;
/// <summary>
/// Derives foreign keys and connection strings from an existing Entity Framework Core model.
/// </summary>
public sealed class FromEntitiesDataModelService(IResourceGraph resourceGraph) : BaseDataModelService(resourceGraph)
public sealed class FromEntitiesDataModelService(IResourceGraph resourceGraph)
: BaseDataModelService(resourceGraph)
{
private readonly Dictionary<RelationshipAttribute, RelationshipForeignKey> _foreignKeysByRelationship = [];
private readonly Dictionary<AttrAttribute, bool> _columnNullabilityPerAttribute = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ public void Reset()
_nameGenerator.Reset();
}

private sealed class ParameterNameGenerator() : UniqueNameGenerator("@p");
private sealed class ParameterNameGenerator()
: UniqueNameGenerator("@p");
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ namespace DapperExample.TranslationToSql.Generators;
/// <summary>
/// Generates a SQL table alias with a unique name.
/// </summary>
internal sealed class TableAliasGenerator() : UniqueNameGenerator("t");
internal sealed class TableAliasGenerator()
: UniqueNameGenerator("t");
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace DapperExample.TranslationToSql.TreeNodes;
/// SELECT t2.Id AS Id0 FROM (SELECT t1.Id FROM Users AS t1) AS t2
/// ]]></code>.
/// </summary>
internal sealed class ColumnInSelectNode(ColumnSelectorNode selector, string? tableAlias) : ColumnNode(GetColumnName(selector), selector.Column.Type,
tableAlias)
internal sealed class ColumnInSelectNode(ColumnSelectorNode selector, string? tableAlias)
: ColumnNode(GetColumnName(selector), selector.Column.Type, tableAlias)
{
public ColumnSelectorNode Selector { get; } = selector;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ namespace DapperExample.TranslationToSql.TreeNodes;
/// FROM Users AS t1
/// ]]></code>.
/// </summary>
internal sealed class ColumnInTableNode(string name, ColumnType type, string? tableAlias) : ColumnNode(name, type, tableAlias)
internal sealed class ColumnInTableNode(string name, ColumnType type, string? tableAlias)
: ColumnNode(name, type, tableAlias)
{
public override TResult Accept<TArgument, TResult>(SqlTreeNodeVisitor<TArgument, TResult> visitor, TArgument argument)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ namespace DapperExample.TranslationToSql.TreeNodes;
/// SELECT COUNT(*) FROM Users
/// ]]></code>.
/// </summary>
internal sealed class CountSelectorNode(string? alias) : SelectorNode(alias)
internal sealed class CountSelectorNode(string? alias)
: SelectorNode(alias)
{
public override TResult Accept<TArgument, TResult>(SqlTreeNodeVisitor<TArgument, TResult> visitor, TArgument argument)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ namespace DapperExample.TranslationToSql.TreeNodes;
/// FROM Customers AS t1
/// ]]></code>.
/// </summary>
internal sealed class FromNode(TableSourceNode source) : TableAccessorNode(source)
internal sealed class FromNode(TableSourceNode source)
: TableAccessorNode(source)
{
public override TResult Accept<TArgument, TResult>(SqlTreeNodeVisitor<TArgument, TResult> visitor, TArgument argument)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ namespace DapperExample.TranslationToSql.TreeNodes;
/// SELECT 1 FROM Users
/// ]]></code>.
/// </summary>
internal sealed class OneSelectorNode(string? alias) : SelectorNode(alias)
internal sealed class OneSelectorNode(string? alias)
: SelectorNode(alias)
{
public override TResult Accept<TArgument, TResult>(SqlTreeNodeVisitor<TArgument, TResult> visitor, TArgument argument)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Examples/GettingStarted/Data/SampleDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
namespace GettingStarted.Data;

[UsedImplicitly(ImplicitUseTargetFlags.Members)]
public class SampleDbContext(DbContextOptions<SampleDbContext> options) : DbContext(options)
public class SampleDbContext(DbContextOptions<SampleDbContext> options)
: DbContext(options)
{
public DbSet<Book> Books => Set<Book>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ namespace JsonApiDotNetCoreExample.Controllers;

public sealed class OperationsController(
IJsonApiOptions options, IResourceGraph resourceGraph, ILoggerFactory loggerFactory, IOperationsProcessor processor, IJsonApiRequest request,
ITargetedFields targetedFields, IAtomicOperationFilter operationFilter) : JsonApiOperationsController(options, resourceGraph, loggerFactory, processor,
request, targetedFields, operationFilter);
ITargetedFields targetedFields, IAtomicOperationFilter operationFilter)
: JsonApiOperationsController(options, resourceGraph, loggerFactory, processor, request, targetedFields, operationFilter);
3 changes: 2 additions & 1 deletion src/Examples/JsonApiDotNetCoreExample/Data/AppDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
namespace JsonApiDotNetCoreExample.Data;

[UsedImplicitly(ImplicitUseTargetFlags.Members)]
public sealed class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(options)
public sealed class AppDbContext(DbContextOptions<AppDbContext> options)
: DbContext(options)
{
public DbSet<TodoItem> TodoItems => Set<TodoItem>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ ISystemClock systemClock
#else
TimeProvider timeProvider
#endif
) : JsonApiResourceDefinition<TodoItem, long>(resourceGraph)
)
: JsonApiResourceDefinition<TodoItem, long>(resourceGraph)
{
#if NET6_0
private readonly Func<DateTimeOffset> _getUtcNow = () => systemClock.UtcNow;
Expand Down
3 changes: 2 additions & 1 deletion src/Examples/MultiDbContextExample/Data/DbContextA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
namespace MultiDbContextExample.Data;

[UsedImplicitly(ImplicitUseTargetFlags.Members)]
public sealed class DbContextA(DbContextOptions<DbContextA> options) : DbContext(options)
public sealed class DbContextA(DbContextOptions<DbContextA> options)
: DbContext(options)
{
public DbSet<ResourceA> ResourceAs => Set<ResourceA>();
}
3 changes: 2 additions & 1 deletion src/Examples/MultiDbContextExample/Data/DbContextB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
namespace MultiDbContextExample.Data;

[UsedImplicitly(ImplicitUseTargetFlags.Members)]
public sealed class DbContextB(DbContextOptions<DbContextB> options) : DbContext(options)
public sealed class DbContextB(DbContextOptions<DbContextB> options)
: DbContext(options)
{
public DbSet<ResourceB> ResourceBs => Set<ResourceB>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace JsonApiDotNetCore.Controllers;
/// </summary>
public abstract class JsonApiOperationsController(
IJsonApiOptions options, IResourceGraph resourceGraph, ILoggerFactory loggerFactory, IOperationsProcessor processor, IJsonApiRequest request,
ITargetedFields targetedFields, IAtomicOperationFilter operationFilter) : BaseJsonApiOperationsController(options, resourceGraph, loggerFactory, processor,
request, targetedFields, operationFilter)
ITargetedFields targetedFields, IAtomicOperationFilter operationFilter)
: BaseJsonApiOperationsController(options, resourceGraph, loggerFactory, processor, request, targetedFields, operationFilter)
{
/// <inheritdoc />
[HttpPost]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace JsonApiDotNetCore.Errors;
/// The error that is thrown when a required relationship is cleared.
/// </summary>
[PublicAPI]
public sealed class CannotClearRequiredRelationshipException(string relationshipName, string resourceType) : JsonApiException(
new ErrorObject(HttpStatusCode.BadRequest)
public sealed class CannotClearRequiredRelationshipException(string relationshipName, string resourceType)
: JsonApiException(new ErrorObject(HttpStatusCode.BadRequest)
{
Title = "Failed to clear a required relationship.",
Detail = $"The relationship '{relationshipName}' on resource type '{resourceType}' cannot be cleared because it is a required relationship."
Expand Down
11 changes: 6 additions & 5 deletions src/JsonApiDotNetCore/Errors/DuplicateLocalIdValueException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ namespace JsonApiDotNetCore.Errors;
/// The error that is thrown when assigning a local ID that was already assigned in an earlier operation.
/// </summary>
[PublicAPI]
public sealed class DuplicateLocalIdValueException(string localId) : JsonApiException(new ErrorObject(HttpStatusCode.BadRequest)
{
Title = "Another local ID with the same name is already defined at this point.",
Detail = $"Another local ID with name '{localId}' is already defined at this point."
});
public sealed class DuplicateLocalIdValueException(string localId)
: JsonApiException(new ErrorObject(HttpStatusCode.BadRequest)
{
Title = "Another local ID with the same name is already defined at this point.",
Detail = $"Another local ID with name '{localId}' is already defined at this point."
});
4 changes: 2 additions & 2 deletions src/JsonApiDotNetCore/Errors/FailedOperationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace JsonApiDotNetCore.Errors;
/// The error that is thrown when an operation in an atomic:operations request failed to be processed for unknown reasons.
/// </summary>
[PublicAPI]
public sealed class FailedOperationException(int operationIndex, Exception innerException) : JsonApiException(
new ErrorObject(HttpStatusCode.InternalServerError)
public sealed class FailedOperationException(int operationIndex, Exception innerException)
: JsonApiException(new ErrorObject(HttpStatusCode.InternalServerError)
{
Title = "An unhandled error occurred while processing an operation in this request.",
Detail = innerException.Message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace JsonApiDotNetCore.Errors;
/// The error that is thrown when referencing a local ID that was assigned to a different resource type.
/// </summary>
[PublicAPI]
public sealed class IncompatibleLocalIdTypeException(string localId, string declaredType, string currentType) : JsonApiException(
new ErrorObject(HttpStatusCode.BadRequest)
public sealed class IncompatibleLocalIdTypeException(string localId, string declaredType, string currentType)
: JsonApiException(new ErrorObject(HttpStatusCode.BadRequest)
{
Title = "Incompatible type in Local ID usage.",
Detail = $"Local ID '{localId}' belongs to resource type '{declaredType}' instead of '{currentType}'."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ namespace JsonApiDotNetCore.Errors;
/// The error that is thrown when configured usage of this library is invalid.
/// </summary>
[PublicAPI]
public sealed class InvalidConfigurationException(string message, Exception? innerException = null) : Exception(message, innerException);
public sealed class InvalidConfigurationException(string message, Exception? innerException = null)
: Exception(message, innerException);
8 changes: 4 additions & 4 deletions src/JsonApiDotNetCore/Errors/InvalidModelStateException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ namespace JsonApiDotNetCore.Errors;
[PublicAPI]
public sealed class InvalidModelStateException(
IReadOnlyDictionary<string, ModelStateEntry?> modelState, Type modelType, bool includeExceptionStackTraceInErrors, IResourceGraph resourceGraph,
Func<Type, int, Type?>? getCollectionElementTypeCallback = null) : JsonApiException(FromModelStateDictionary(modelState, modelType, resourceGraph,
includeExceptionStackTraceInErrors, getCollectionElementTypeCallback))
Func<Type, int, Type?>? getCollectionElementTypeCallback = null)
: JsonApiException(FromModelStateDictionary(modelState, modelType, resourceGraph, includeExceptionStackTraceInErrors, getCollectionElementTypeCallback))
{
private static List<ErrorObject> FromModelStateDictionary(IReadOnlyDictionary<string, ModelStateEntry?> modelState, Type modelType,
IResourceGraph resourceGraph, bool includeExceptionStackTraceInErrors, Func<Type, int, Type?>? getCollectionElementTypeCallback)
Expand Down Expand Up @@ -316,8 +316,8 @@ private static ModelStateKeySegment CreateSegment(Type modelType, string key, bo
/// </summary>
private sealed class ArrayIndexerSegment(
int arrayIndex, Type modelType, bool isInComplexType, string nextKey, string? sourcePointer, ModelStateKeySegment? parent,
Func<Type, int, Type?>? getCollectionElementTypeCallback) : ModelStateKeySegment(modelType, isInComplexType, nextKey, sourcePointer, parent,
getCollectionElementTypeCallback)
Func<Type, int, Type?>? getCollectionElementTypeCallback)
: ModelStateKeySegment(modelType, isInComplexType, nextKey, sourcePointer, parent, getCollectionElementTypeCallback)
{
private static readonly CollectionConverter CollectionConverter = new();

Expand Down
11 changes: 6 additions & 5 deletions src/JsonApiDotNetCore/Errors/InvalidQueryException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ namespace JsonApiDotNetCore.Errors;
/// The error that is thrown when translating a <see cref="QueryLayer" /> to Entity Framework Core fails.
/// </summary>
[PublicAPI]
public sealed class InvalidQueryException(string reason, Exception? innerException) : JsonApiException(new ErrorObject(HttpStatusCode.BadRequest)
{
Title = reason,
Detail = innerException?.Message
}, innerException);
public sealed class InvalidQueryException(string reason, Exception? innerException)
: JsonApiException(new ErrorObject(HttpStatusCode.BadRequest)
{
Title = reason,
Detail = innerException?.Message
}, innerException);
35 changes: 18 additions & 17 deletions src/JsonApiDotNetCore/Errors/InvalidRequestBodyException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@ namespace JsonApiDotNetCore.Errors;
[PublicAPI]
public sealed class InvalidRequestBodyException(
string? requestBody, string? genericMessage, string? specificMessage, string? sourcePointer, HttpStatusCode? alternativeStatusCode = null,
Exception? innerException = null) : JsonApiException(new ErrorObject(alternativeStatusCode ?? HttpStatusCode.UnprocessableEntity)
{
Title = genericMessage != null ? $"Failed to deserialize request body: {genericMessage}" : "Failed to deserialize request body.",
Detail = specificMessage,
Source = sourcePointer == null
? null
: new ErrorSource
{
Pointer = sourcePointer
},
Meta = string.IsNullOrEmpty(requestBody)
? null
: new Dictionary<string, object?>
{
["RequestBody"] = requestBody
}
}, innerException);
Exception? innerException = null)
: JsonApiException(new ErrorObject(alternativeStatusCode ?? HttpStatusCode.UnprocessableEntity)
{
Title = genericMessage != null ? $"Failed to deserialize request body: {genericMessage}" : "Failed to deserialize request body.",
Detail = specificMessage,
Source = sourcePointer == null
? null
: new ErrorSource
{
Pointer = sourcePointer
},
Meta = string.IsNullOrEmpty(requestBody)
? null
: new Dictionary<string, object?>
{
["RequestBody"] = requestBody
}
}, innerException);
11 changes: 6 additions & 5 deletions src/JsonApiDotNetCore/Errors/LocalIdSingleOperationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ namespace JsonApiDotNetCore.Errors;
/// The error that is thrown when assigning and referencing a local ID within the same operation.
/// </summary>
[PublicAPI]
public sealed class LocalIdSingleOperationException(string localId) : JsonApiException(new ErrorObject(HttpStatusCode.BadRequest)
{
Title = "Local ID cannot be both defined and used within the same operation.",
Detail = $"Local ID '{localId}' cannot be both defined and used within the same operation."
});
public sealed class LocalIdSingleOperationException(string localId)
: JsonApiException(new ErrorObject(HttpStatusCode.BadRequest)
{
Title = "Local ID cannot be both defined and used within the same operation.",
Detail = $"Local ID '{localId}' cannot be both defined and used within the same operation."
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ namespace JsonApiDotNetCore.Errors;
/// The error that is thrown when accessing a repository that does not support transactions during an atomic:operations request.
/// </summary>
[PublicAPI]
public sealed class MissingTransactionSupportException(string resourceType) : JsonApiException(new ErrorObject(HttpStatusCode.UnprocessableEntity)
{
Title = "Unsupported resource type in atomic:operations request.",
Detail = $"Operations on resources of type '{resourceType}' cannot be used because transaction support is unavailable."
});
public sealed class MissingTransactionSupportException(string resourceType)
: JsonApiException(new ErrorObject(HttpStatusCode.UnprocessableEntity)
{
Title = "Unsupported resource type in atomic:operations request.",
Detail = $"Operations on resources of type '{resourceType}' cannot be used because transaction support is unavailable."
});
Loading

0 comments on commit 51d2e49

Please sign in to comment.