Skip to content

Commit

Permalink
fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianAuinger committed Mar 18, 2022
1 parent 1f18354 commit f949be4
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 4 deletions.
9 changes: 9 additions & 0 deletions Weingartner.Json.Migration.Roslyn/AnalyzerReleases.Shipped.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Release 1.0.2

### New Rules

Rule ID | Category | Severity | Notes
--------|----------|----------|-------
DataContractAnalyzer | DataMigration | Error | DataContractAnalyzer
MigrationHashAnalyzer | DataMigration | Error | MigrationHashAnalyzer
MigrationMethodAnalyzer | DataMigration | Error | MigrationMethodAnalyzer
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

4 changes: 3 additions & 1 deletion Weingartner.Json.Migration.Roslyn/DataContractAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class DataContractAnalyzer : DiagnosticAnalyzer
{
public const string DiagnosticId = "DataContractAnalyzer";
private static readonly LocalizableString Title = "Migratable type should have `DataContract` and `DataMember` attributes";
public static readonly LocalizableString MessageFormat = "Type '{0}' is migratable but is missing either `DataContract` or `DataMember` attributes.";
public static readonly LocalizableString MessageFormat = "Type '{0}' is migratable but is missing either `DataContract` or `DataMember` attributes";
private const string Category = "DataMigration";

private static readonly DiagnosticDescriptor Rule = new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category, DiagnosticSeverity.Error, true);
Expand All @@ -21,6 +21,8 @@ public class DataContractAnalyzer : DiagnosticAnalyzer

public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
context.RegisterCompilationStartAction(OnCompilationStart);
}

Expand Down
4 changes: 3 additions & 1 deletion Weingartner.Json.Migration.Roslyn/MigrationHashAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class MigrationHashAnalyzer : DiagnosticAnalyzer
{
public const string DiagnosticId = "MigrationHashAnalyzer";
private static readonly LocalizableString Title = "Should have correct migration hash";
public static readonly LocalizableString MessageFormat = "Expected migration hash of type '{0}' to be '{1}'.";
public static readonly LocalizableString MessageFormat = "Expected migration hash of type '{0}' to be '{1}'";

private static readonly LocalizableString Description = "An incorrect migration hash is a hint that you may have forgotten to add a migration. " +
"The hash is calculated from all properties with a `DataMember` attribute " +
Expand All @@ -40,6 +40,8 @@ public class MigrationHashAnalyzer : DiagnosticAnalyzer

public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
context.RegisterCompilationStartAction(OnCompilationStart);
}

Expand Down
2 changes: 1 addition & 1 deletion Weingartner.Json.Migration.Roslyn/MigrationHashHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private static AttributeSyntax GetAttribute(SyntaxList<AttributeListSyntax> attr
{
var ctorSymbol = semanticModel.GetSymbolInfo(a, ct).Symbol;
var typeSymbol = ctorSymbol?.ContainingSymbol;
return typeSymbol?.Equals(attributeType) ?? false;
return typeSymbol?.Equals(attributeType, SymbolEqualityComparer.Default) ?? false;
});
}

Expand Down
5 changes: 4 additions & 1 deletion Weingartner.Json.Migration.Roslyn/MigrationMethodAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ public class MigrationMethodAnalyzer : DiagnosticAnalyzer

public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
context.RegisterCompilationStartAction(OnCompilationStart);
}

private static void OnCompilationStart(CompilationStartAnalysisContext context)
{
var migratableAttributeType = context.Compilation.GetTypeByMetadataName(Constants.MigratableAttributeMetadataName);
Expand Down Expand Up @@ -73,7 +76,7 @@ private static Func<SimpleType, SimpleType, bool> CanAssign(SyntaxNodeAnalysisCo

var t1 = context.SemanticModel.Compilation.GetTypeByMetadataName(srcType.FullName);
var t2 = context.SemanticModel.Compilation.GetTypeByMetadataName(targetType.FullName);
return getBaseTypesAndSelf(t1).Contains(t2);
return getBaseTypesAndSelf(t1).Contains(t2,SymbolEqualityComparer.Default);
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,10 @@
<None Update="tools\*.ps1" CopyToOutputDirectory="Always" Pack="true" PackagePath="" />
</ItemGroup>

<ItemGroup>
<AdditionalFiles Include="AnalyzerReleases.Shipped.md" />
<AdditionalFiles Include="AnalyzerReleases.Unshipped.md" />
</ItemGroup>

</Project>

0 comments on commit f949be4

Please sign in to comment.