Skip to content

Commit

Permalink
Some analyzer fixes
Browse files Browse the repository at this point in the history
Update Firebird EF Core 7 provider
  • Loading branch information
ErikEJ committed Aug 29, 2023
1 parent 931fd32 commit 80b57a8
Show file tree
Hide file tree
Showing 19 changed files with 29 additions and 87 deletions.
2 changes: 1 addition & 1 deletion src/GUI/Directory.Build.Props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.5.0.73987">
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.8.0.76515">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ public static class DbContextExtensions
/// </returns>
public static async Task<List<T>> SqlQueryValueAsync<T>(this DbContext db, string sql, object[] parameters = null, CancellationToken cancellationToken = default) // where T : class
{
if (db is null)
{
throw new ArgumentNullException(nameof(db));
}
ArgumentNullException.ThrowIfNull(db);

if (parameters is null)
{
Expand Down Expand Up @@ -79,10 +76,7 @@ public static async Task<List<T>> SqlQueryValueAsync<T>(this DbContext db, strin
public static async Task<List<T>> SqlQueryAsync<T>(this DbContext db, string sql, object[] parameters = null, CancellationToken cancellationToken = default)
where T : class
{
if (db is null)
{
throw new ArgumentNullException(nameof(db));
}
ArgumentNullException.ThrowIfNull(db);

return await SqlQueryInternalAsync<T>(db, sql, parameters, cancellationToken).ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace Microsoft.EntityFrameworkCore
/// <summary>
/// Useful extensions for DbContext.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Major Code Smell", "S4457:Parameter validation in \"async\"/\"await\" methods should be wrapped", Justification = "Broken analyzer?")]
public static class DbContextExtensions
{
/// <summary>
Expand All @@ -39,10 +38,7 @@ public static class DbContextExtensions
public static async Task<List<T>> SqlQueryAsync<T>(this DbContext db, string sql, object[] parameters = null, CancellationToken cancellationToken = default)
where T : class
{
if (db is null)
{
throw new ArgumentNullException(nameof(db));
}
ArgumentNullException.ThrowIfNull(db);

return await SqlQueryInternalAsync<T>(db, sql, parameters, cancellationToken).ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ public Table(string name, IEnumerable<Column> columns)
/// <param name="foreignKeys">The foreign keys.</param>
public Table(dac.TSqlObject tSqlObject)
{
if (tSqlObject == null)
{
throw new ArgumentNullException(nameof(tSqlObject));
}
ArgumentNullException.ThrowIfNull(tSqlObject);

// Get the name.
this.Name = tSqlObject.Name.Parts[tSqlObject.Name.Parts.Count - 1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ public ColumnRemovingScaffoldingModelFactory([NotNull] IOperationReporter report

protected override EntityTypeBuilder VisitTable(ModelBuilder modelBuilder, DatabaseTable table)
{
if (table is null)
{
throw new ArgumentNullException(nameof(table));
}
ArgumentNullException.ThrowIfNull(table);

string name;
if (databaseType == DatabaseType.SQLServer || databaseType == DatabaseType.SQLServerDacpac)
Expand Down
7 changes: 2 additions & 5 deletions src/GUI/RevEng.Core.60/DbContextSplitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ public static class DbContextSplitter
// Adapted from https://github.com/lauxjpn/DbContextOnModelCreatingSplitter
public static List<string> Split(string dbContextPath, string configNamespace, bool supportNullable)
{
if (dbContextPath == null)
{
throw new ArgumentNullException(nameof(dbContextPath));
}
ArgumentNullException.ThrowIfNull(dbContextPath);

var dbContextFilePath = Path.GetFullPath(dbContextPath);

Expand Down Expand Up @@ -71,7 +68,7 @@ public static List<string> Split(string dbContextPath, string configNamespace, b
.Where(m => m.Value.Trim().StartsWith("entity", StringComparison.Ordinal))
.ToList();

if (!statementsBlockMatches.Any())
if (statementsBlockMatches.Count == 0)
{
return new List<string>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ public RoutineModel Create(string connectionString, ModuleModelFactoryOptions op

protected override List<List<ModuleResultElement>> GetResultElementLists(SqlConnection connection, Routine module, bool multipleResults, bool useLegacyResultSetDiscovery)
{
if (module is null)
{
throw new ArgumentNullException(nameof(module));
}
ArgumentNullException.ThrowIfNull(module);

using var dtResult = new DataTable();
var list = new List<ModuleResultElement>();
Expand Down
12 changes: 3 additions & 9 deletions src/GUI/RevEng.Core.60/Functions/SqlServerFunctionScaffolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,9 @@ protected override string WriteDbContextInterface(ModuleScaffolderOptions scaffo

protected override string WriteDbContext(ModuleScaffolderOptions scaffolderOptions, RoutineModel model, List<string> schemas)
{
if (scaffolderOptions is null)
{
throw new ArgumentNullException(nameof(scaffolderOptions));
}
ArgumentNullException.ThrowIfNull(scaffolderOptions);

if (model is null)
{
throw new ArgumentNullException(nameof(model));
}
ArgumentNullException.ThrowIfNull(model);

Sb = new IndentedStringBuilder();

Expand Down Expand Up @@ -143,7 +137,7 @@ private void GenerateFunctionStub(Routine function, RoutineModel model)

var parameters = string.Empty;

if (function.Parameters.Any())
if (function.Parameters.Count != 0)
{
parameters = string.Join(", ", paramStrings);
}
Expand Down
5 changes: 1 addition & 4 deletions src/GUI/RevEng.Core.60/ReplacingCandidateNamingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ public override string GenerateCandidateIdentifier(DatabaseTable originalTable)

public override string GenerateCandidateIdentifier(DatabaseColumn originalColumn)
{
if (originalColumn is null)
{
throw new ArgumentNullException(nameof(originalColumn));
}
ArgumentNullException.ThrowIfNull(originalColumn);

var candidateStringBuilder = new StringBuilder();

Expand Down
4 changes: 2 additions & 2 deletions src/GUI/RevEng.Core.60/ReverseEngineerRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public static ReverseEngineerResult GenerateFiles(ReverseEngineerCommandOptions

public static void RetryFileWrite(string path, List<string> finalLines)
{
for (int i = 1; i <= 3; ++i)
for (int i = 1; i <= 4; ++i)
{
try
{
Expand All @@ -235,7 +235,7 @@ public static void RetryFileWrite(string path, List<string> finalLines)

public static void RetryFileWrite(string path, string finalText)
{
for (int i = 1; i <= 3; ++i)
for (int i = 1; i <= 4; ++i)
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ public abstract class SqlServerRoutineModelFactory

protected RoutineModel GetRoutines(string connectionString, ModuleModelFactoryOptions options)
{
if (options is null)
{
throw new ArgumentNullException(nameof(options));
}
ArgumentNullException.ThrowIfNull(options);

SqlServerSqlTypeExtensions.UseDateOnlyTimeOnly = options.UseDateOnlyTimeOnly;

Expand Down Expand Up @@ -56,7 +53,7 @@ protected RoutineModel GetRoutines(string connectionString, ModuleModelFactoryOp
}
#pragma warning restore CA2100 // Review SQL queries for security vulnerabilities

var allParameters = options.FullModel && found.Any() ? GetParameters(connection) : new Dictionary<string, List<ModuleParameter>>();
var allParameters = options.FullModel && found.Count != 0 ? GetParameters(connection) : new Dictionary<string, List<ModuleParameter>>();

foreach (var foundModule in found)
{
Expand Down Expand Up @@ -136,7 +133,7 @@ protected RoutineModel GetRoutines(string connectionString, ModuleModelFactoryOp
.Select(y => y.Key)
.ToList();

if (duplicates.Any())
if (duplicates.Count != 0)
{
dupesFound = true;
errors.Add($"Unable to scaffold {RoutineType} '{module.Schema}.{module.Name}' as it has duplicate result column names: '{duplicates[0]}'.");
Expand Down
10 changes: 2 additions & 8 deletions src/GUI/RevEng.Core.60/Routines/SqlServerRoutineScaffolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ public abstract class SqlServerRoutineScaffolder : IRoutineScaffolder

protected SqlServerRoutineScaffolder([System.Diagnostics.CodeAnalysis.NotNull] ICSharpHelper code)
{
if (code == null)
{
throw new ArgumentNullException(nameof(code));
}
ArgumentNullException.ThrowIfNull(code);

this.Code = code;
}
Expand Down Expand Up @@ -296,10 +293,7 @@ private static string GenerateUniqueName(Routine routine, RoutineModel model)

private static Tuple<string, string> GeneratePropertyName(string propertyName)
{
if (propertyName == null)
{
throw new ArgumentNullException(nameof(propertyName));
}
ArgumentNullException.ThrowIfNull(propertyName);

return CreateIdentifier(propertyName);
}
Expand Down
10 changes: 2 additions & 8 deletions src/GUI/RevEng.Core.60/ServiceProviderBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,9 @@ public static class ServiceProviderBuilder
{
public static IServiceCollection AddEfpt(this IServiceCollection serviceCollection, ReverseEngineerCommandOptions options, List<string> errors, List<string> warnings, List<string> info)
{
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
ArgumentNullException.ThrowIfNull(options);

if (serviceCollection == null)
{
throw new ArgumentNullException(nameof(serviceCollection));
}
ArgumentNullException.ThrowIfNull(serviceCollection);

var reporter = new OperationReporter(
new OperationReportHandler(
Expand Down
5 changes: 1 addition & 4 deletions src/GUI/RevEng.Core.60/TableListBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ public TableListBuilder(
IDatabaseModelFactory databaseModelFactory,
SchemaInfo[] schemas)
{
if (options is null)
{
throw new ArgumentNullException(nameof(options));
}
ArgumentNullException.ThrowIfNull(options);

this.procedureModelFactory = procedureModelFactory;
this.functionModelFactory = functionModelFactory;
Expand Down
2 changes: 1 addition & 1 deletion src/GUI/RevEng.Core.70/RevEng.Core.70.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<PackageReference Include="EntityFrameworkCore.Sqlite.NodaTime" Version="7.0.0" />
<PackageReference Include="EntityFrameworkCore.SqlServer.HierarchyId" Version="4.0.0" />
<PackageReference Include="ErikEJ.EntityFrameworkCore.SqlServer.DateOnlyTimeOnly" Version="7.0.5" />
<PackageReference Include="FirebirdSql.EntityFrameworkCore.Firebird" Version="9.2.0-alpha1" />
<PackageReference Include="FirebirdSql.EntityFrameworkCore.Firebird" Version="9.2.0-beta1" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.10" />
Expand Down
5 changes: 1 addition & 4 deletions src/GUI/efpt60.core/EFCoreCompareBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ public static List<Tuple<string, string>> GenerateDbContextList(string outputPat

public static List<Tuple<string, string>> GenerateSchemaCompareResult(string outputPath, string startupOutputPath, string connectionString, string dbContexts)
{
if (dbContexts == null)
{
throw new ArgumentNullException(nameof(dbContexts));
}
ArgumentNullException.ThrowIfNull(dbContexts);

return GetCompareResult(outputPath, startupOutputPath ?? outputPath, connectionString, dbContexts);
}
Expand Down
4 changes: 2 additions & 2 deletions src/GUI/efpt60.core/EFCoreMigrationsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ private static string GetMigrationStatus(DbContext context)

var migrations = context.Database.GetMigrations().ToArray();

if (!migrations.Any())
if (migrations.Length == 0)
{
return "NoMigrations";
}

var pendingMigrations = context.Database.GetPendingMigrations().ToArray();

if (pendingMigrations.Any())
if (pendingMigrations.Length != 0)
{
return "Pending";
}
Expand Down
5 changes: 1 addition & 4 deletions src/GUI/efpt60.core/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ public static int Main(string[] args)
{
Console.OutputEncoding = Encoding.UTF8;

if (args == null)
{
throw new ArgumentNullException(nameof(args));
}
ArgumentNullException.ThrowIfNull(args);

if (args.Length > 0)
{
Expand Down
5 changes: 1 addition & 4 deletions src/GUI/efreveng60/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ public static async System.Threading.Tasks.Task<int> Main(string[] args)
{
Console.OutputEncoding = Encoding.UTF8;

if (args == null)
{
throw new ArgumentNullException(nameof(args));
}
ArgumentNullException.ThrowIfNull(args);

if (args.Length > 0)
{
Expand Down

0 comments on commit 80b57a8

Please sign in to comment.