Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static analysis: redundancies in symbol declarations #26921

Merged
merged 1 commit into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,28 @@ private void ConfigurePartitionKeyJoinEntityType(
CreateSkipNavigationForeignKey(skipNavigation.Inverse!, joinEntityTypeBuilder, partitionKey);
}

private IConventionForeignKey CreateSkipNavigationForeignKey(
private void CreateSkipNavigationForeignKey(
IConventionSkipNavigation skipNavigation,
IConventionEntityTypeBuilder joinEntityTypeBuilder,
IConventionProperty partitionKeyProperty)
{
if (skipNavigation.ForeignKey != null
&& !skipNavigation.Builder.CanSetForeignKey(null))
{
return skipNavigation.ForeignKey;
return;
}

var principalKey = skipNavigation.DeclaringEntityType.FindPrimaryKey();
if (principalKey == null
|| principalKey.Properties.All(p => p.Name != partitionKeyProperty.Name))
{
return CreateSkipNavigationForeignKey(skipNavigation, joinEntityTypeBuilder);
CreateSkipNavigationForeignKey(skipNavigation, joinEntityTypeBuilder);
return;
}

if (skipNavigation.ForeignKey?.Properties.Contains(partitionKeyProperty) == true)
{
return skipNavigation.ForeignKey;
return;
}

var dependentProperties = new IConventionProperty[principalKey.Properties.Count];
Expand All @@ -136,8 +137,6 @@ private IConventionForeignKey CreateSkipNavigationForeignKey(
.Metadata;

skipNavigation.Builder.HasForeignKey(foreignKey);

return foreignKey;
}

private void ProcessJoinPartitionKey(IConventionSkipNavigation skipNavigation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ private static bool CanEvaluate(Expression expression)
switch (expression)
#pragma warning restore IDE0066 // Convert switch statement to expression
{
case ConstantExpression constantExpression:
case ConstantExpression:
return true;

case NewExpression newExpression:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,9 @@ private IUpdateAdapter AddSeedData()
var updateAdapter = _updateAdapterFactory.CreateStandalone();
foreach (var entityType in _designTimeModel.Model.GetEntityTypes())
{
IEntityType? targetEntityType = null;
foreach (var targetSeed in entityType.GetSeedData())
{
targetEntityType ??= updateAdapter.Model.FindEntityType(entityType.Name)!;
updateAdapter.Model.FindEntityType(entityType.Name);
var entry = updateAdapter.CreateEntry(targetSeed, entityType);
entry.EntityState = EntityState.Added;
}
Expand Down
8 changes: 3 additions & 5 deletions src/EFCore.Design/Design/Internal/CSharpHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,23 +264,21 @@ public virtual string Identifier(string name, ICollection<string>? scope = null,
return _keywords.Contains(identifier) ? "@" + identifier : identifier;
}

private static StringBuilder ChangeFirstLetterCase(StringBuilder builder, bool capitalize)
private static void ChangeFirstLetterCase(StringBuilder builder, bool capitalize)
{
if (builder.Length == 0)
{
return builder;
return;
}

var first = builder[index: 0];
if (char.IsUpper(first) == capitalize)
{
return builder;
return;
}

builder.Remove(startIndex: 0, length: 1)
.Insert(index: 0, value: capitalize ? char.ToUpperInvariant(first) : char.ToLowerInvariant(first));

return builder;
}

/// <summary>
Expand Down
2 changes: 0 additions & 2 deletions src/EFCore.Design/Design/Internal/DatabaseOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace Microsoft.EntityFrameworkCore.Design.Internal;
/// </summary>
public class DatabaseOperations
{
private readonly IOperationReporter _reporter;
private readonly string _projectDir;
private readonly string? _rootNamespace;
private readonly string? _language;
Expand All @@ -35,7 +34,6 @@ public DatabaseOperations(
bool nullable,
string[]? args)
{
_reporter = reporter;
_projectDir = projectDir;
_rootNamespace = rootNamespace;
_language = language;
Expand Down
2 changes: 0 additions & 2 deletions src/EFCore.Design/Design/Internal/MigrationsOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class MigrationsOperations
private readonly string _projectDir;
private readonly string? _rootNamespace;
private readonly string? _language;
private readonly bool _nullable;
private readonly DesignTimeServicesBuilder _servicesBuilder;
private readonly DbContextOperations _contextOperations;
private readonly string[] _args;
Expand All @@ -44,7 +43,6 @@ public MigrationsOperations(
_projectDir = projectDir;
_rootNamespace = rootNamespace;
_language = language;
_nullable = nullable;
_args = args ?? Array.Empty<string>();
_contextOperations = new DbContextOperations(
reporter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public virtual IReadOnlyCollection<ScaffoldedFile> GenerateModel(
CompiledModelCodeGenerationOptions options)
{
var scaffoldedFiles = new List<ScaffoldedFile>();
var modelCode = CreateModel(model, options.ModelNamespace, options.ContextType, options.UseNullableReferenceTypes);
var modelCode = CreateModel(options.ModelNamespace, options.ContextType, options.UseNullableReferenceTypes);
var modelFileName = options.ContextType.ShortDisplayName() + ModelSuffix + FileExtension;
scaffoldedFiles.Add(new ScaffoldedFile { Path = modelFileName, Code = modelCode });

Expand Down Expand Up @@ -115,7 +115,6 @@ private static string GenerateHeader(SortedSet<string> namespaces, string curren
}

private string CreateModel(
IModel model,
string @namespace,
Type contextType,
bool nullable)
Expand Down Expand Up @@ -306,7 +305,7 @@ private string CreateModelBuilder(
mainBuilder.AppendLine();
}

foreach (var (entityType, namePair) in entityTypeIds)
foreach (var (_, namePair) in entityTypeIds)
{
var (variableName, entityClassName) = namePair;

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

using System.Globalization;
using System.Text;
using Microsoft.EntityFrameworkCore.Design.Internal;
using Microsoft.EntityFrameworkCore.Internal;

namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal;
Expand All @@ -16,20 +15,15 @@ namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal;
/// </summary>
public class CompiledModelScaffolder : ICompiledModelScaffolder
{
private readonly IOperationReporter _reporter;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public CompiledModelScaffolder(
ICompiledModelCodeGeneratorSelector modelCodeGeneratorSelector,
IOperationReporter reporter)
public CompiledModelScaffolder(ICompiledModelCodeGeneratorSelector modelCodeGeneratorSelector)
{
ModelCodeGeneratorSelector = modelCodeGeneratorSelector;
_reporter = reporter;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class RelationalScaffoldingModelFactory : IScaffoldingModelFactory
private readonly IPluralizer _pluralizer;
private readonly ICSharpUtilities _cSharpUtilities;
private readonly IScaffoldingTypeMapper _scaffoldingTypeMapper;
private readonly LoggingDefinitions _loggingDefinitions;
private readonly IModelRuntimeInitializer _modelRuntimeInitializer;

/// <summary>
Expand All @@ -47,15 +46,13 @@ public RelationalScaffoldingModelFactory(
IPluralizer pluralizer,
ICSharpUtilities cSharpUtilities,
IScaffoldingTypeMapper scaffoldingTypeMapper,
LoggingDefinitions loggingDefinitions,
IModelRuntimeInitializer modelRuntimeInitializer)
{
_reporter = reporter;
_candidateNamingService = candidateNamingService;
_pluralizer = pluralizer;
_cSharpUtilities = cSharpUtilities;
_scaffoldingTypeMapper = scaffoldingTypeMapper;
_loggingDefinitions = loggingDefinitions;
_modelRuntimeInitializer = modelRuntimeInitializer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@ private static bool CanEvaluate(Expression expression)
switch (expression)
#pragma warning restore IDE0066 // Convert switch statement to expression
{
case ConstantExpression constantExpression:
case ConstantExpression:
return true;

case NewExpression newExpression:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,14 +457,6 @@ public override void Generate(IForeignKey foreignKey, CSharpRuntimeAnnotationCod
base.Generate(foreignKey, parameters);
}

/// <inheritdoc />
public override void Generate(INavigation navigation, CSharpRuntimeAnnotationCodeGeneratorParameters parameters)
=> base.Generate(navigation, parameters);

/// <inheritdoc />
public override void Generate(ISkipNavigation navigation, CSharpRuntimeAnnotationCodeGeneratorParameters parameters)
=> base.Generate(navigation, parameters);

/// <inheritdoc />
public override void Generate(IIndex index, CSharpRuntimeAnnotationCodeGeneratorParameters parameters)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ public virtual InterceptionResult DataReaderDisposing(

var eventData = new DataReaderDisposingEventData(
definition,
(d, p) => ((EventDefinition)d).GenerateMessage(),
(d, _) => ((EventDefinition)d).GenerateMessage(),
command,
dataReader,
connection.Context,
Expand Down
Loading