Skip to content

Commit a3a9389

Browse files
author
Bart Koelman
authored
Package updates (#1146)
* Renamed method to avoid clash with built-in method from newer version of FluentAssertions * Package updates * Fix cases for AV1130: Return type should be interface to unchangeable collection * Fix cases for AV1553/AV1554: Optional string/collection/task parameter usage
1 parent b48f02e commit a3a9389

File tree

147 files changed

+1343
-1275
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+1343
-1275
lines changed

.config/dotnet-tools.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
"isRoot": true,
44
"tools": {
55
"jetbrains.resharper.globaltools": {
6-
"version": "2021.3.0",
6+
"version": "2021.3.4",
77
"commands": [
88
"jb"
99
]
1010
},
1111
"regitlint": {
12-
"version": "6.0.6",
12+
"version": "6.0.8",
1313
"commands": [
1414
"regitlint"
1515
]
@@ -21,7 +21,7 @@
2121
]
2222
},
2323
"dotnet-reportgenerator-globaltool": {
24-
"version": "5.0.0",
24+
"version": "5.1.3",
2525
"commands": [
2626
"reportgenerator"
2727
]

CodingGuidelines.ruleset

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
<Rule Id="AV1555" Action="Warning" />
1515
<Rule Id="AV1564" Action="Info" />
1616
<Rule Id="AV1568" Action="Warning" />
17+
<Rule Id="AV1580" Action="None" />
1718
<Rule Id="AV1706" Action="Warning" />
1819
<Rule Id="AV1710" Action="Info" />
1920
<Rule Id="AV1711" Action="Info" />
2021
<Rule Id="AV1738" Action="Warning" />
2122
<Rule Id="AV1739" Action="Warning" />
2223
<Rule Id="AV1745" Action="Warning" />
2324
<Rule Id="AV1755" Action="Warning" />
24-
<Rule Id="AV2210" Action="None" />
25+
<Rule Id="AV2210" Action="Warning" />
2526
<Rule Id="AV2220" Action="Warning" />
2627
<Rule Id="AV2230" Action="Info" />
2728
<Rule Id="AV2305" Action="None" />

Directory.Build.props

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<AspNetVersion>6.0.*</AspNetVersion>
55
<EFCoreVersion>6.0.*</EFCoreVersion>
66
<EFCorePostgresVersion>6.0.*</EFCorePostgresVersion>
7-
<MicrosoftCodeAnalysisVersion>4.0.*</MicrosoftCodeAnalysisVersion>
7+
<MicrosoftCodeAnalysisVersion>4.1.*</MicrosoftCodeAnalysisVersion>
88
<HumanizerVersion>2.*</HumanizerVersion>
99
<JsonApiDotNetCoreVersionPrefix>5.0.0</JsonApiDotNetCoreVersionPrefix>
1010
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)CodingGuidelines.ruleset</CodeAnalysisRuleSet>
@@ -17,7 +17,7 @@
1717

1818
<ItemGroup>
1919
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" PrivateAssets="All" />
20-
<PackageReference Include="CSharpGuidelinesAnalyzer" Version="3.7.1" PrivateAssets="All" />
20+
<PackageReference Include="CSharpGuidelinesAnalyzer" Version="3.8.0" PrivateAssets="All" />
2121
<AdditionalFiles Include="$(MSBuildThisFileDirectory)CSharpGuidelinesAnalyzer.config" Visible="False" />
2222
</ItemGroup>
2323

@@ -27,10 +27,14 @@
2727
<GenerateDocumentationFile>true</GenerateDocumentationFile>
2828
</PropertyGroup>
2929

30+
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
31+
<NoWarn>$(NoWarn);AV2210</NoWarn>
32+
</PropertyGroup>
33+
3034
<!-- Test Project Dependencies -->
3135
<PropertyGroup>
3236
<CoverletVersion>3.1.2</CoverletVersion>
33-
<MoqVersion>4.16.1</MoqVersion>
37+
<MoqVersion>4.17.2</MoqVersion>
3438
<TestSdkVersion>17.1.0</TestSdkVersion>
3539
</PropertyGroup>
3640
</Project>

benchmarks/Serialization/SerializationBenchmarkBase.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public RelationshipLinks GetRelationshipLinks(RelationshipAttribute relationship
245245

246246
private sealed class FakeMetaBuilder : IMetaBuilder
247247
{
248-
public void Add(IReadOnlyDictionary<string, object?> values)
248+
public void Add(IDictionary<string, object?> values)
249249
{
250250
}
251251

src/JsonApiDotNetCore.Annotations/ArgumentGuard.cs

+13-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,24 @@ public static void NotNull<T>([NoEnumeration] [SysNotNull] T? value, [InvokerPar
1818
}
1919

2020
[AssertionMethod]
21-
public static void NotNullNorEmpty<T>([SysNotNull] IEnumerable<T>? value, [InvokerParameterName] string name, string? collectionName = null)
21+
public static void NotNullNorEmpty<T>([SysNotNull] IEnumerable<T>? value, [InvokerParameterName] string name)
2222
{
2323
NotNull(value, name);
2424

2525
if (!value.Any())
2626
{
27-
throw new ArgumentException($"Must have one or more {collectionName ?? name}.", name);
27+
throw new ArgumentException($"Must have one or more {name}.", name);
28+
}
29+
}
30+
31+
[AssertionMethod]
32+
public static void NotNullNorEmpty<T>([SysNotNull] IEnumerable<T>? value, [InvokerParameterName] string name, string collectionName)
33+
{
34+
NotNull(value, name);
35+
36+
if (!value.Any())
37+
{
38+
throw new ArgumentException($"Must have one or more {collectionName}.", name);
2839
}
2940
}
3041

src/JsonApiDotNetCore.Annotations/CollectionConverter.cs

+12-2
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,19 @@ private Type ToConcreteCollectionType(Type collectionType)
6666
/// <summary>
6767
/// Returns a collection that contains zero, one or multiple resources, depending on the specified value.
6868
/// </summary>
69-
public ICollection<IIdentifiable> ExtractResources(object? value)
69+
public IReadOnlyCollection<IIdentifiable> ExtractResources(object? value)
7070
{
71-
if (value is ICollection<IIdentifiable> resourceCollection)
71+
if (value is List<IIdentifiable> resourceList)
72+
{
73+
return resourceList;
74+
}
75+
76+
if (value is HashSet<IIdentifiable> resourceSet)
77+
{
78+
return resourceSet;
79+
}
80+
81+
if (value is IReadOnlyCollection<IIdentifiable> resourceCollection)
7282
{
7383
return resourceCollection;
7484
}

src/JsonApiDotNetCore.Annotations/Configuration/ResourceType.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,14 @@ public sealed class ResourceType
8989
/// </remarks>
9090
public LinkTypes RelationshipLinks { get; }
9191

92-
public ResourceType(string publicName, Type clrType, Type identityClrType, IReadOnlyCollection<AttrAttribute>? attributes = null,
93-
IReadOnlyCollection<RelationshipAttribute>? relationships = null, IReadOnlyCollection<EagerLoadAttribute>? eagerLoads = null,
92+
public ResourceType(string publicName, Type clrType, Type identityClrType, LinkTypes topLevelLinks = LinkTypes.NotConfigured,
93+
LinkTypes resourceLinks = LinkTypes.NotConfigured, LinkTypes relationshipLinks = LinkTypes.NotConfigured)
94+
: this(publicName, clrType, identityClrType, null, null, null, topLevelLinks, resourceLinks, relationshipLinks)
95+
{
96+
}
97+
98+
public ResourceType(string publicName, Type clrType, Type identityClrType, IReadOnlyCollection<AttrAttribute>? attributes,
99+
IReadOnlyCollection<RelationshipAttribute>? relationships, IReadOnlyCollection<EagerLoadAttribute>? eagerLoads,
94100
LinkTypes topLevelLinks = LinkTypes.NotConfigured, LinkTypes resourceLinks = LinkTypes.NotConfigured,
95101
LinkTypes relationshipLinks = LinkTypes.NotConfigured)
96102
{

src/JsonApiDotNetCore.Annotations/ObjectExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#pragma warning disable AV1130 // Return type in method signature should be a collection interface instead of a concrete type
1+
#pragma warning disable AV1130 // Return type in method signature should be an interface to an unchangeable collection
22

33
namespace JsonApiDotNetCore;
44

src/JsonApiDotNetCore/ArrayFactory.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#pragma warning disable AV1008 // Class should not be static
2-
#pragma warning disable AV1130 // Return type in method signature should be a collection interface instead of a concrete type
2+
#pragma warning disable AV1130 // Return type in method signature should be an interface to an unchangeable collection
33

44
namespace JsonApiDotNetCore;
55

src/JsonApiDotNetCore/AtomicOperations/Processors/SetRelationshipProcessor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public SetRelationshipProcessor(ISetRelationshipService<TResource, TId> service)
4040

4141
if (relationship is HasManyAttribute)
4242
{
43-
ICollection<IIdentifiable> rightResources = _collectionConverter.ExtractResources(rightValue);
43+
IReadOnlyCollection<IIdentifiable> rightResources = _collectionConverter.ExtractResources(rightValue);
4444
return rightResources.ToHashSet(IdentifiableComparer.Instance);
4545
}
4646

src/JsonApiDotNetCore/Configuration/ResourceGraphBuilder.cs

+4
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,10 @@ private static bool IsImplicitManyToManyJoinEntity(IEntityType entityType)
175175
/// The name under which the resource is publicly exposed by the API. If nothing is specified, the naming convention is applied on the pluralized CLR
176176
/// type name.
177177
/// </param>
178+
#pragma warning disable AV1553 // Do not use optional parameters with default value null for strings, collections or tasks
178179
public ResourceGraphBuilder Add<TResource, TId>(string? publicName = null)
179180
where TResource : class, IIdentifiable<TId>
181+
#pragma warning restore AV1553 // Do not use optional parameters with default value null for strings, collections or tasks
180182
{
181183
return Add(typeof(TResource), typeof(TId), publicName);
182184
}
@@ -194,7 +196,9 @@ public ResourceGraphBuilder Add<TResource, TId>(string? publicName = null)
194196
/// The name under which the resource is publicly exposed by the API. If nothing is specified, the naming convention is applied on the pluralized CLR
195197
/// type name.
196198
/// </param>
199+
#pragma warning disable AV1553 // Do not use optional parameters with default value null for strings, collections or tasks
197200
public ResourceGraphBuilder Add(Type resourceClrType, Type? idClrType = null, string? publicName = null)
201+
#pragma warning restore AV1553 // Do not use optional parameters with default value null for strings, collections or tasks
198202
{
199203
ArgumentGuard.NotNull(resourceClrType, nameof(resourceClrType));
200204

src/JsonApiDotNetCore/Configuration/ServiceCollectionExtensions.cs

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using Microsoft.EntityFrameworkCore;
77
using Microsoft.Extensions.DependencyInjection;
88

9+
#pragma warning disable AV1130 // Return type in method signature should be an interface to an unchangeable collection
10+
911
namespace JsonApiDotNetCore.Configuration;
1012

1113
[PublicAPI]
@@ -16,9 +18,11 @@ public static class ServiceCollectionExtensions
1618
/// <summary>
1719
/// Configures JsonApiDotNetCore by registering resources manually.
1820
/// </summary>
21+
#pragma warning disable AV1553 // Do not use optional parameters with default value null for strings, collections or tasks
1922
public static IServiceCollection AddJsonApi(this IServiceCollection services, Action<JsonApiOptions>? options = null,
2023
Action<ServiceDiscoveryFacade>? discovery = null, Action<ResourceGraphBuilder>? resources = null, IMvcCoreBuilder? mvcBuilder = null,
2124
ICollection<Type>? dbContextTypes = null)
25+
#pragma warning restore AV1553 // Do not use optional parameters with default value null for strings, collections or tasks
2226
{
2327
ArgumentGuard.NotNull(services, nameof(services));
2428

src/JsonApiDotNetCore/Diagnostics/CascadingCodeTimer.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ static CascadingCodeTimer()
3232
}
3333

3434
/// <inheritdoc />
35-
public IDisposable Measure(string name, bool excludeInRelativeCost = false)
35+
public IDisposable Measure(string name)
36+
{
37+
return Measure(name, false);
38+
}
39+
40+
/// <inheritdoc />
41+
public IDisposable Measure(string name, bool excludeInRelativeCost)
3642
{
3743
MeasureScope childScope = CreateChildScope(name, excludeInRelativeCost);
3844
_activeScopeStack.Push(childScope);

src/JsonApiDotNetCore/Diagnostics/DisabledCodeTimer.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ private DisabledCodeTimer()
1111
{
1212
}
1313

14-
public IDisposable Measure(string name, bool excludeInRelativeCost = false)
14+
public IDisposable Measure(string name)
15+
{
16+
return this;
17+
}
18+
19+
public IDisposable Measure(string name, bool excludeInRelativeCost)
1520
{
1621
return this;
1722
}

src/JsonApiDotNetCore/Diagnostics/ICodeTimer.cs

+11-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ namespace JsonApiDotNetCore.Diagnostics;
55
/// </summary>
66
public interface ICodeTimer : IDisposable
77
{
8+
/// <summary>
9+
/// Starts recording the duration of a code block, while including this measurement in calculated percentages. Wrap this call in a <c>using</c>
10+
/// statement, so the recording stops when the return value goes out of scope.
11+
/// </summary>
12+
/// <param name="name">
13+
/// Description of what is being recorded.
14+
/// </param>
15+
IDisposable Measure(string name);
16+
817
/// <summary>
918
/// Starts recording the duration of a code block. Wrap this call in a <c>using</c> statement, so the recording stops when the return value goes out of
1019
/// scope.
@@ -13,9 +22,9 @@ public interface ICodeTimer : IDisposable
1322
/// Description of what is being recorded.
1423
/// </param>
1524
/// <param name="excludeInRelativeCost">
16-
/// When set, indicates to exclude this measurement in calculated percentages. <c>false</c> by default.
25+
/// When set, indicates to exclude this measurement in calculated percentages.
1726
/// </param>
18-
IDisposable Measure(string name, bool excludeInRelativeCost = false);
27+
IDisposable Measure(string name, bool excludeInRelativeCost);
1928

2029
/// <summary>
2130
/// Returns intermediate or final results.

src/JsonApiDotNetCore/Queries/Expressions/QueryableHandlerExpression.cs

+2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ public QueryableHandlerExpression(object queryableHandler, StringValues paramete
2121
_parameterValue = parameterValue;
2222
}
2323

24+
#pragma warning disable AV1130 // Return type in method signature should be an interface to an unchangeable collection
2425
public IQueryable<TResource> Apply<TResource>(IQueryable<TResource> query)
2526
where TResource : class, IIdentifiable
27+
#pragma warning restore AV1130 // Return type in method signature should be an interface to an unchangeable collection
2628
{
2729
var handler = (Func<IQueryable<TResource>, StringValues, IQueryable<TResource>>)_queryableHandler;
2830
return handler(query, _parameterValue);

src/JsonApiDotNetCore/Queries/FieldSelection.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ public sealed class FieldSelection : Dictionary<ResourceType, FieldSelectors>
1414
{
1515
public bool IsEmpty => Values.All(selectors => selectors.IsEmpty);
1616

17-
public ISet<ResourceType> GetResourceTypes()
17+
public IReadOnlySet<ResourceType> GetResourceTypes()
1818
{
1919
return Keys.ToHashSet();
2020
}
2121

22-
#pragma warning disable AV1130 // Return type in method signature should be a collection interface instead of a concrete type
22+
#pragma warning disable AV1130 // Return type in method signature should be an interface to an unchangeable collection
2323
public FieldSelectors GetOrCreateSelectors(ResourceType resourceType)
24-
#pragma warning restore AV1130 // Return type in method signature should be a collection interface instead of a concrete type
24+
#pragma warning restore AV1130 // Return type in method signature should be an interface to an unchangeable collection
2525
{
2626
ArgumentGuard.NotNull(resourceType, nameof(resourceType));
2727

src/JsonApiDotNetCore/Queries/Internal/Parsing/Token.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ public sealed class Token
88
public TokenKind Kind { get; }
99
public string? Value { get; }
1010

11-
public Token(TokenKind kind, string? value = null)
11+
public Token(TokenKind kind)
1212
{
1313
Kind = kind;
14+
}
15+
16+
public Token(TokenKind kind, string value)
17+
: this(kind)
18+
{
1419
Value = value;
1520
}
1621

src/JsonApiDotNetCore/Queries/Internal/QueryLayerComposer.cs

+3-5
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,7 @@ public QueryLayer ComposeSecondaryLayerForRelationship(ResourceType secondaryRes
305305
return secondaryLayer;
306306
}
307307

308-
#pragma warning disable AV1130 // Return type in method signature should be a collection interface instead of a concrete type
309308
private FieldSelection GetSelectionForRelationship(ResourceType secondaryResourceType)
310-
#pragma warning restore AV1130 // Return type in method signature should be a collection interface instead of a concrete type
311309
{
312310
var selection = new FieldSelection();
313311
FieldSelectors selectors = selection.GetOrCreateSelectors(secondaryResourceType);
@@ -404,7 +402,7 @@ public QueryLayer ComposeForUpdate<TId>(TId id, ResourceType primaryResourceType
404402
foreach (RelationshipAttribute relationship in _targetedFields.Relationships)
405403
{
406404
object? rightValue = relationship.GetValue(primaryResource);
407-
ICollection<IIdentifiable> rightResourceIds = _collectionConverter.ExtractResources(rightValue);
405+
HashSet<IIdentifiable> rightResourceIds = _collectionConverter.ExtractResources(rightValue).ToHashSet(IdentifiableComparer.Instance);
408406

409407
if (rightResourceIds.Any())
410408
{
@@ -527,9 +525,9 @@ protected virtual PaginationExpression GetPagination(IReadOnlyCollection<QueryEx
527525
return pagination;
528526
}
529527

530-
#pragma warning disable AV1130 // Return type in method signature should be a collection interface instead of a concrete type
528+
#pragma warning disable AV1130 // Return type in method signature should be an interface to an unchangeable collection
531529
protected virtual FieldSelection? GetSelectionForSparseAttributeSet(ResourceType resourceType)
532-
#pragma warning restore AV1130 // Return type in method signature should be a collection interface instead of a concrete type
530+
#pragma warning restore AV1130 // Return type in method signature should be an interface to an unchangeable collection
533531
{
534532
ArgumentGuard.NotNull(resourceType, nameof(resourceType));
535533

src/JsonApiDotNetCore/Queries/Internal/QueryableBuilding/SelectClauseBuilder.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private Expression CreateLambdaBodyInitializer(FieldSelection selection, Resourc
7676
private Expression CreateLambdaBodyInitializerForTypeHierarchy(FieldSelection selection, ResourceType baseResourceType,
7777
IEnumerable<IEntityType> concreteEntityTypes, LambdaScope lambdaScope)
7878
{
79-
ISet<ResourceType> resourceTypes = selection.GetResourceTypes();
79+
IReadOnlySet<ResourceType> resourceTypes = selection.GetResourceTypes();
8080
Expression rootCondition = lambdaScope.Accessor;
8181

8282
foreach (IEntityType entityType in concreteEntityTypes)

0 commit comments

Comments
 (0)