Skip to content

Commit

Permalink
feat: add Meziantou.Analyzer configure and fix findings
Browse files Browse the repository at this point in the history
feat: add Meziantou.Analyzer configure and fix findings
  • Loading branch information
AndreaCuneo authored Jan 2, 2025
2 parents 7d72f0e + 3250ddd commit 590b3eb
Show file tree
Hide file tree
Showing 516 changed files with 8,612 additions and 7,130 deletions.
55 changes: 54 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,51 @@ csharp_style_prefer_tuple_swap = true:suggestion
csharp_style_prefer_utf8_string_literals = true:suggestion
dotnet_code_quality.ca1051.exclude_structs = true
csharp_style_prefer_primary_constructors = true:suggestion
csharp_prefer_system_threading_lock = true:suggestion
dotnet_diagnostic.MA0042.severity = error
dotnet_diagnostic.MA0045.severity = error
dotnet_diagnostic.MA0050.severity = warning
dotnet_diagnostic.MA0053.severity = warning
dotnet_diagnostic.MA0067.severity = warning
dotnet_diagnostic.MA0102.severity = warning
dotnet_diagnostic.MA0113.severity = warning
dotnet_diagnostic.MA0114.severity = warning
dotnet_diagnostic.MA0121.severity = suggestion
dotnet_diagnostic.MA0133.severity = error
dotnet_diagnostic.MA0057.severity = warning
dotnet_diagnostic.MA0058.severity = warning
dotnet_diagnostic.MA0059.severity = warning
dotnet_diagnostic.CA1866.severity = warning
dotnet_diagnostic.CA1865.severity = warning
dotnet_diagnostic.CA1845.severity = warning
dotnet_diagnostic.CA1870.severity = warning
dotnet_diagnostic.MA0028.severity = warning
dotnet_diagnostic.MA0029.severity = suggestion
dotnet_diagnostic.MA0044.severity = warning
dotnet_diagnostic.MA0063.severity = warning
dotnet_diagnostic.MA0078.severity = error
dotnet_diagnostic.MA0152.severity = warning
dotnet_diagnostic.MA0160.severity = warning
dotnet_diagnostic.CA2020.severity = warning
dotnet_diagnostic.MA0032.severity = none
dotnet_diagnostic.MA0040.severity = error
dotnet_diagnostic.MA0004.severity = warning
dotnet_diagnostic.MA0043.severity = warning
dotnet_diagnostic.MA0079.severity = error
dotnet_diagnostic.MA0080.severity = warning
csharp_style_prefer_pattern_matching = true:silent
csharp_style_prefer_not_pattern = true:suggestion
csharp_style_prefer_extended_property_pattern = true:suggestion
dotnet_diagnostic.MA0048.severity = silent
dotnet_diagnostic.MA0006.severity = silent
dotnet_diagnostic.MA0051.severity = suggestion
dotnet_diagnostic.MA0016.severity = suggestion

# VSTHRD200: Use "Async" suffix for async methods
dotnet_diagnostic.VSTHRD200.severity = silent
dotnet_diagnostic.MA0056.severity = silent
dotnet_diagnostic.MA0049.severity = none
dotnet_diagnostic.MA0007.severity = silent

[*.{cs,vb}]
dotnet_style_operator_placement_when_wrapping = beginning_of_line
Expand Down Expand Up @@ -284,7 +329,7 @@ dotnet_diagnostic.CA2011.severity = warning
dotnet_diagnostic.CA5350.severity = warning
dotnet_diagnostic.CA5351.severity = error
dotnet_diagnostic.CA5359.severity = warning
dotnet_diagnostic.CA5379.severity = suggestion
dotnet_diagnostic.CA5379.severity = warning
dotnet_diagnostic.CA5385.severity = warning
dotnet_diagnostic.CA5397.severity = warning
dotnet_diagnostic.CA1816.severity = warning
Expand Down Expand Up @@ -320,5 +365,13 @@ dotnet_diagnostic.CA5360.severity = warning
dotnet_diagnostic.CA5363.severity = warning
dotnet_diagnostic.CA2250.severity = warning
dotnet_diagnostic.CA2253.severity = warning
dotnet_diagnostic.CA1839.severity = warning
dotnet_diagnostic.CA1853.severity = warning
dotnet_diagnostic.CA1854.severity = error
dotnet_diagnostic.CA1864.severity = warning
dotnet_diagnostic.CA1868.severity = warning
dotnet_diagnostic.CA1869.severity = warning
dotnet_diagnostic.CA5365.severity = warning
dotnet_diagnostic.CA5364.severity = warning
[*.vb]
dotnet_diagnostic.CA1047.severity = warning
3 changes: 2 additions & 1 deletion .github/workflows/dependecy-review.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ jobs:
# @source https://github.com/actions/dependency-review-action/issues/809#issuecomment-2285930024
with:
# Use comma-separated names to pass list arguments:
allow-licenses: Apache-2.0,BSD-3-Clause,BSD-2-Clause,MIT,Apache-2.0 AND MIT
allow-licenses: Apache-2.0,BSD-3-Clause,BSD-2-Clause,MIT,Apache-2.0 AND MIT,LicenseRef-scancode-generic-cla AND MIT
allow-dependencies-licenses: pkg:nuget/[email protected], pkg:nuget/[email protected]
61 changes: 59 additions & 2 deletions Ark.ReferenceProject/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,55 @@ csharp_style_prefer_tuple_swap = true:suggestion
csharp_style_prefer_utf8_string_literals = true:suggestion
dotnet_code_quality.ca1051.exclude_structs = true
csharp_style_prefer_primary_constructors = true:suggestion
csharp_prefer_system_threading_lock = true:suggestion
dotnet_diagnostic.MA0042.severity = error
dotnet_diagnostic.MA0045.severity = error
dotnet_diagnostic.MA0050.severity = warning
dotnet_diagnostic.MA0053.severity = warning
dotnet_diagnostic.MA0067.severity = warning
dotnet_diagnostic.MA0102.severity = warning
dotnet_diagnostic.MA0113.severity = warning
dotnet_diagnostic.MA0114.severity = warning
dotnet_diagnostic.MA0121.severity = suggestion
dotnet_diagnostic.MA0133.severity = error
dotnet_diagnostic.MA0057.severity = warning
dotnet_diagnostic.MA0058.severity = warning
dotnet_diagnostic.MA0059.severity = warning
dotnet_diagnostic.CA1866.severity = warning
dotnet_diagnostic.CA1865.severity = warning
dotnet_diagnostic.CA1845.severity = warning
dotnet_diagnostic.CA1870.severity = warning
dotnet_diagnostic.MA0028.severity = warning
dotnet_diagnostic.MA0029.severity = warning
dotnet_diagnostic.MA0044.severity = warning
dotnet_diagnostic.MA0063.severity = warning
dotnet_diagnostic.MA0078.severity = error
dotnet_diagnostic.MA0152.severity = warning
dotnet_diagnostic.MA0160.severity = warning
dotnet_diagnostic.CA2020.severity = warning
dotnet_diagnostic.MA0032.severity = none
dotnet_diagnostic.MA0040.severity = error
dotnet_diagnostic.MA0004.severity = none
dotnet_diagnostic.MA0043.severity = warning
dotnet_diagnostic.MA0079.severity = error
dotnet_diagnostic.MA0080.severity = warning
csharp_style_prefer_pattern_matching = true:silent
csharp_style_prefer_not_pattern = true:suggestion
csharp_style_prefer_extended_property_pattern = true:suggestion
dotnet_diagnostic.MA0048.severity = silent
dotnet_diagnostic.MA0006.severity = silent
dotnet_diagnostic.MA0051.severity = suggestion
dotnet_diagnostic.MA0016.severity = suggestion

# VSTHRD200: Use "Async" suffix for async methods
dotnet_diagnostic.VSTHRD200.severity = silent
dotnet_diagnostic.MA0056.severity = silent
dotnet_diagnostic.MA0049.severity = none
dotnet_diagnostic.MA0007.severity = silent

# IDE0290: Use primary constructor
dotnet_diagnostic.IDE0290.severity = none
dotnet_diagnostic.MA0003.severity = none

[*.{cs,vb}]
dotnet_style_operator_placement_when_wrapping = beginning_of_line
Expand Down Expand Up @@ -284,7 +333,7 @@ dotnet_diagnostic.CA2011.severity = warning
dotnet_diagnostic.CA5350.severity = warning
dotnet_diagnostic.CA5351.severity = error
dotnet_diagnostic.CA5359.severity = warning
dotnet_diagnostic.CA5379.severity = suggestion
dotnet_diagnostic.CA5379.severity = warning
dotnet_diagnostic.CA5385.severity = warning
dotnet_diagnostic.CA5397.severity = warning
dotnet_diagnostic.CA1816.severity = warning
Expand All @@ -294,7 +343,7 @@ dotnet_diagnostic.CA2215.severity = warning
dotnet_diagnostic.CA2219.severity = warning
dotnet_diagnostic.CA2242.severity = warning
dotnet_diagnostic.CA2245.severity = error
dotnet_diagnostic.CA1510.severity = suggestion
dotnet_diagnostic.CA1510.severity = warning
dotnet_diagnostic.CA1050.severity = warning
dotnet_diagnostic.CA1862.severity = warning
dotnet_diagnostic.CA1850.severity = warning
Expand All @@ -320,5 +369,13 @@ dotnet_diagnostic.CA5360.severity = warning
dotnet_diagnostic.CA5363.severity = warning
dotnet_diagnostic.CA2250.severity = warning
dotnet_diagnostic.CA2253.severity = warning
dotnet_diagnostic.CA1839.severity = warning
dotnet_diagnostic.CA1853.severity = warning
dotnet_diagnostic.CA1854.severity = error
dotnet_diagnostic.CA1864.severity = warning
dotnet_diagnostic.CA1868.severity = warning
dotnet_diagnostic.CA1869.severity = warning
dotnet_diagnostic.CA5365.severity = warning
dotnet_diagnostic.CA5364.severity = warning
[*.vb]
dotnet_diagnostic.CA1047.severity = warning
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static PermissionAuthorizationHandler()
{
if (!typeof(TPermissionEnum).IsEnum)
{
throw new ArgumentException("TPermissionEnum must be an enumerated type");
throw new InvalidOperationException("TPermissionEnum must be an enumerated type");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static class PermissionsConstants

public static readonly string AdminGrant = "grant:admin";

public static readonly IReadOnlyDictionary<string, Permissions> PermissionsMap = new Dictionary<string, Permissions>()
public static readonly IReadOnlyDictionary<string, Permissions> PermissionsMap = new Dictionary<string, Permissions>(System.StringComparer.Ordinal)
{
{ AdminGrant, Permissions.Admin }
}.ToImmutableDictionary();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Ark.Reference.Common.Auth
public abstract class RequiredScopePolicyHandler : AuthorizationHandler<RequiredScopePolicy>
{
private readonly string _serviceScope;
private static readonly char[] _separator = new[] { ' ' };
private static readonly char[] _separator = [' '];

protected RequiredScopePolicyHandler(
string serviceScope)
Expand All @@ -27,7 +27,7 @@ protected override Task HandleRequirementAsync(AuthorizationContext context, Req

var requiredScope = requirement.Scope;

if (!scopes.Contains(requiredScope))
if (!scopes.Contains(requiredScope, StringComparer.Ordinal))
context.Fail(requirement, $"User does not possess the required scopes '{requiredScope}'");
else
context.Succeed(requirement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Ark.Reference.Common
{
public static class CommonConstants
{
{
public const string TimeZone = "CET";
public static readonly DateTimeZone Tz = DateTimeZoneProviders.Tzdb[TimeZone];

Expand Down
13 changes: 6 additions & 7 deletions Ark.ReferenceProject/Ark.Reference.Common/Ex.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using Ark.Tools.Core;
using Ark.Reference.Common.Auth;
using Ark.Tools.Core;
using Ark.Tools.Core.BusinessRuleViolation;

using Dapper;

using Ark.Reference.Common.Auth;

using FluentValidation;

using Microsoft.Data.SqlClient;
Expand Down Expand Up @@ -44,12 +43,12 @@ public static IEnumerable<Permissions> GetPermissions(this ClaimsPrincipal user)
public static string[] CompileSorts(this IEnumerable<string> sorts, Dictionary<string, string> validCols, string defaultValue)
{
return (sorts ?? Enumerable.Empty<string>())
.Select(s => Regex.Match(s, "^(\\S+)(\\s(asc|desc))?$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant))
.Select(s => Regex.Match(s, "^(?<col>\\S+)(\\s(?<dir>asc|desc))?$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture, TimeSpan.FromMilliseconds(1000)))
.Where(s => s.Success)
.Join(validCols
, s => s.Groups[1].Value.ToLowerInvariant()
, s => s.Groups["col"].Value.ToLowerInvariant()
, d => d.Key.ToLowerInvariant()
, (s, i) => i.Value + s.Groups[2].Value)
, (s, i) => i.Value + s.Groups["dir"].Value, StringComparer.Ordinal)
.DefaultIfEmpty(defaultValue)
.ToArray();
}
Expand Down Expand Up @@ -140,7 +139,7 @@ public static OffsetDateTime StartOfDayInZone(this OffsetDateTime odt, int plusD
}
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@

namespace Ark.Reference.Common.Exceptions
{
public class ExternalServiceException : Exception
{
public ExternalServiceException(string message)
: base(message)
{
}
public class ExternalServiceException : Exception
{
public ExternalServiceException(string message)
: base(message)
{
}

public ExternalServiceException(string format, params object[] args)
: base(string.Format(CultureInfo.InvariantCulture, format, args))
{
}
public ExternalServiceException(string format, params object[] args)
: base(string.Format(CultureInfo.InvariantCulture, format, args))
{
}


public ExternalServiceException(Exception inner, string message)
: base(message, inner)
{
}
public ExternalServiceException(Exception inner, string message)
: base(message, inner)
{
}

public ExternalServiceException(Exception inner, string format, params object[] args)
: base(string.Format(CultureInfo.InvariantCulture, format, args), inner)
{
}
public ExternalServiceException(Exception inner, string format, params object[] args)
: base(string.Format(CultureInfo.InvariantCulture, format, args), inner)
{
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -35,7 +36,7 @@ AuditQueryDto.V1<TAuditKind> query
, CancellationToken ctk = default
)
{
_logger.Trace("ReadAuditByFilterAsync called");
_logger.Trace(CultureInfo.InvariantCulture, "ReadAuditByFilterAsync called");

var parameters = new
{
Expand Down Expand Up @@ -73,22 +74,21 @@ FROM [{_schemaAudit}].[{_tableAudit}]
{(query.AuditKinds?.Length > 0 ? "AND [Kind] IN @AuditKinds" : "")}
{(query.FromDateTime != null ? "AND [SysStartTime] >= @FromDateTime" : "")}
{(query.ToDateTime != null ? "AND [SysStartTime] <= @ToDateTime" : "")}
",
",
parameters, transaction: _dbTransaction, cancellationToken: ctk);

using var q = await _dbConnection.QueryMultipleAsync(cmd);
await using var q = await _dbConnection.QueryMultipleAsync(cmd);

var retVal = await q.ReadAsync<AuditDto<TAuditKind>>();
var count = await q.ReadFirstAsync<int>();

_logger.Trace("ReadAuditById ended");
_logger.Trace(CultureInfo.InvariantCulture, "ReadAuditById ended");
return (retVal, count);
}


public async Task<IEnumerable<string>> ReadAuditUsersAsync(CancellationToken ctk = default)
{
_logger.Trace("ReadAuditUsersAsync called");
_logger.Trace(CultureInfo.InvariantCulture, "ReadAuditUsersAsync called");

var parameters = new
{
Expand All @@ -102,7 +102,7 @@ FROM [{_schemaAudit}].[{_tableAudit}]

var retVal = await _dbConnection.QueryAsync<string>(cmd).ConfigureAwait(true);

_logger.Trace("ReadAuditUsersAsync ended");
_logger.Trace(CultureInfo.InvariantCulture, "ReadAuditUsersAsync ended");
return retVal;
}

Expand Down Expand Up @@ -131,7 +131,7 @@ public async ValueTask<AuditDto<TAuditKind>> EnsureAudit(TAuditKind kind, string

private Task _insertAudit(AuditDto<TAuditKind> dto, CancellationToken ctk = default)
{
_logger.Trace("CreateAudit called");
_logger.Trace(CultureInfo.InvariantCulture, "CreateAudit called");

var parameters = new
{
Expand All @@ -158,7 +158,7 @@ INSERT INTO [{_schemaAudit}].[{_tableAudit}]
)
", parameters, transaction: _dbTransaction, cancellationToken: ctk);

_logger.Trace("CreateAudit ended");
_logger.Trace(CultureInfo.InvariantCulture, "CreateAudit ended");
return _dbConnection.ExecuteAsync(cmd);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NodaTime;

using System;

namespace Ark.Reference.Common.Services.Audit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface IAuditedEntityDto<out TEntity>
public record AuditedEntityDto<TEntity> : IAuditedEntityDto<TEntity>
where TEntity : class, IAuditEntity
{
public TEntity? Entity { get; set; }
public TEntity? Entity { get; set; }
public Instant SysStartTime { get; set; }
public Instant SysEndTime { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Ark.Tools.Core;

using System;
using System.Collections.Generic;
using System.Threading;
Expand Down
Loading

0 comments on commit 590b3eb

Please sign in to comment.