Skip to content

Commit 5068bd7

Browse files
author
Bart Koelman
committed
AV1706: Don't use single-letter variables
1 parent 599e103 commit 5068bd7

File tree

72 files changed

+346
-335
lines changed

Some content is hidden

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

72 files changed

+346
-335
lines changed

benchmarks/Query/QueryParserBenchmarks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void ComplexQuery()
107107

108108
private void Run(int iterations, Action action)
109109
{
110-
for (int i = 0; i < iterations; i++)
110+
for (int index = 0; index < iterations; index++)
111111
{
112112
action();
113113
}

src/Examples/JsonApiDotNetCoreExample/Data/AppDbContext.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ public AppDbContext(DbContextOptions<AppDbContext> options)
2323
protected override void OnModelCreating(ModelBuilder builder)
2424
{
2525
builder.Entity<TodoItem>()
26-
.HasOne(t => t.Assignee)
27-
.WithMany(p => p.AssignedTodoItems);
26+
.HasOne(todoItem => todoItem.Assignee)
27+
.WithMany(person => person.AssignedTodoItems);
2828

2929
builder.Entity<TodoItem>()
30-
.HasOne(t => t.Owner)
31-
.WithMany(p => p.TodoItems);
30+
.HasOne(todoItem => todoItem.Owner)
31+
.WithMany(person => person.TodoItems);
3232

3333
builder.Entity<ArticleTag>()
3434
.HasKey(bc => new
@@ -45,23 +45,23 @@ protected override void OnModelCreating(ModelBuilder builder)
4545
});
4646

4747
builder.Entity<Person>()
48-
.HasOne(t => t.StakeHolderTodoItem)
49-
.WithMany(t => t.StakeHolders)
48+
.HasOne(person => person.StakeHolderTodoItem)
49+
.WithMany(todoItem => todoItem.StakeHolders)
5050
.OnDelete(DeleteBehavior.Cascade);
5151

5252
builder.Entity<TodoItem>()
53-
.HasMany(t => t.ChildTodoItems)
54-
.WithOne(t => t.ParentTodo);
53+
.HasMany(todoItem => todoItem.ChildTodoItems)
54+
.WithOne(todoItem => todoItem.ParentTodo);
5555

5656
builder.Entity<Passport>()
57-
.HasOne(p => p.Person)
58-
.WithOne(p => p.Passport)
57+
.HasOne(passport => passport.Person)
58+
.WithOne(person => person.Passport)
5959
.HasForeignKey<Person>("PassportKey")
6060
.OnDelete(DeleteBehavior.SetNull);
6161

6262
builder.Entity<TodoItem>()
63-
.HasOne(p => p.OneToOnePerson)
64-
.WithOne(p => p.OneToOneTodoItem)
63+
.HasOne(todoItem => todoItem.OneToOnePerson)
64+
.WithOne(person => person.OneToOneTodoItem)
6565
.HasForeignKey<TodoItem>("OneToOnePersonKey");
6666
}
6767
}

src/Examples/JsonApiDotNetCoreExample/Definitions/ArticleHooksDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public ArticleHooksDefinition(IResourceGraph resourceGraph)
2121

2222
public override IEnumerable<Article> OnReturn(HashSet<Article> resources, ResourcePipeline pipeline)
2323
{
24-
if (pipeline == ResourcePipeline.GetSingle && resources.Any(r => r.Caption == "Classified"))
24+
if (pipeline == ResourcePipeline.GetSingle && resources.Any(article => article.Caption == "Classified"))
2525
{
2626
throw new JsonApiException(new Error(HttpStatusCode.Forbidden)
2727
{

src/JsonApiDotNetCore/Configuration/ResourceGraph.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public ResourceContext GetResourceContext(string resourceName)
3434
{
3535
ArgumentGuard.NotNullNorEmpty(resourceName, nameof(resourceName));
3636

37-
return _resources.SingleOrDefault(e => e.PublicName == resourceName);
37+
return _resources.SingleOrDefault(resourceContext => resourceContext.PublicName == resourceName);
3838
}
3939

4040
/// <inheritdoc />
@@ -43,8 +43,8 @@ public ResourceContext GetResourceContext(Type resourceType)
4343
ArgumentGuard.NotNull(resourceType, nameof(resourceType));
4444

4545
return IsLazyLoadingProxyForResourceType(resourceType)
46-
? _resources.SingleOrDefault(e => e.ResourceType == resourceType.BaseType)
47-
: _resources.SingleOrDefault(e => e.ResourceType == resourceType);
46+
? _resources.SingleOrDefault(resourceContext => resourceContext.ResourceType == resourceType.BaseType)
47+
: _resources.SingleOrDefault(resourceContext => resourceContext.ResourceType == resourceType);
4848
}
4949

5050
/// <inheritdoc />
@@ -109,7 +109,8 @@ public RelationshipAttribute GetInverseRelationship(RelationshipAttribute relati
109109
return null;
110110
}
111111

112-
return GetResourceContext(relationship.RightType).Relationships.SingleOrDefault(r => r.Property == relationship.InverseNavigationProperty);
112+
return GetResourceContext(relationship.RightType).Relationships
113+
.SingleOrDefault(nextRelationship => nextRelationship.Property == relationship.InverseNavigationProperty);
113114
}
114115

115116
private IReadOnlyCollection<ResourceFieldAttribute> Getter<TResource>(Expression<Func<TResource, dynamic>> selector = null,
@@ -145,7 +146,7 @@ private IReadOnlyCollection<ResourceFieldAttribute> Getter<TResource>(Expression
145146
// model => model.Field1
146147
try
147148
{
148-
targeted.Add(available.Single(f => f.Property.Name == memberExpression.Member.Name));
149+
targeted.Add(available.Single(field => field.Property.Name == memberExpression.Member.Name));
149150
return targeted;
150151
}
151152
catch (InvalidOperationException)
@@ -169,7 +170,7 @@ private IReadOnlyCollection<ResourceFieldAttribute> Getter<TResource>(Expression
169170
foreach (MemberInfo member in newExpression.Members)
170171
{
171172
memberName = member.Name;
172-
targeted.Add(available.Single(f => f.Property.Name == memberName));
173+
targeted.Add(available.Single(field => field.Property.Name == memberName));
173174
}
174175

175176
return targeted;

src/JsonApiDotNetCore/Configuration/ResourceGraphBuilder.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public ResourceGraphBuilder Add(Type resourceType, Type idType = null, string pu
102102
{
103103
ArgumentGuard.NotNull(resourceType, nameof(resourceType));
104104

105-
if (_resources.Any(e => e.ResourceType == resourceType))
105+
if (_resources.Any(resourceContext => resourceContext.ResourceType == resourceType))
106106
{
107107
return this;
108108
}
@@ -205,7 +205,7 @@ private IReadOnlyCollection<RelationshipAttribute> GetRelationships(Type resourc
205205

206206
if (attribute is HasManyThroughAttribute hasManyThroughAttribute)
207207
{
208-
PropertyInfo throughProperty = properties.SingleOrDefault(p => p.Name == hasManyThroughAttribute.ThroughPropertyName);
208+
PropertyInfo throughProperty = properties.SingleOrDefault(property => property.Name == hasManyThroughAttribute.ThroughPropertyName);
209209

210210
if (throughProperty == null)
211211
{
@@ -240,14 +240,15 @@ private IReadOnlyCollection<RelationshipAttribute> GetRelationships(Type resourc
240240
else
241241
{
242242
// In case of a non-self-referencing many-to-many relationship, we just pick the single compatible type.
243-
hasManyThroughAttribute.LeftProperty = throughProperties.SingleOrDefault(x => x.PropertyType.IsAssignableFrom(resourceType)) ??
243+
hasManyThroughAttribute.LeftProperty =
244+
throughProperties.SingleOrDefault(property => property.PropertyType.IsAssignableFrom(resourceType)) ??
244245
throw new InvalidConfigurationException($"'{throughType}' does not contain a navigation property to type '{resourceType}'.");
245246
}
246247

247248
// ArticleTag.ArticleId
248249
string leftIdPropertyName = hasManyThroughAttribute.LeftIdPropertyName ?? hasManyThroughAttribute.LeftProperty.Name + "Id";
249250

250-
hasManyThroughAttribute.LeftIdProperty = throughProperties.SingleOrDefault(x => x.Name == leftIdPropertyName) ??
251+
hasManyThroughAttribute.LeftIdProperty = throughProperties.SingleOrDefault(property => property.Name == leftIdPropertyName) ??
251252
throw new InvalidConfigurationException(
252253
$"'{throughType}' does not contain a relationship ID property to type '{resourceType}' with name '{leftIdPropertyName}'.");
253254

@@ -262,15 +263,16 @@ private IReadOnlyCollection<RelationshipAttribute> GetRelationships(Type resourc
262263
else
263264
{
264265
// In case of a non-self-referencing many-to-many relationship, we just pick the single compatible type.
265-
hasManyThroughAttribute.RightProperty = throughProperties.SingleOrDefault(x => x.PropertyType == hasManyThroughAttribute.RightType) ??
266+
hasManyThroughAttribute.RightProperty =
267+
throughProperties.SingleOrDefault(property => property.PropertyType == hasManyThroughAttribute.RightType) ??
266268
throw new InvalidConfigurationException(
267269
$"'{throughType}' does not contain a navigation property to type '{hasManyThroughAttribute.RightType}'.");
268270
}
269271

270272
// ArticleTag.TagId
271273
string rightIdPropertyName = hasManyThroughAttribute.RightIdPropertyName ?? hasManyThroughAttribute.RightProperty.Name + "Id";
272274

273-
hasManyThroughAttribute.RightIdProperty = throughProperties.SingleOrDefault(x => x.Name == rightIdPropertyName) ??
275+
hasManyThroughAttribute.RightIdProperty = throughProperties.SingleOrDefault(property => property.Name == rightIdPropertyName) ??
274276
throw new InvalidConfigurationException(
275277
$"'{throughType}' does not contain a relationship ID property to type '{hasManyThroughAttribute.RightType}' with name '{rightIdPropertyName}'.");
276278
}
@@ -339,7 +341,8 @@ private IReadOnlyCollection<EagerLoadAttribute> GetEagerLoads(Type resourceType,
339341

340342
private Type TypeOrElementType(Type type)
341343
{
342-
Type[] interfaces = type.GetInterfaces().Where(t => t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IEnumerable<>)).ToArray();
344+
Type[] interfaces = type.GetInterfaces()
345+
.Where(@interface => @interface.IsGenericType && @interface.GetGenericTypeDefinition() == typeof(IEnumerable<>)).ToArray();
343346

344347
return interfaces.Length == 1 ? interfaces.Single().GenericTypeArguments[0] : type;
345348
}

src/JsonApiDotNetCore/Configuration/ServiceDiscoveryFacade.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ private void AddResourceHookDefinitions(Assembly assembly, ResourceDescriptor id
166166
_services.AddScoped(typeof(ResourceHooksDefinition<>).MakeGenericType(identifiable.ResourceType), resourceDefinition);
167167
}
168168
}
169-
catch (InvalidOperationException e)
169+
catch (InvalidOperationException exception)
170170
{
171171
throw new InvalidConfigurationException($"Cannot define multiple ResourceHooksDefinition<> implementations for '{identifiable.ResourceType}'",
172-
e);
172+
exception);
173173
}
174174
}
175175

src/JsonApiDotNetCore/Configuration/TypeLocator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ internal static class TypeLocator
1616
/// </summary>
1717
public static Type TryGetIdType(Type resourceType)
1818
{
19-
Type identifiableInterface = resourceType.GetInterfaces()
20-
.FirstOrDefault(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IIdentifiable<>));
19+
Type identifiableInterface = resourceType.GetInterfaces().FirstOrDefault(@interface =>
20+
@interface.IsGenericType && @interface.GetGenericTypeDefinition() == typeof(IIdentifiable<>));
2121

2222
return identifiableInterface?.GetGenericArguments()[0];
2323
}

src/JsonApiDotNetCore/Hooks/Internal/Discovery/HooksDiscovery.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class HooksDiscovery<TResource> : IHooksDiscovery<TResource>
3535

3636
public HooksDiscovery(IServiceProvider provider)
3737
{
38-
_allHooks = Enum.GetValues(typeof(ResourceHook)).Cast<ResourceHook>().Where(h => h != ResourceHook.None).ToArray();
38+
_allHooks = Enum.GetValues(typeof(ResourceHook)).Cast<ResourceHook>().Where(hook => hook != ResourceHook.None).ToArray();
3939

4040
Type containerType;
4141

src/JsonApiDotNetCore/Hooks/Internal/Execution/DiffableResourceHashSet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public IEnumerable<ResourceDiffPair<TResource>> GetDiffs()
5151

5252
foreach (TResource resource in this)
5353
{
54-
TResource currentValueInDatabase = _databaseValues.Single(e => resource.StringId == e.StringId);
54+
TResource currentValueInDatabase = _databaseValues.Single(databaseResource => resource.StringId == databaseResource.StringId);
5555
yield return new ResourceDiffPair<TResource>(resource, currentValueInDatabase);
5656
}
5757
}

src/JsonApiDotNetCore/Hooks/Internal/Execution/HookExecutorHelper.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ public IResourceHookContainer<TResource> GetResourceHookContainer<TResource>(Res
8787
return (IResourceHookContainer<TResource>)GetResourceHookContainer(typeof(TResource), hook);
8888
}
8989

90-
public IEnumerable LoadDbValues(LeftType resourceTypeForRepository, IEnumerable resources,
91-
params RelationshipAttribute[] relationshipsToNextLayer)
90+
public IEnumerable LoadDbValues(LeftType resourceTypeForRepository, IEnumerable resources, params RelationshipAttribute[] relationshipsToNextLayer)
9291
{
9392
LeftType idType = TypeHelper.GetIdType(resourceTypeForRepository);
9493

@@ -97,7 +96,7 @@ public IEnumerable LoadDbValues(LeftType resourceTypeForRepository, IEnumerable
9796
idType);
9897

9998
IEnumerable<IIdentifiable> cast = ((IEnumerable<object>)resources).Cast<IIdentifiable>();
100-
IList ids = TypeHelper.CopyToList(cast.Select(i => i.GetTypedId()), idType);
99+
IList ids = TypeHelper.CopyToList(cast.Select(resource => resource.GetTypedId()), idType);
101100
var values = (IEnumerable)parameterizedGetWhere.Invoke(this, ArrayFactory.Create<object>(ids, relationshipsToNextLayer));
102101

103102
if (values == null)

src/JsonApiDotNetCore/Hooks/Internal/Execution/RelationshipsDictionary.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public Dictionary<RelationshipAttribute, HashSet<TResource>> GetByRelationship<T
4747
/// <inheritdoc />
4848
public Dictionary<RelationshipAttribute, HashSet<TResource>> GetByRelationship(Type resourceType)
4949
{
50-
return this.Where(p => p.Key.RightType == resourceType).ToDictionary(p => p.Key, p => p.Value);
50+
return this.Where(pair => pair.Key.RightType == resourceType).ToDictionary(pair => pair.Key, pair => pair.Value);
5151
}
5252

5353
/// <inheritdoc />
@@ -56,7 +56,7 @@ public HashSet<TResource> GetAffected(Expression<Func<TResource, object>> naviga
5656
ArgumentGuard.NotNull(navigationAction, nameof(navigationAction));
5757

5858
PropertyInfo property = TypeHelper.ParseNavigationExpression(navigationAction);
59-
return this.Where(p => p.Key.Property.Name == property.Name).Select(p => p.Value).SingleOrDefault();
59+
return this.Where(pair => pair.Key.Property.Name == property.Name).Select(pair => pair.Value).SingleOrDefault();
6060
}
6161
}
6262
}

src/JsonApiDotNetCore/Hooks/Internal/ResourceHookExecutor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public IEnumerable<TResource> BeforeUpdate<TResource>(IEnumerable<TResource> res
6969
{
7070
if (GetHook(ResourceHook.BeforeUpdate, resources, out IResourceHookContainer<TResource> container, out RootNode<TResource> node))
7171
{
72-
RelationshipAttribute[] relationships = node.RelationshipsToNextLayer.Select(p => p.Attribute).ToArray();
72+
RelationshipAttribute[] relationships = node.RelationshipsToNextLayer.Select(proxy => proxy.Attribute).ToArray();
7373
IEnumerable dbValues = LoadDbValues(typeof(TResource), (IEnumerable<TResource>)node.UniqueResources, ResourceHook.BeforeUpdate, relationships);
7474
var diff = new DiffableResourceHashSet<TResource>(node.UniqueResources, dbValues, node.LeftsToNextLayer(), _targetedFields);
7575
IEnumerable<TResource> updated = container.BeforeUpdate(diff, pipeline);
@@ -103,7 +103,7 @@ public IEnumerable<TResource> BeforeDelete<TResource>(IEnumerable<TResource> res
103103
{
104104
if (GetHook(ResourceHook.BeforeDelete, resources, out IResourceHookContainer<TResource> container, out RootNode<TResource> node))
105105
{
106-
RelationshipAttribute[] relationships = node.RelationshipsToNextLayer.Select(p => p.Attribute).ToArray();
106+
RelationshipAttribute[] relationships = node.RelationshipsToNextLayer.Select(proxy => proxy.Attribute).ToArray();
107107

108108
IEnumerable targetResources =
109109
LoadDbValues(typeof(TResource), (IEnumerable<TResource>)node.UniqueResources, ResourceHook.BeforeDelete, relationships) ??
@@ -312,7 +312,7 @@ private void FireNestedBeforeUpdateHooks(ResourcePipeline pipeline, NodeLayer la
312312
{
313313
if (uniqueResources.Cast<IIdentifiable>().Any())
314314
{
315-
RelationshipAttribute[] relationships = node.RelationshipsToNextLayer.Select(p => p.Attribute).ToArray();
315+
RelationshipAttribute[] relationships = node.RelationshipsToNextLayer.Select(proxy => proxy.Attribute).ToArray();
316316
IEnumerable dbValues = LoadDbValues(resourceType, uniqueResources, ResourceHook.BeforeUpdateRelationship, relationships);
317317

318318
// these are the resources of the current node grouped by
@@ -575,7 +575,7 @@ private void FireAfterUpdateRelationship(IResourceHookContainer container, IReso
575575
/// </param>
576576
private HashSet<string> GetIds(IEnumerable resources)
577577
{
578-
return new HashSet<string>(resources.Cast<IIdentifiable>().Select(e => e.StringId));
578+
return new HashSet<string>(resources.Cast<IIdentifiable>().Select(resource => resource.StringId));
579579
}
580580
}
581581
}

src/JsonApiDotNetCore/Hooks/Internal/Traversal/NodeLayer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public NodeLayer(List<IResourceNode> nodes)
2020

2121
public bool AnyResources()
2222
{
23-
return _collection.Any(n => n.UniqueResources.Cast<IIdentifiable>().Any());
23+
return _collection.Any(node => node.UniqueResources.Cast<IIdentifiable>().Any());
2424
}
2525

2626
public IEnumerator<IResourceNode> GetEnumerator()

src/JsonApiDotNetCore/Hooks/Internal/Traversal/RootNode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ public RootNode(IEnumerable<TResource> uniqueResources, RelationshipProxy[] popu
3636
public Dictionary<Type, Dictionary<RelationshipAttribute, IEnumerable>> LeftsToNextLayerByRelationships()
3737
{
3838
return _allRelationshipsToNextLayer.GroupBy(proxy => proxy.RightType)
39-
.ToDictionary(gdc => gdc.Key, gdc => gdc.ToDictionary(p => p.Attribute, _ => UniqueResources));
39+
.ToDictionary(gdc => gdc.Key, gdc => gdc.ToDictionary(proxy => proxy.Attribute, _ => UniqueResources));
4040
}
4141

4242
/// <summary>
4343
/// The current layer resources grouped by affected relationship to the next layer
4444
/// </summary>
4545
public Dictionary<RelationshipAttribute, IEnumerable> LeftsToNextLayer()
4646
{
47-
return RelationshipsToNextLayer.ToDictionary(p => p.Attribute, _ => UniqueResources);
47+
return RelationshipsToNextLayer.ToDictionary(proxy => proxy.Attribute, _ => UniqueResources);
4848
}
4949

5050
/// <summary>

src/JsonApiDotNetCore/Hooks/Internal/Traversal/TraversalHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ private RelationshipProxy[] GetPopulatedRelationships(LeftType leftType, IEnumer
216216
IEnumerable<RelationshipProxy> relationshipsFromLeftToRight =
217217
_relationshipProxies.Select(entry => entry.Value).Where(proxy => proxy.LeftType == leftType);
218218

219-
return relationshipsFromLeftToRight.Where(proxy => proxy.IsContextRelation || lefts.Any(p => proxy.GetValue(p) != null)).ToArray();
219+
return relationshipsFromLeftToRight.Where(proxy => proxy.IsContextRelation || lefts.Any(resource => proxy.GetValue(resource) != null)).ToArray();
220220
}
221221

222222
/// <summary>

0 commit comments

Comments
 (0)