Skip to content

Commit

Permalink
Fix some analyzer issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikEJ committed Nov 12, 2023
1 parent 62e9b28 commit 1a163fc
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 30 deletions.
3 changes: 1 addition & 2 deletions src/GUI/Directory.Build.Props
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
<Project>

<PropertyGroup Label="Analyzer settings">
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisLevel>latest</AnalysisLevel>
<AnalysisLevel>latest-All</AnalysisLevel>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using dac = Microsoft.SqlServer.Dac.Model;
using Dac = Microsoft.SqlServer.Dac.Model;

namespace SqlSharpener.Model
{
Expand Down Expand Up @@ -42,31 +42,31 @@ public Column(string name, IDictionary<TypeFormat, string> dataTypes, bool isIde
/// <param name="tSqlTable">The table or view this column belongs to.</param>
/// <param name="primaryKeys">The primary keys.</param>
/// <param name="foreignKeys">The foreign keys.</param>
public Column(dac.TSqlObject tSqlObject)
public Column(Dac.TSqlObject tSqlObject)
{
this.Name = tSqlObject.Name.Parts.Last();

if (tSqlObject.ObjectType.Name == "TableTypeColumn")
{
var sqlDataTypeName = tSqlObject.GetReferenced(dac.TableTypeColumn.DataType).ToList().First().Name.Parts.Last();
var sqlDataTypeName = tSqlObject.GetReferenced(Dac.TableTypeColumn.DataType).ToList().First().Name.Parts.Last();
this.DataTypes = DataTypeHelper.Instance.GetMap(TypeFormat.SqlServerDbType, sqlDataTypeName);
this.IsIdentity = dac.TableTypeColumn.IsIdentity.GetValue<bool>(tSqlObject);
this.IsNullable = dac.TableTypeColumn.Nullable.GetValue<bool>(tSqlObject);
this.Precision = dac.TableTypeColumn.Precision.GetValue<int>(tSqlObject);
this.Scale = dac.TableTypeColumn.Scale.GetValue<int>(tSqlObject);
this.Length = dac.TableTypeColumn.Length.GetValue<int>(tSqlObject);
this.IsIdentity = Dac.TableTypeColumn.IsIdentity.GetValue<bool>(tSqlObject);
this.IsNullable = Dac.TableTypeColumn.Nullable.GetValue<bool>(tSqlObject);
this.Precision = Dac.TableTypeColumn.Precision.GetValue<int>(tSqlObject);
this.Scale = Dac.TableTypeColumn.Scale.GetValue<int>(tSqlObject);
this.Length = Dac.TableTypeColumn.Length.GetValue<int>(tSqlObject);
}
else
{
dac.ColumnType metaType = tSqlObject.GetMetadata<dac.ColumnType>(dac.Column.ColumnType);
Dac.ColumnType metaType = tSqlObject.GetMetadata<Dac.ColumnType>(Dac.Column.ColumnType);

switch (metaType)
{
case dac.ColumnType.Column:
case dac.ColumnType.ColumnSet:
case Dac.ColumnType.Column:
case Dac.ColumnType.ColumnSet:
SetProperties(tSqlObject);
break;
case dac.ColumnType.ComputedColumn:
case Dac.ColumnType.ComputedColumn:
// use the referenced column - this works for simple view referenced
// column but not for a computed expression like [Name] = [FirstName] + ' ' + [LastName]
var referenced = tSqlObject.GetReferenced().ToArray();
Expand Down Expand Up @@ -136,15 +136,15 @@ public Column(dac.TSqlObject tSqlObject)
/// </value>
public int Length { get; private set; }

private void SetProperties(dac.TSqlObject tSqlObject)
private void SetProperties(Dac.TSqlObject tSqlObject)
{
var sqlDataTypeName = tSqlObject.GetReferenced(dac.Column.DataType).ToList().First().Name.Parts.Last();
var sqlDataTypeName = tSqlObject.GetReferenced(Dac.Column.DataType).ToList().First().Name.Parts.Last();
this.DataTypes = DataTypeHelper.Instance.GetMap(TypeFormat.SqlServerDbType, sqlDataTypeName);
this.IsIdentity = dac.Column.IsIdentity.GetValue<bool>(tSqlObject);
this.IsNullable = dac.Column.Nullable.GetValue<bool>(tSqlObject);
this.Precision = dac.Column.Precision.GetValue<int>(tSqlObject);
this.Scale = dac.Column.Scale.GetValue<int>(tSqlObject);
this.Length = dac.Column.Length.GetValue<int>(tSqlObject);
this.IsIdentity = Dac.Column.IsIdentity.GetValue<bool>(tSqlObject);
this.IsNullable = Dac.Column.Nullable.GetValue<bool>(tSqlObject);
this.Precision = Dac.Column.Precision.GetValue<int>(tSqlObject);
this.Scale = Dac.Column.Scale.GetValue<int>(tSqlObject);
this.Length = Dac.Column.Length.GetValue<int>(tSqlObject);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using dac = Microsoft.SqlServer.Dac.Model;
using Dac = Microsoft.SqlServer.Dac.Model;

namespace SqlSharpener.Model
{
Expand All @@ -20,7 +20,7 @@ public class Procedure
/// Initializes a new instance of the <see cref="Procedure"/> class.
/// </summary>
/// <param name="prefix">The prefix used on stored procedure names.</param>
public Procedure(dac.TSqlObject tSqlObject)
public Procedure(Dac.TSqlObject tSqlObject)
{
this.Name = tSqlObject.Name.Parts.Last();
this.Schema = tSqlObject.Name.Parts.First();
Expand All @@ -31,7 +31,7 @@ public Procedure(dac.TSqlObject tSqlObject)
var selectVisitor = new SqlSharpener.SelectVisitor();
frag.Accept(selectVisitor);

var depends = tSqlObject.GetReferenced(dac.Procedure.BodyDependencies)
var depends = tSqlObject.GetReferenced(Dac.Procedure.BodyDependencies)
.Where(x => x.ObjectType.Name == "Column")
.ToList();

Expand All @@ -44,8 +44,8 @@ public Procedure(dac.TSqlObject tSqlObject)
key => string.Join(".", key.Name.Parts),
val => new DataType
{
Map = DataTypeHelper.Instance.GetMap(TypeFormat.SqlServerDbType, val.GetReferenced(dac.Column.DataType).FirstOrDefault()?.Name.Parts.Last()),
Nullable = dac.Column.Nullable.GetValue<bool>(val)
Map = DataTypeHelper.Instance.GetMap(TypeFormat.SqlServerDbType, val.GetReferenced(Dac.Column.DataType).FirstOrDefault()?.Name.Parts.Last()),
Nullable = Dac.Column.Nullable.GetValue<bool>(val)
},
StringComparer.InvariantCultureIgnoreCase);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using dac = Microsoft.SqlServer.Dac.Model;
using Dac = Microsoft.SqlServer.Dac.Model;

namespace SqlSharpener.Model
{
Expand All @@ -28,7 +28,7 @@ public Table(string name, IEnumerable<Column> columns)
/// <param name="tSqlObject">The TSqlObject representing the table.</param>
/// <param name="primaryKeys">The primary keys.</param>
/// <param name="foreignKeys">The foreign keys.</param>
public Table(dac.TSqlObject tSqlObject)
public Table(Dac.TSqlObject tSqlObject)
{
ArgumentNullException.ThrowIfNull(tSqlObject);

Expand All @@ -37,7 +37,7 @@ public Table(dac.TSqlObject tSqlObject)

// Get the columns
var columns = new List<Column>();
var sqlColumns = tSqlObject.ObjectType.Name == "TableType" ? tSqlObject.GetReferenced(dac.TableType.Columns) : tSqlObject.GetReferenced(dac.Table.Columns);
var sqlColumns = tSqlObject.ObjectType.Name == "TableType" ? tSqlObject.GetReferenced(Dac.TableType.Columns) : tSqlObject.GetReferenced(Dac.Table.Columns);
foreach (var sqlColumn in sqlColumns)
{
var column = new Column(sqlColumn);
Expand Down
7 changes: 6 additions & 1 deletion src/GUI/RevEng.Shared/Cli/VsCode/VsCodeTaskHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ namespace RevEng.Common.Cli.VsCode
{
public static class VsCodeTaskHelper
{
private static readonly JsonSerializerOptions WriteOptions = new()
{
WriteIndented = true,
};

public static void GenerateTaskPayload(string projectPath, int version, string redactedConnectionString)
{
var path = Path.Combine(projectPath, ".vscode");
Expand Down Expand Up @@ -95,7 +100,7 @@ public static void GenerateTaskPayload(string projectPath, int version, string r
},
};

File.WriteAllText(path, JsonSerializer.Serialize(vsCodeTask, new JsonSerializerOptions { WriteIndented = true }), Encoding.UTF8);
File.WriteAllText(path, JsonSerializer.Serialize(vsCodeTask, WriteOptions), Encoding.UTF8);
}
}
}

0 comments on commit 1a163fc

Please sign in to comment.