Skip to content

Commit

Permalink
Static analysis: inconsistent naming and namespaces (#26919)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers authored Dec 14, 2021
1 parent 98a1153 commit 70cd929
Show file tree
Hide file tree
Showing 176 changed files with 1,088 additions and 1,079 deletions.
8 changes: 0 additions & 8 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,6 @@ dotnet_naming_rule.const_field_naming.symbols = const_field_symbol
dotnet_naming_rule.const_field_naming.style = pascal_case_style
dotnet_naming_rule.const_field_naming.severity = suggestion

# Private Fields
dotnet_naming_symbols.private_field_symbol.applicable_kinds = field
dotnet_naming_symbols.private_field_symbol.applicable_accessibilities = private

dotnet_naming_rule.private_field_naming.symbols = private_field_symbol
dotnet_naming_rule.private_field_naming.style = _camelCase
dotnet_naming_rule.private_field_naming.severity = suggestion

# Parameters
dotnet_naming_symbols.parameter_symbol.applicable_kinds = parameter
dotnet_naming_symbols.parameter_symbol.applicable_accessibilities = *
Expand Down
2 changes: 1 addition & 1 deletion All.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=FK/@EntryIndexedValue">FK</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MARS/@EntryIndexedValue">MARS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/EventHandlerPatternLong/@EntryValue">$object$_On$event$</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=042e7460_002D3ec6_002D4f1c_002D87c3_002Dfc91240d4c90/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Static, Instance" AccessRightKinds="Public" Description="Test Methods"&gt;&lt;ElementKinds&gt;&lt;Kind Name="TEST_MEMBER" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="Aa_bb" /&gt;&lt;/Policy&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=EF/@EntryIndexedValue">EF</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/JavaScriptNaming/UserRules/=JS_005FBLOCK_005FSCOPE_005FCONSTANT/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
Expand Down
20 changes: 10 additions & 10 deletions src/EFCore.Analyzers/InternalUsageDiagnosticAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed class InternalUsageDiagnosticAnalyzer : DiagnosticAnalyzer
public const string Id = "EF1001";
private static readonly int EFLen = "EntityFrameworkCore".Length;

private static readonly DiagnosticDescriptor _descriptor
private static readonly DiagnosticDescriptor Descriptor
= new(
Id,
title: AnalyzerStrings.InternalUsageTitle,
Expand All @@ -25,7 +25,7 @@ private static readonly DiagnosticDescriptor _descriptor
isEnabledByDefault: true);

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
=> ImmutableArray.Create(_descriptor);
=> ImmutableArray.Create(Descriptor);

public override void Initialize(AnalysisContext context)
{
Expand Down Expand Up @@ -115,7 +115,7 @@ private static void AnalyzeInvocation(OperationAnalysisContext context, IInvocat
{
if (IsInternal(context, a))
{
context.ReportDiagnostic(Diagnostic.Create(_descriptor, context.Operation.Syntax.GetLocation(), a));
context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Operation.Syntax.GetLocation(), a));
}
}

Expand All @@ -134,7 +134,7 @@ private static void AnalyzeVariableDeclaration(OperationAnalysisContext context,
CSharpSyntax.VariableDeclarationSyntax s => s.Type,
_ => context.Operation.Syntax
};
context.ReportDiagnostic(Diagnostic.Create(_descriptor, syntax.GetLocation(), declarator.Symbol.Type));
context.ReportDiagnostic(Diagnostic.Create(Descriptor, syntax.GetLocation(), declarator.Symbol.Type));
return;
}
}
Expand Down Expand Up @@ -191,7 +191,7 @@ CSharpSyntax.ClassDeclarationSyntax s when s.BaseList?.Types.Count > 0
{ } otherSyntax => otherSyntax.GetLocation()
};

context.ReportDiagnostic(Diagnostic.Create(_descriptor, location, baseSymbol));
context.ReportDiagnostic(Diagnostic.Create(Descriptor, location, baseSymbol));
}
}

Expand All @@ -205,7 +205,7 @@ CSharpSyntax.ClassDeclarationSyntax s when s.BaseList?.Types.Count > 0
{ } otherSyntax => otherSyntax.GetLocation()
};

context.ReportDiagnostic(Diagnostic.Create(_descriptor, location, @interface));
context.ReportDiagnostic(Diagnostic.Create(Descriptor, location, @interface));
}
}
}
Expand All @@ -229,7 +229,7 @@ private static void AnalyzeMethodTypeSymbol(SymbolAnalysisContext context, IMeth
{ } otherSyntax => otherSyntax.GetLocation()
};

context.ReportDiagnostic(Diagnostic.Create(_descriptor, location, symbol.ReturnType));
context.ReportDiagnostic(Diagnostic.Create(Descriptor, location, symbol.ReturnType));
}
}

Expand All @@ -243,7 +243,7 @@ private static void AnalyzeMethodTypeSymbol(SymbolAnalysisContext context, IMeth
{ } otherSyntax => otherSyntax.GetLocation()
};

context.ReportDiagnostic(Diagnostic.Create(_descriptor, location, paramSymbol.Type));
context.ReportDiagnostic(Diagnostic.Create(Descriptor, location, paramSymbol.Type));
}
}
}
Expand All @@ -264,10 +264,10 @@ private static void AnalyzeMemberDeclarationTypeSymbol(

private static void ReportDiagnostic(OperationAnalysisContext context, object messageArg)
=> context.ReportDiagnostic(
Diagnostic.Create(_descriptor, NarrowDownSyntax(context.Operation.Syntax).GetLocation(), messageArg));
Diagnostic.Create(Descriptor, NarrowDownSyntax(context.Operation.Syntax).GetLocation(), messageArg));

private static void ReportDiagnostic(SymbolAnalysisContext context, SyntaxNode syntax, object messageArg)
=> context.ReportDiagnostic(Diagnostic.Create(_descriptor, NarrowDownSyntax(syntax).GetLocation(), messageArg));
=> context.ReportDiagnostic(Diagnostic.Create(Descriptor, NarrowDownSyntax(syntax).GetLocation(), messageArg));

/// <summary>
/// Given a syntax node, pattern matches some known types and returns a narrowed-down node for the type syntax which
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ namespace Microsoft.EntityFrameworkCore;
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public sealed class UninitializedDbSetDiagnosticSuppressor : DiagnosticSuppressor
{
private static readonly SuppressionDescriptor _suppressUninitializedDbSetRule = new(
private static readonly SuppressionDescriptor SuppressUninitializedDbSetRule = new(
id: "SPR1001",
suppressedDiagnosticId: "CS8618",
justification: AnalyzerStrings.UninitializedDbSetWarningSuppressionJustification);

/// <inheritdoc />
public override ImmutableArray<SuppressionDescriptor> SupportedSuppressions { get; }
= ImmutableArray.Create(_suppressUninitializedDbSetRule);
= ImmutableArray.Create(SuppressUninitializedDbSetRule);

/// <inheritdoc />
public override void ReportSuppressions(SuppressionAnalysisContext context)
Expand Down
16 changes: 8 additions & 8 deletions src/EFCore.Cosmos/Diagnostics/CosmosEventId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private enum Id
ExecutedDeleteItem
}

private static readonly string _commandPrefix = DbLoggerCategory.Database.Command.Name + ".";
private static readonly string CommandPrefix = DbLoggerCategory.Database.Command.Name + ".";

/// <summary>
/// A SQL query is going to be executed.
Expand All @@ -50,7 +50,7 @@ private enum Id
/// </para>
/// </remarks>
public static readonly EventId ExecutingSqlQuery
= new((int)Id.ExecutingSqlQuery, _commandPrefix + Id.ExecutingSqlQuery);
= new((int)Id.ExecutingSqlQuery, CommandPrefix + Id.ExecutingSqlQuery);

/// <summary>
/// ReadItem is going to be executed.
Expand All @@ -64,7 +64,7 @@ public static readonly EventId ExecutingSqlQuery
/// </para>
/// </remarks>
public static readonly EventId ExecutingReadItem
= new((int)Id.ExecutingReadItem, _commandPrefix + Id.ExecutingReadItem);
= new((int)Id.ExecutingReadItem, CommandPrefix + Id.ExecutingReadItem);

/// <summary>
/// ReadNext was executed.
Expand All @@ -78,7 +78,7 @@ public static readonly EventId ExecutingReadItem
/// </para>
/// </remarks>
public static readonly EventId ExecutedReadNext
= new((int)Id.ExecutedReadNext, _commandPrefix + Id.ExecutedReadNext);
= new((int)Id.ExecutedReadNext, CommandPrefix + Id.ExecutedReadNext);

/// <summary>
/// ReadItem was executed.
Expand All @@ -92,7 +92,7 @@ public static readonly EventId ExecutedReadNext
/// </para>
/// </remarks>
public static readonly EventId ExecutedReadItem
= new((int)Id.ExecutedReadItem, _commandPrefix + Id.ExecutedReadItem);
= new((int)Id.ExecutedReadItem, CommandPrefix + Id.ExecutedReadItem);

/// <summary>
/// CreateItem was executed.
Expand All @@ -106,7 +106,7 @@ public static readonly EventId ExecutedReadItem
/// </para>
/// </remarks>
public static readonly EventId ExecutedCreateItem
= new((int)Id.ExecutedCreateItem, _commandPrefix + Id.ExecutedCreateItem);
= new((int)Id.ExecutedCreateItem, CommandPrefix + Id.ExecutedCreateItem);

/// <summary>
/// ReplaceItem was executed.
Expand All @@ -120,7 +120,7 @@ public static readonly EventId ExecutedCreateItem
/// </para>
/// </remarks>
public static readonly EventId ExecutedReplaceItem
= new((int)Id.ExecutedReplaceItem, _commandPrefix + Id.ExecutedReplaceItem);
= new((int)Id.ExecutedReplaceItem, CommandPrefix + Id.ExecutedReplaceItem);

/// <summary>
/// DeleteItem was executed.
Expand All @@ -134,5 +134,5 @@ public static readonly EventId ExecutedReplaceItem
/// </para>
/// </remarks>
public static readonly EventId ExecutedDeleteItem
= new((int)Id.ExecutedDeleteItem, _commandPrefix + Id.ExecutedDeleteItem);
= new((int)Id.ExecutedDeleteItem, CommandPrefix + Id.ExecutedDeleteItem);
}
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 All @@ -17,7 +18,7 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal;
/// </summary>
public class CosmosProjectionBindingExpressionVisitor : ExpressionVisitor
{
private static readonly MethodInfo _getParameterValueMethodInfo
private static readonly MethodInfo GetParameterValueMethodInfo
= typeof(CosmosProjectionBindingExpressionVisitor)
.GetTypeInfo().GetDeclaredMethod(nameof(GetParameterValue));

Expand Down Expand Up @@ -123,7 +124,7 @@ public override Expression Visit(Expression expression)
== true)
{
return Expression.Call(
_getParameterValueMethodInfo.MakeGenericMethod(parameterExpression.Type),
GetParameterValueMethodInfo.MakeGenericMethod(parameterExpression.Type),
QueryCompilationContext.QueryContextParameter,
Expression.Constant(parameterExpression.Name));
}
Expand Down
Loading

0 comments on commit 70cd929

Please sign in to comment.