Skip to content

Commit

Permalink
Fix analysis warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveDunn committed Oct 27, 2024
1 parent f20bbbc commit 42e8307
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 17 deletions.
1 change: 1 addition & 0 deletions Vogen.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<s:String x:Key="/Default/CodeInspection/GeneratedCode/GeneratedFileMasks/=_002A_002Eg_002Ecs/@EntryIndexedValue">*.g.cs</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=BitwiseOperatorOnEnumWithoutFlags/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CheckNamespace/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CognitiveComplexity/@EntryIndexedValue">SUGGESTION</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertToPrimaryConstructor/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=InvalidXmlDocComment/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MemberCanBeMadeStatic_002ELocal/@EntryIndexedValue">ERROR</s:String>
Expand Down
3 changes: 2 additions & 1 deletion src/Vogen/Extensions/IMethodSymbolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Diagnostics;
using System.Linq;
using Microsoft.CodeAnalysis;
// ReSharper disable ConditionIsAlwaysTrueOrFalse

#if HAS_IOPERATION
using System.Threading;
Expand Down Expand Up @@ -739,7 +740,7 @@ public static bool IsGetAwaiterFromAwaitablePattern(this IMethodSymbol? method,
return false;
}

var returnType = method.ReturnType?.OriginalDefinition;
var returnType = method.ReturnType.OriginalDefinition;
if (returnType is null)
{
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/Vogen/Extensions/IPropertySymbolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static bool IsIsCompletedFromAwaiterPattern(
{
if (property is null
|| !property.Name.Equals("IsCompleted", StringComparison.Ordinal)
|| property.Type?.SpecialType != SpecialType.System_Boolean)
|| property.Type.SpecialType != SpecialType.System_Boolean)
{
return false;
}
Expand Down
7 changes: 3 additions & 4 deletions src/Vogen/Extensions/ReportDiagnosticExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@ namespace Microsoft.CodeAnalysis
{
internal static class ReportDiagnosticExtensions
{
public static string ToAnalyzerConfigString(this ReportDiagnostic reportDiagnostic)
{
return reportDiagnostic switch
public static string ToAnalyzerConfigString(this ReportDiagnostic reportDiagnostic) =>
reportDiagnostic switch
{
ReportDiagnostic.Error => "error",
ReportDiagnostic.Warn => "warning",
ReportDiagnostic.Info => "suggestion",
ReportDiagnostic.Hidden => "silent",
ReportDiagnostic.Suppress => "none",
ReportDiagnostic.Default => "none",
_ => throw new NotImplementedException(),
};
}

public static DiagnosticSeverity? ToDiagnosticSeverity(this ReportDiagnostic reportDiagnostic)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Vogen/Extensions/SourceTextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Analyzer.Utilities.Extensions
/// <summary>
/// Class that contains extensions to <see cref="SourceText"/>.
/// </summary>
internal static partial class SourceTextExtensions
internal static class SourceTextExtensions
{
/// <summary>
/// Reads the <paramref name="text"/> contents into a stream and returns the result of calling the
Expand Down
2 changes: 0 additions & 2 deletions src/Vogen/GenerateCodeForToString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public static class GenerateCodeForToString

private static string GenerateAnyHoistedToStringMethods(GenerationParameters generationParameters, bool isReadOnly)
{
List<IMethodSymbol> formattableMethods = generationParameters.VogenKnownSymbols.IFormattable.GetJustMethods().ToList();

var item = generationParameters.WorkItem;

INamedTypeSymbol primitiveSymbol = item.UnderlyingType;
Expand Down
4 changes: 2 additions & 2 deletions src/Vogen/Generators/ClassGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public string Generate(GenerationParameters parameters)
string underlyingBang = item.Nullable.BangForUnderlying;
string wrapperBang = item.Nullable.BangForWrapper;

var code = Generate();
var code = GenerateCode();

return item.Nullable.WrapBlock(code);


string Generate() => $@"
string GenerateCode() => $@"
{Util.WriteStartNamespace(item.FullNamespace)}
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
Expand Down
2 changes: 1 addition & 1 deletion src/Vogen/WriteDiagnostics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private void ReportTargets(StringBuilder sb)

foreach (var eachTarget in _targets)
{
sb.AppendLine($"{eachTarget.VoSymbolInformation.ToString()}");
sb.AppendLine($"{eachTarget.VoSymbolInformation}");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
using LinqToDB.Data;
using LinqToDB.DataProvider.SQLite;
using LinqToDB.Mapping;
// ReSharper disable EqualExpressionComparison
// ReSharper disable SuspiciousTypeConversion.Global
// ReSharper disable ArrangeMethodOrOperatorBody
// ReSharper disable TryCastAlwaysSucceeds
// ReSharper disable NullableWarningSuppressionIsUsed

namespace Vogen.IntegrationTests.SerializationAndConversionTests.ClassVos;

Expand Down Expand Up @@ -172,7 +177,7 @@ public void WhenEfCoreValueConverterUsesValueConverter()
[Fact]
public async Task WhenDapperValueConverterUsesValueConverter()
{
using var connection = new SqliteConnection("DataSource=:memory:");
await using var connection = new SqliteConnection("DataSource=:memory:");
await connection.OpenAsync();

IEnumerable<DapperStringVo> results = await connection.QueryAsync<DapperStringVo>("SELECT 'foo!'");
Expand Down Expand Up @@ -215,7 +220,7 @@ public void TypeConverter_CanConvertToAndFrom(object value)
var converter = TypeDescriptor.GetConverter(typeof(NoJsonStringVo));
var id = converter.ConvertFrom(value);
Assert.IsType<NoJsonStringVo>(id);
Assert.Equal(NoJsonStringVo.From(value!.ToString()), id);
Assert.Equal(NoJsonStringVo.From(value.ToString()!), id);

var reconverted = converter.ConvertTo(id, value.GetType());
Assert.Equal(value, reconverted);
Expand Down Expand Up @@ -244,13 +249,13 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

public class EfCoreTestEntity
{
public EfCoreStringVo Id { get; set; }
public EfCoreStringVo Id { get; init; }
}

public class LinqToDbTestEntity
{
[Column(DataType = DataType.VarChar)]
[ValueConverter(ConverterType = typeof(LinqToDbStringVo.LinqToDbValueConverter))]
public LinqToDbStringVo Id { get; set; }
public LinqToDbStringVo Id { get; init; }
}
}
7 changes: 6 additions & 1 deletion tests/Shared/ProjectBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Shared;

public record struct NuGetPackage(string PackageName, string Version, string PathPrefix);

public sealed partial class ProjectBuilder
public sealed class ProjectBuilder
{
public IList<DiagnosticAnalyzer> DiagnosticAnalyzers { get; } = new List<DiagnosticAnalyzer>();
public IList<DiagnosticResult> ExpectedDiagnosticResults { get; } = new List<DiagnosticResult>();
Expand Down Expand Up @@ -160,6 +160,10 @@ private void AddNuGetReferences()
AddNuGetReference("Microsoft.OpenApi", "1.4.3.0", "lib/netstandard2.0/");
AddNuGetReference("MongoDB.Bson", "2.27.0", "lib/netstandard2.0");
break;
case null:
break;
default:
throw new ArgumentOutOfRangeException();
}

AddNuGetReference("System.Collections.Immutable", "1.5.0", "lib/netstandard2.0/");
Expand Down Expand Up @@ -227,6 +231,7 @@ async Task<string[]> Download()
var metadataReader = peFile.GetMetadataReader();
result.Add(eachDllNameAndPath);
}
// ReSharper disable once EmptyGeneralCatchClause
catch
{
}
Expand Down

0 comments on commit 42e8307

Please sign in to comment.