Skip to content

Commit

Permalink
Static analysis: inconsistent naming and namespaces
Browse files Browse the repository at this point in the history
Part of #26805
  • Loading branch information
ajcvickers committed Dec 7, 2021
1 parent ad1cf49 commit 2813548
Show file tree
Hide file tree
Showing 29 changed files with 71 additions and 54 deletions.
6 changes: 3 additions & 3 deletions src/EFCore.Analyzers/InternalUsageDiagnosticAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Microsoft.EntityFrameworkCore;
public sealed class InternalUsageDiagnosticAnalyzer : DiagnosticAnalyzer
{
public const string Id = "EF1001";
private static readonly int EFLen = "EntityFrameworkCore".Length;
private static readonly int _efLen = "EntityFrameworkCore".Length;

private static readonly DiagnosticDescriptor _descriptor
= new(
Expand Down Expand Up @@ -318,8 +318,8 @@ private static bool IsInInternalNamespace(ISymbol symbol)
return
i != -1
&& (i == 0 || ns[i - 1] == '.')
&& i + EFLen < ns.Length
&& ns[i + EFLen] == '.'
&& i + _efLen < ns.Length
&& ns[i + _efLen] == '.'
&& ns.EndsWith(".Internal", StringComparison.Ordinal);
}

Expand Down
28 changes: 14 additions & 14 deletions src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ protected virtual void ValidateSharedContainerCompatibility(
{
var discriminatorValues = new Dictionary<object, IEntityType>();
IProperty? partitionKey = null;
int? analyticalTTL = null;
int? defaultTTL = null;
int? analyticalTtl = null;
int? defaultTtl = null;
ThroughputProperties? throughput = null;
IEntityType? firstEntityType = null;
foreach (var entityType in mappedTypes)
Expand Down Expand Up @@ -156,36 +156,36 @@ protected virtual void ValidateSharedContainerCompatibility(
discriminatorValues[discriminatorValue] = entityType;
}

var currentAnalyticalTTL = entityType.GetAnalyticalStoreTimeToLive();
if (currentAnalyticalTTL != null)
var currentAnalyticalTtl = entityType.GetAnalyticalStoreTimeToLive();
if (currentAnalyticalTtl != null)
{
if (analyticalTTL == null)
if (analyticalTtl == null)
{
analyticalTTL = currentAnalyticalTTL;
analyticalTtl = currentAnalyticalTtl;
}
else if (analyticalTTL != currentAnalyticalTTL)
else if (analyticalTtl != currentAnalyticalTtl)
{
var conflictingEntityType = mappedTypes.First(et => et.GetAnalyticalStoreTimeToLive() != null);
throw new InvalidOperationException(
CosmosStrings.AnalyticalTTLMismatch(
analyticalTTL, conflictingEntityType.DisplayName(), entityType.DisplayName(), currentAnalyticalTTL,
analyticalTtl, conflictingEntityType.DisplayName(), entityType.DisplayName(), currentAnalyticalTtl,
container));
}
}

var currentDefaultTTL = entityType.GetDefaultTimeToLive();
if (currentDefaultTTL != null)
var currentDefaultTtl = entityType.GetDefaultTimeToLive();
if (currentDefaultTtl != null)
{
if (defaultTTL == null)
if (defaultTtl == null)
{
defaultTTL = currentDefaultTTL;
defaultTtl = currentDefaultTtl;
}
else if (defaultTTL != currentDefaultTTL)
else if (defaultTtl != currentDefaultTtl)
{
var conflictingEntityType = mappedTypes.First(et => et.GetDefaultTimeToLive() != null);
throw new InvalidOperationException(
CosmosStrings.DefaultTTLMismatch(
defaultTTL, conflictingEntityType.DisplayName(), entityType.DisplayName(), currentDefaultTTL, container));
defaultTtl, conflictingEntityType.DisplayName(), entityType.DisplayName(), currentDefaultTtl, container));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.EntityFrameworkCore.Query;
namespace Microsoft.EntityFrameworkCore.Query.Internal;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Cosmos.Internal;
using Microsoft.EntityFrameworkCore.Cosmos.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Query.Internal;

#nullable disable

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.EntityFrameworkCore.Cosmos.Internal;
using Microsoft.EntityFrameworkCore.Cosmos.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal;
using Microsoft.EntityFrameworkCore.Query.Internal;
using Newtonsoft.Json.Linq;

#nullable disable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.EntityFrameworkCore.Query.Internal;
using Newtonsoft.Json.Linq;

#nullable disable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal;
/// </summary>
public class CosmosSqlTranslatingExpressionVisitor : ExpressionVisitor
{
private const string _runtimeParameterPrefix = QueryCompilationContext.QueryParameterPrefix + "entity_equality_";
private const string RuntimeParameterPrefix = QueryCompilationContext.QueryParameterPrefix + "entity_equality_";

private static readonly MethodInfo _parameterValueExtractor =
typeof(CosmosSqlTranslatingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(ParameterValueExtractor));
Expand Down Expand Up @@ -737,7 +737,7 @@ when sqlParameterExpression.Name.StartsWith(QueryCompilationContext.QueryParamet
);

var newParameterName =
$"{_runtimeParameterPrefix}"
$"{RuntimeParameterPrefix}"
+ $"{sqlParameterExpression.Name[QueryCompilationContext.QueryParameterPrefix.Length..]}_{property.Name}";

rewrittenSource = _queryCompilationContext.RegisterRuntimeParameter(newParameterName, lambda);
Expand Down Expand Up @@ -863,7 +863,7 @@ when sqlParameterExpression.Name.StartsWith(QueryCompilationContext.QueryParamet
QueryCompilationContext.QueryContextParameter);

var newParameterName =
$"{_runtimeParameterPrefix}"
$"{RuntimeParameterPrefix}"
+ $"{sqlParameterExpression.Name[QueryCompilationContext.QueryParameterPrefix.Length..]}_{property.Name}";

return _queryCompilationContext.RegisterRuntimeParameter(newParameterName, lambda);
Expand Down
16 changes: 8 additions & 8 deletions src/EFCore.Cosmos/Storage/Internal/ContainerProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ public record struct ContainerProperties
public ContainerProperties(
string containerId,
string partitionKey,
int? analyticalTTL,
int? defaultTTL,
int? analyticalTtl,
int? defaultTtl,
ThroughputProperties? throughput)
{
Id = containerId;
PartitionKey = partitionKey;
AnalyticalStoreTimeToLiveInSeconds = analyticalTTL;
DefaultTimeToLive = defaultTTL;
AnalyticalStoreTimeToLiveInSeconds = analyticalTtl;
DefaultTimeToLive = defaultTtl;
Throughput = throughput;
}

Expand All @@ -80,14 +80,14 @@ public ContainerProperties(
public void Deconstruct(
out string containerId,
out string partitionKey,
out int? analyticalTTL,
out int? defaultTTL,
out int? analyticalTtl,
out int? defaultTtl,
out ThroughputProperties? throughput)
{
containerId = Id;
partitionKey = PartitionKey;
analyticalTTL = AnalyticalStoreTimeToLiveInSeconds;
defaultTTL = DefaultTimeToLive;
analyticalTtl = AnalyticalStoreTimeToLiveInSeconds;
defaultTtl = DefaultTimeToLive;
throughput = Throughput;
}
}
12 changes: 6 additions & 6 deletions src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,23 @@ private IEnumerable<ContainerProperties> GetContainersToCreate(IModel model)
var mappedTypes = containerMapping.Value;
var containerName = containerMapping.Key;
string? partitionKey = null;
int? analyticalTTL = null;
int? defaultTTL = null;
int? analyticalTtl = null;
int? defaultTtl = null;
ThroughputProperties? throughput = null;

foreach (var entityType in mappedTypes)
{
partitionKey ??= GetPartitionKeyStoreName(entityType);
analyticalTTL ??= entityType.GetAnalyticalStoreTimeToLive();
defaultTTL ??= entityType.GetDefaultTimeToLive();
analyticalTtl ??= entityType.GetAnalyticalStoreTimeToLive();
defaultTtl ??= entityType.GetDefaultTimeToLive();
throughput ??= entityType.GetThroughput();
}

yield return new ContainerProperties(
containerName,
partitionKey!,
analyticalTTL,
defaultTTL,
analyticalTtl,
defaultTtl,
throughput);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.Cosmos/Storage/Internal/JsonCosmosSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal;
/// </summary>
public class JsonCosmosSerializer : CosmosSerializer
{
private static readonly Encoding DefaultEncoding = new UTF8Encoding(false, true);
private static readonly Encoding _defaultEncoding = new UTF8Encoding(false, true);

/// <inheritdoc />
public override T FromStream<T>(Stream stream)
Expand All @@ -36,7 +36,7 @@ public override T FromStream<T>(Stream stream)
public override Stream ToStream<T>(T input)
{
var streamPayload = new MemoryStream();
using (var streamWriter = new StreamWriter(streamPayload, encoding: DefaultEncoding, bufferSize: 1024, leaveOpen: true))
using (var streamWriter = new StreamWriter(streamPayload, encoding: _defaultEncoding, bufferSize: 1024, leaveOpen: true))
{
using var jsonTextWriter = new JsonTextWriter(streamWriter);
jsonTextWriter.Formatting = Formatting.None;
Expand Down
1 change: 1 addition & 0 deletions src/EFCore.Relational/Diagnostics/RelationalEventId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ private enum Id
// Query events
QueryClientEvaluationWarning = CoreEventId.RelationalBaseId + 500,
QueryPossibleUnintendedUseOfEqualsWarning,
// ReSharper disable twice InconsistentNaming
Obsolete_QueryPossibleExceptionWithAggregateOperatorWarning,
Obsolete_ValueConversionSqlLiteralWarning,
MultipleCollectionIncludeWarning,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore.Internal;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using Microsoft.EntityFrameworkCore.Query.Internal;

// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore.Internal;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1252,9 +1252,9 @@ protected override void ValidateInheritanceMapping(
}

// Hierarchy mapping strategy must be the same across all types of mappings
var isTPH = rootEntityType.FindPrimaryKey() == null
var isTph = rootEntityType.FindPrimaryKey() == null
|| rootEntityType.FindDiscriminatorProperty() != null;
if (isTPH)
if (isTph)
{
ValidateTPHMapping(rootEntityType, forTables: false);
ValidateTPHMapping(rootEntityType, forTables: true);
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.Relational/Metadata/Internal/RelationalModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public static IRelationalModel Create(
AddMappedFunctions(databaseModel, entityType);
}

AddTVFs(databaseModel);
AddTvfs(databaseModel);

foreach (var table in databaseModel.Tables.Values)
{
Expand Down Expand Up @@ -636,7 +636,7 @@ private static void AddMappedFunctions(RelationalModel databaseModel, IEntityTyp
functionMappings?.Reverse();
}

private static void AddTVFs(RelationalModel relationalModel)
private static void AddTvfs(RelationalModel relationalModel)
{
var model = relationalModel.Model;
foreach (IRuntimeDbFunction function in model.GetDbFunctions())
Expand Down
2 changes: 2 additions & 0 deletions src/EFCore.Relational/Query/Internal/BufferedDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,7 @@ public T GetFieldValue<T>(int ordinal)
_ => (T)_objects[_currentRowNumber * _objectCount + _ordinalToIndexMap[ordinal]]
};

// ReSharper disable once InconsistentNaming
public bool IsDBNull(int ordinal)
=> _nulls[_currentRowNumber * _nullCount + _nullOrdinalToIndexMap[ordinal]];

Expand All @@ -873,6 +874,7 @@ public bool Read()
public Task<T> GetFieldValueAsync<T>(int ordinal, CancellationToken cancellationToken)
=> Task.FromResult(GetFieldValue<T>(ordinal));

// ReSharper disable once InconsistentNaming
public Task<bool> IsDBNullAsync(int ordinal, CancellationToken cancellationToken)
=> Task.FromResult(IsDBNull(ordinal));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private static readonly MethodInfo _collectionAccessorAddMethodInfo
private readonly IDictionary<ParameterExpression, IDictionary<IProperty, int>> _materializationContextBindings
= new Dictionary<ParameterExpression, IDictionary<IProperty, int>>();

private readonly IDictionary<ParameterExpression, int> entityTypeIdentifyingExpressionOffsets
private readonly IDictionary<ParameterExpression, int> _entityTypeIdentifyingExpressionOffsets
= new Dictionary<ParameterExpression, int>();

public ShaperProcessingExpressionVisitor(
Expand Down Expand Up @@ -359,7 +359,7 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression)

var propertyMap = (IDictionary<IProperty, int>)GetProjectionIndex(projectionBindingExpression);
_materializationContextBindings[parameterExpression] = propertyMap;
entityTypeIdentifyingExpressionOffsets[parameterExpression] = propertyMap.Values.Max() + 1;
_entityTypeIdentifyingExpressionOffsets[parameterExpression] = propertyMap.Values.Max() + 1;

var updatedExpression = newExpression.Update(
new[] { Expression.Constant(ValueBuffer.Empty), newExpression.Arguments[1] });
Expand Down Expand Up @@ -868,7 +868,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
var property = methodCallExpression.Arguments[2].GetConstantValue<IProperty?>();
var mappingParameter = (ParameterExpression)((MethodCallExpression)methodCallExpression.Arguments[0]).Object!;
var projectionIndex = property == null
? entityTypeIdentifyingExpressionOffsets[mappingParameter]
? _entityTypeIdentifyingExpressionOffsets[mappingParameter]
+ methodCallExpression.Arguments[1].GetConstantValue<int>()
: _materializationContextBindings[mappingParameter][property];
var projection = _selectExpression.Projection[projectionIndex];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ protected override Expression VisitTypeBinary(TypeBinaryExpression typeBinaryExp
var entityProjection = (EntityProjectionExpression)Visit(entityShaper.ValueBufferExpression);
var subSelectExpression = (SelectExpression)entityReferenceExpression.SubqueryEntity.QueryExpression;

var predicate = GeneratePredicateTPT(entityProjection);
var predicate = GeneratePredicateTpt(entityProjection);

subSelectExpression.ApplyPredicate(predicate);
subSelectExpression.ReplaceProjection(new Dictionary<ProjectionMember, Expression>());
Expand All @@ -721,10 +721,10 @@ protected override Expression VisitTypeBinary(TypeBinaryExpression typeBinaryExp
var entityProjection = (EntityProjectionExpression)Visit(
entityReferenceExpression.ParameterEntity.ValueBufferExpression);

return GeneratePredicateTPT(entityProjection);
return GeneratePredicateTpt(entityProjection);
}

SqlExpression GeneratePredicateTPT(EntityProjectionExpression entityProjectionExpression)
SqlExpression GeneratePredicateTpt(EntityProjectionExpression entityProjectionExpression)
{
if (entityProjectionExpression.DiscriminatorExpression is CaseExpression caseExpression)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ private string CreateWktWithSrid(object value)
/// <summary>
/// The type of the NTS 'WKTReader'.
/// </summary>
// ReSharper disable once InconsistentNaming
protected abstract Type WKTReaderType { get; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal;

// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal;
using Microsoft.Extensions.DependencyInjection.Extensions;

// ReSharper disable once CheckNamespace
namespace Microsoft.Extensions.DependencyInjection;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ private static readonly ISet<string> _maxLengthRequiredTypes
"nvarchar"
};

private const string _namePartRegex
private const string NamePartRegex
= @"(?:(?:\[(?<part{0}>(?:(?:\]\])|[^\]])+)\])|(?<part{0}>[^\.\[\]]+))";

private static readonly Regex _partExtractor
= new(
string.Format(
CultureInfo.InvariantCulture,
@"^{0}(?:\.{1})?$",
string.Format(CultureInfo.InvariantCulture, _namePartRegex, 1),
string.Format(CultureInfo.InvariantCulture, _namePartRegex, 2)),
string.Format(CultureInfo.InvariantCulture, NamePartRegex, 1),
string.Format(CultureInfo.InvariantCulture, NamePartRegex, 2)),
RegexOptions.Compiled,
TimeSpan.FromMilliseconds(1000));

Expand Down
1 change: 1 addition & 0 deletions src/EFCore/Diagnostics/CoreEventId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

// ReSharper disable InconsistentNaming
// ReSharper disable UnusedMember.Local
namespace Microsoft.EntityFrameworkCore.Diagnostics;

Expand Down
Loading

0 comments on commit 2813548

Please sign in to comment.