Skip to content

Commit 42cff78

Browse files
authored
Update to Resharper v2023.2.1 (#1302)
* Update to Resharper v2023.2.1 * Add workaround for Resharper bug at https://youtrack.jetbrains.com/issue/RSRP-493256/Incorrect-possible-null-assignment * Use new formatting directives * Fail the build when capturing closures in lambdas within source generators project (they cause expensive allocations)
1 parent 952518a commit 42cff78

File tree

59 files changed

+645
-735
lines changed

Some content is hidden

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

59 files changed

+645
-735
lines changed

.config/dotnet-tools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"isRoot": true,
44
"tools": {
55
"jetbrains.resharper.globaltools": {
6-
"version": "2023.1.2",
6+
"version": "2023.2.1",
77
"commands": [
88
"jb"
99
]

src/Examples/NoEntityFrameworkExample/Services/InMemoryResourceService.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,16 @@ public Task<IReadOnlyCollection<TResource>> GetAsync(CancellationToken cancellat
8383
private void LogFiltersInTopScope()
8484
{
8585
// @formatter:wrap_chained_method_calls chop_always
86-
// @formatter:keep_existing_linebreaks true
86+
// @formatter:wrap_before_first_method_call true
8787

88-
FilterExpression[] filtersInTopScope = _constraintProviders.SelectMany(provider => provider.GetConstraints())
88+
FilterExpression[] filtersInTopScope = _constraintProviders
89+
.SelectMany(provider => provider.GetConstraints())
8990
.Where(constraint => constraint.Scope == null)
9091
.Select(constraint => constraint.Expression)
9192
.OfType<FilterExpression>()
9293
.ToArray();
9394

94-
// @formatter:keep_existing_linebreaks restore
95+
// @formatter:wrap_before_first_method_call restore
9596
// @formatter:wrap_chained_method_calls restore
9697

9798
FilterExpression? filter = LogicalExpression.Compose(LogicalOperator.And, filtersInTopScope);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=LambdaExpressionCanBeMadeStatic/@EntryIndexedValue">WARNING</s:String>
3+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=LambdaExpressionMustBeStatic/@EntryIndexedValue">WARNING</s:String>
4+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=LocalFunctionCanBeMadeStatic/@EntryIndexedValue">WARNING</s:String>
5+
</wpf:ResourceDictionary>

src/JsonApiDotNetCore/Queries/EvaluatedIncludeCache.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,16 @@ public void Set(IncludeExpression include)
3434
// then as a fallback, we feed the requested includes from query string to the response serializer.
3535

3636
// @formatter:wrap_chained_method_calls chop_always
37-
// @formatter:keep_existing_linebreaks true
37+
// @formatter:wrap_before_first_method_call true
3838

39-
_include = _constraintProviders.SelectMany(provider => provider.GetConstraints())
39+
_include = _constraintProviders
40+
.SelectMany(provider => provider.GetConstraints())
4041
.Where(constraint => constraint.Scope == null)
4142
.Select(constraint => constraint.Expression)
4243
.OfType<IncludeExpression>()
4344
.FirstOrDefault();
4445

45-
// @formatter:keep_existing_linebreaks restore
46+
// @formatter:wrap_before_first_method_call restore
4647
// @formatter:wrap_chained_method_calls restore
4748
_isAssigned = true;
4849
}

src/JsonApiDotNetCore/Queries/QueryLayerComposer.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ public QueryLayerComposer(IEnumerable<IQueryConstraintProvider> constraintProvid
4848
ExpressionInScope[] constraints = _constraintProviders.SelectMany(provider => provider.GetConstraints()).ToArray();
4949

5050
// @formatter:wrap_chained_method_calls chop_always
51-
// @formatter:keep_existing_linebreaks true
51+
// @formatter:wrap_before_first_method_call true
5252

5353
FilterExpression[] filtersInTopScope = constraints
5454
.Where(constraint => constraint.Scope == null)
5555
.Select(constraint => constraint.Expression)
5656
.OfType<FilterExpression>()
5757
.ToArray();
5858

59-
// @formatter:keep_existing_linebreaks restore
59+
// @formatter:wrap_before_first_method_call restore
6060
// @formatter:wrap_chained_method_calls restore
6161

6262
return GetFilter(filtersInTopScope, primaryResourceType);
@@ -83,15 +83,15 @@ public QueryLayerComposer(IEnumerable<IQueryConstraintProvider> constraintProvid
8383
ExpressionInScope[] constraints = _constraintProviders.SelectMany(provider => provider.GetConstraints()).ToArray();
8484

8585
// @formatter:wrap_chained_method_calls chop_always
86-
// @formatter:keep_existing_linebreaks true
86+
// @formatter:wrap_before_first_method_call true
8787

8888
FilterExpression[] filtersInSecondaryScope = constraints
8989
.Where(constraint => constraint.Scope == null)
9090
.Select(constraint => constraint.Expression)
9191
.OfType<FilterExpression>()
9292
.ToArray();
9393

94-
// @formatter:keep_existing_linebreaks restore
94+
// @formatter:wrap_before_first_method_call restore
9595
// @formatter:wrap_chained_method_calls restore
9696

9797
FilterExpression? primaryFilter = GetFilter(Array.Empty<QueryExpression>(), hasManyRelationship.LeftType);
@@ -146,14 +146,14 @@ private QueryLayer ComposeTopLayer(IEnumerable<ExpressionInScope> constraints, R
146146
using IDisposable _ = CodeTimingSessionManager.Current.Measure("Top-level query composition");
147147

148148
// @formatter:wrap_chained_method_calls chop_always
149-
// @formatter:keep_existing_linebreaks true
149+
// @formatter:wrap_before_first_method_call true
150150

151151
QueryExpression[] expressionsInTopScope = constraints
152152
.Where(constraint => constraint.Scope == null)
153153
.Select(constraint => constraint.Expression)
154154
.ToArray();
155155

156-
// @formatter:keep_existing_linebreaks restore
156+
// @formatter:wrap_before_first_method_call restore
157157
// @formatter:wrap_chained_method_calls restore
158158

159159
PaginationExpression topPagination = GetPagination(expressionsInTopScope, resourceType);
@@ -174,15 +174,15 @@ private IncludeExpression ComposeChildren(QueryLayer topLayer, ICollection<Expre
174174
using IDisposable _ = CodeTimingSessionManager.Current.Measure("Nested query composition");
175175

176176
// @formatter:wrap_chained_method_calls chop_always
177-
// @formatter:keep_existing_linebreaks true
177+
// @formatter:wrap_before_first_method_call true
178178

179179
IncludeExpression include = constraints
180180
.Where(constraint => constraint.Scope == null)
181181
.Select(constraint => constraint.Expression)
182182
.OfType<IncludeExpression>()
183183
.FirstOrDefault() ?? IncludeExpression.Empty;
184184

185-
// @formatter:keep_existing_linebreaks restore
185+
// @formatter:wrap_before_first_method_call restore
186186
// @formatter:wrap_chained_method_calls restore
187187

188188
IImmutableSet<IncludeElementExpression> includeElements = ProcessIncludeSet(include.Elements, topLayer, new List<RelationshipAttribute>(), constraints);
@@ -212,15 +212,14 @@ private IImmutableSet<IncludeElementExpression> ProcessIncludeSet(IImmutableSet<
212212
};
213213

214214
// @formatter:wrap_chained_method_calls chop_always
215-
// @formatter:keep_existing_linebreaks true
215+
// @formatter:wrap_before_first_method_call true
216216

217217
QueryExpression[] expressionsInCurrentScope = constraints
218-
.Where(constraint =>
219-
constraint.Scope != null && constraint.Scope.Fields.SequenceEqual(relationshipChain))
218+
.Where(constraint => constraint.Scope != null && constraint.Scope.Fields.SequenceEqual(relationshipChain))
220219
.Select(constraint => constraint.Expression)
221220
.ToArray();
222221

223-
// @formatter:keep_existing_linebreaks restore
222+
// @formatter:wrap_before_first_method_call restore
224223
// @formatter:wrap_chained_method_calls restore
225224

226225
ResourceType resourceType = includeElement.Relationship.RightType;

src/JsonApiDotNetCore/Queries/SparseFieldSetCache.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public SparseFieldSetCache(IEnumerable<IQueryConstraintProvider> constraintProvi
2929
private static IDictionary<ResourceType, IImmutableSet<ResourceFieldAttribute>> BuildSourceTable(IEnumerable<IQueryConstraintProvider> constraintProviders)
3030
{
3131
// @formatter:wrap_chained_method_calls chop_always
32-
// @formatter:keep_existing_linebreaks true
32+
// @formatter:wrap_before_first_method_call true
3333

3434
KeyValuePair<ResourceType, SparseFieldSetExpression>[] sparseFieldTables = constraintProviders
3535
.SelectMany(provider => provider.GetConstraints())
@@ -40,7 +40,7 @@ private static IDictionary<ResourceType, IImmutableSet<ResourceFieldAttribute>>
4040
.SelectMany(table => table)
4141
.ToArray();
4242

43-
// @formatter:keep_existing_linebreaks restore
43+
// @formatter:wrap_before_first_method_call restore
4444
// @formatter:wrap_chained_method_calls restore
4545

4646
var mergedTable = new Dictionary<ResourceType, ImmutableHashSet<ResourceFieldAttribute>.Builder>();

src/JsonApiDotNetCore/QueryStrings/IncludeQueryStringParameterReader.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,14 @@ public virtual void Read(string parameterName, StringValues parameterValue)
4747
{
4848
try
4949
{
50+
// Workaround for https://youtrack.jetbrains.com/issue/RSRP-493256/Incorrect-possible-null-assignment
51+
// ReSharper disable once AssignNullToNotNullAttribute
5052
_includeExpression = GetInclude(parameterValue.ToString());
5153
}
5254
catch (QueryParseException exception)
5355
{
56+
// Workaround for https://youtrack.jetbrains.com/issue/RSRP-493256/Incorrect-possible-null-assignment
57+
// ReSharper disable once AssignNullToNotNullAttribute
5458
string specificMessage = exception.GetMessageWithPosition(parameterValue.ToString());
5559
throw new InvalidQueryStringParameterException(parameterName, "The specified include is invalid.", specificMessage, exception);
5660
}

src/JsonApiDotNetCore/QueryStrings/PaginationQueryStringParameterReader.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public virtual void Read(string parameterName, StringValues parameterValue)
5858

5959
try
6060
{
61+
// Workaround for https://youtrack.jetbrains.com/issue/RSRP-493256/Incorrect-possible-null-assignment
62+
// ReSharper disable once AssignNullToNotNullAttribute
6163
PaginationQueryStringValueExpression constraint = GetPageConstraint(parameterValue.ToString());
6264

6365
if (constraint.Elements.Any(element => element.Scope == null))
@@ -80,6 +82,8 @@ public virtual void Read(string parameterName, StringValues parameterValue)
8082
}
8183
catch (QueryParseException exception)
8284
{
85+
// Workaround for https://youtrack.jetbrains.com/issue/RSRP-493256/Incorrect-possible-null-assignment
86+
// ReSharper disable once AssignNullToNotNullAttribute
8387
string specificMessage = exception.GetMessageWithPosition(isParameterNameValid ? parameterValue.ToString() : parameterName);
8488
throw new InvalidQueryStringParameterException(parameterName, "The specified pagination is invalid.", specificMessage, exception);
8589
}

src/JsonApiDotNetCore/QueryStrings/SortQueryStringParameterReader.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,16 @@ public virtual void Read(string parameterName, StringValues parameterValue)
5959
ResourceFieldChainExpression? scope = GetScope(parameterName);
6060
parameterNameIsValid = true;
6161

62+
// Workaround for https://youtrack.jetbrains.com/issue/RSRP-493256/Incorrect-possible-null-assignment
63+
// ReSharper disable once AssignNullToNotNullAttribute
6264
SortExpression sort = GetSort(parameterValue.ToString(), scope);
6365
var expressionInScope = new ExpressionInScope(scope, sort);
6466
_constraints.Add(expressionInScope);
6567
}
6668
catch (QueryParseException exception)
6769
{
70+
// Workaround for https://youtrack.jetbrains.com/issue/RSRP-493256/Incorrect-possible-null-assignment
71+
// ReSharper disable once AssignNullToNotNullAttribute
6872
string specificMessage = exception.GetMessageWithPosition(parameterNameIsValid ? parameterValue.ToString() : parameterName);
6973
throw new InvalidQueryStringParameterException(parameterName, "The specified sort is invalid.", specificMessage, exception);
7074
}

src/JsonApiDotNetCore/QueryStrings/SparseFieldSetQueryStringParameterReader.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,15 @@ public virtual void Read(string parameterName, StringValues parameterValue)
6363
ResourceType resourceType = GetScope(parameterName);
6464
parameterNameIsValid = true;
6565

66+
// Workaround for https://youtrack.jetbrains.com/issue/RSRP-493256/Incorrect-possible-null-assignment
67+
// ReSharper disable once AssignNullToNotNullAttribute
6668
SparseFieldSetExpression sparseFieldSet = GetSparseFieldSet(parameterValue.ToString(), resourceType);
6769
_sparseFieldTableBuilder[resourceType] = sparseFieldSet;
6870
}
6971
catch (QueryParseException exception)
7072
{
73+
// Workaround for https://youtrack.jetbrains.com/issue/RSRP-493256/Incorrect-possible-null-assignment
74+
// ReSharper disable once AssignNullToNotNullAttribute
7175
string specificMessage = exception.GetMessageWithPosition(parameterNameIsValid ? parameterValue.ToString() : parameterName);
7276
throw new InvalidQueryStringParameterException(parameterName, "The specified fieldset is invalid.", specificMessage, exception);
7377
}

src/JsonApiDotNetCore/Repositories/EntityFrameworkCoreRepository.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ protected virtual IQueryable<TResource> ApplyQueryLayer(QueryLayer queryLayer)
119119
IQueryable<TResource> source = GetAll();
120120

121121
// @formatter:wrap_chained_method_calls chop_always
122-
// @formatter:keep_existing_linebreaks true
122+
// @formatter:wrap_before_first_method_call true
123123

124124
QueryableHandlerExpression[] queryableHandlers = _constraintProviders
125125
.SelectMany(provider => provider.GetConstraints())
@@ -128,7 +128,7 @@ protected virtual IQueryable<TResource> ApplyQueryLayer(QueryLayer queryLayer)
128128
.OfType<QueryableHandlerExpression>()
129129
.ToArray();
130130

131-
// @formatter:keep_existing_linebreaks restore
131+
// @formatter:wrap_before_first_method_call restore
132132
// @formatter:wrap_chained_method_calls restore
133133

134134
foreach (QueryableHandlerExpression queryableHandler in queryableHandlers)
@@ -470,14 +470,14 @@ private IEnumerable GetRightValueToStoreForAddToToMany(TResource leftResource, H
470470
object? rightValueStored = relationship.GetValue(leftResource);
471471

472472
// @formatter:wrap_chained_method_calls chop_always
473-
// @formatter:keep_existing_linebreaks true
473+
// @formatter:wrap_before_first_method_call true
474474

475475
HashSet<IIdentifiable> rightResourceIdsStored = _collectionConverter
476476
.ExtractResources(rightValueStored)
477477
.Select(rightResource => _dbContext.GetTrackedOrAttach(rightResource))
478478
.ToHashSet(IdentifiableComparer.Instance);
479479

480-
// @formatter:keep_existing_linebreaks restore
480+
// @formatter:wrap_before_first_method_call restore
481481
// @formatter:wrap_chained_method_calls restore
482482

483483
if (rightResourceIdsStored.Any())
@@ -519,15 +519,15 @@ public virtual async Task RemoveFromToManyRelationshipAsync(TResource leftResour
519519
object? rightValueStored = relationship.GetValue(leftResourceTracked);
520520

521521
// @formatter:wrap_chained_method_calls chop_always
522-
// @formatter:keep_existing_linebreaks true
522+
// @formatter:wrap_before_first_method_call true
523523

524524
IIdentifiable[] rightResourceIdsStored = _collectionConverter
525525
.ExtractResources(rightValueStored)
526526
.Concat(extraResourceIdsToRemove)
527527
.Select(rightResource => _dbContext.GetTrackedOrAttach(rightResource))
528528
.ToArray();
529529

530-
// @formatter:keep_existing_linebreaks restore
530+
// @formatter:wrap_before_first_method_call restore
531531
// @formatter:wrap_chained_method_calls restore
532532

533533
rightValueStored = _collectionConverter.CopyToTypedCollection(rightResourceIdsStored, relationship.Property.PropertyType);

test/JsonApiDotNetCoreTests/IntegrationTests/Archiving/TelevisionBroadcastDefinition.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private bool IsRequestingCollectionOfTelevisionBroadcasts()
7171
private bool IsIncludingCollectionOfTelevisionBroadcasts()
7272
{
7373
// @formatter:wrap_chained_method_calls chop_always
74-
// @formatter:keep_existing_linebreaks true
74+
// @formatter:wrap_before_first_method_call true
7575

7676
IncludeElementExpression[] includeElements = _constraintProviders
7777
.SelectMany(provider => provider.GetConstraints())
@@ -80,7 +80,7 @@ private bool IsIncludingCollectionOfTelevisionBroadcasts()
8080
.SelectMany(include => include.Elements)
8181
.ToArray();
8282

83-
// @formatter:keep_existing_linebreaks restore
83+
// @formatter:wrap_before_first_method_call restore
8484
// @formatter:wrap_chained_method_calls restore
8585

8686
foreach (IncludeElementExpression includeElement in includeElements)

test/JsonApiDotNetCoreTests/IntegrationTests/Archiving/TelevisionFakers.cs

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,31 @@
11
using Bogus;
22
using TestBuildingBlocks;
33

4-
// @formatter:wrap_chained_method_calls chop_always
5-
// @formatter:keep_existing_linebreaks true
4+
// @formatter:wrap_chained_method_calls chop_if_long
5+
// @formatter:wrap_before_first_method_call true
66

77
namespace JsonApiDotNetCoreTests.IntegrationTests.Archiving;
88

99
internal sealed class TelevisionFakers : FakerContainer
1010
{
11-
private readonly Lazy<Faker<TelevisionNetwork>> _lazyTelevisionNetworkFaker = new(() =>
12-
new Faker<TelevisionNetwork>()
13-
.UseSeed(GetFakerSeed())
14-
.RuleFor(network => network.Name, faker => faker.Company.CompanyName()));
11+
private readonly Lazy<Faker<TelevisionNetwork>> _lazyTelevisionNetworkFaker = new(() => new Faker<TelevisionNetwork>()
12+
.UseSeed(GetFakerSeed())
13+
.RuleFor(network => network.Name, faker => faker.Company.CompanyName()));
1514

16-
private readonly Lazy<Faker<TelevisionStation>> _lazyTelevisionStationFaker = new(() =>
17-
new Faker<TelevisionStation>()
18-
.UseSeed(GetFakerSeed())
19-
.RuleFor(station => station.Name, faker => faker.Company.CompanyName()));
15+
private readonly Lazy<Faker<TelevisionStation>> _lazyTelevisionStationFaker = new(() => new Faker<TelevisionStation>()
16+
.UseSeed(GetFakerSeed())
17+
.RuleFor(station => station.Name, faker => faker.Company.CompanyName()));
2018

21-
private readonly Lazy<Faker<TelevisionBroadcast>> _lazyTelevisionBroadcastFaker = new(() =>
22-
new Faker<TelevisionBroadcast>()
23-
.UseSeed(GetFakerSeed())
24-
.RuleFor(broadcast => broadcast.Title, faker => faker.Lorem.Sentence())
25-
.RuleFor(broadcast => broadcast.AiredAt, faker => faker.Date.PastOffset()
26-
.TruncateToWholeMilliseconds())
27-
.RuleFor(broadcast => broadcast.ArchivedAt, faker => faker.Date.RecentOffset()
28-
.TruncateToWholeMilliseconds()));
19+
private readonly Lazy<Faker<TelevisionBroadcast>> _lazyTelevisionBroadcastFaker = new(() => new Faker<TelevisionBroadcast>()
20+
.UseSeed(GetFakerSeed())
21+
.RuleFor(broadcast => broadcast.Title, faker => faker.Lorem.Sentence())
22+
.RuleFor(broadcast => broadcast.AiredAt, faker => faker.Date.PastOffset().TruncateToWholeMilliseconds())
23+
.RuleFor(broadcast => broadcast.ArchivedAt, faker => faker.Date.RecentOffset().TruncateToWholeMilliseconds()));
2924

30-
private readonly Lazy<Faker<BroadcastComment>> _lazyBroadcastCommentFaker = new(() =>
31-
new Faker<BroadcastComment>()
32-
.UseSeed(GetFakerSeed())
33-
.RuleFor(comment => comment.Text, faker => faker.Lorem.Paragraph())
34-
.RuleFor(comment => comment.CreatedAt, faker => faker.Date.PastOffset()
35-
.TruncateToWholeMilliseconds()));
25+
private readonly Lazy<Faker<BroadcastComment>> _lazyBroadcastCommentFaker = new(() => new Faker<BroadcastComment>()
26+
.UseSeed(GetFakerSeed())
27+
.RuleFor(comment => comment.Text, faker => faker.Lorem.Paragraph())
28+
.RuleFor(comment => comment.CreatedAt, faker => faker.Date.PastOffset().TruncateToWholeMilliseconds()));
3629

3730
public Faker<TelevisionNetwork> TelevisionNetwork => _lazyTelevisionNetworkFaker.Value;
3831
public Faker<TelevisionStation> TelevisionStation => _lazyTelevisionStationFaker.Value;

0 commit comments

Comments
 (0)