Skip to content

Commit

Permalink
fix(codegen): Don't warn on CA1001 by default (disposable fields) for…
Browse files Browse the repository at this point in the history
… generated code
  • Loading branch information
jeromelaban committed May 11, 2022
1 parent 3fe3862 commit 1d4fb90
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@
<IncludeXamlNamespaces Condition="'$(XamarinProjectType)'=='net461'" Include="not_netstdref" />

<!--
A list of analyzer suppressions to include in every generated class.
This is required for roslyn analyzers that do not support the GeneratedCodeAttribute.
-->
A list of analyzer suppressions to include in every generated class.
This is required for roslyn analyzers that do not support the GeneratedCodeAttribute.
-->
<XamlGeneratorAnalyzerSuppressions Include="nventive.Usage-NV0056" />
<XamlGeneratorAnalyzerSuppressions Include="nventive.Usage-NV0058" />
<XamlGeneratorAnalyzerSuppressions Include="nventive.Usage-NV1003" />
Expand All @@ -180,6 +180,12 @@
<XamlGeneratorAnalyzerSuppressions Include="nventive.Usage-NV2003" />
<XamlGeneratorAnalyzerSuppressions Include="nventive.Usage-NV2004" />
<XamlGeneratorAnalyzerSuppressions Include="nventive.Usage-NV2005" />

<!--
Ignore disposable fields, Uno manages those on its own.
https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1001
-->
<XamlGeneratorAnalyzerSuppressions Include="dotnet-CA1001" />
</ItemGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ private class SerializationMethodsGenerator : SymbolVisitor
private readonly INamedTypeSymbol? _iFrameworkElementSymbol;
private readonly INamedTypeSymbol? _frameworkElementSymbol;
private readonly bool _isUnoSolution;
private readonly string[] _analyzerSuppressions;

public SerializationMethodsGenerator(GeneratorExecutionContext context)
{
Expand All @@ -68,6 +69,7 @@ public SerializationMethodsGenerator(GeneratorExecutionContext context)
_iFrameworkElementSymbol = comp.GetTypeByMetadataName(XamlConstants.Types.IFrameworkElement);
_frameworkElementSymbol = comp.GetTypeByMetadataName("Windows.UI.Xaml.FrameworkElement");
_isUnoSolution = _context.GetMSBuildPropertyValue("_IsUnoUISolution") == "true";
_analyzerSuppressions = context.GetMSBuildPropertyValue("XamlGeneratorAnalyzerSuppressionsProperty").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
}

public override void VisitNamedType(INamedTypeSymbol type)
Expand Down Expand Up @@ -164,6 +166,8 @@ private void ProcessType(INamedTypeSymbol typeSymbol)
builder.AppendLineInvariant(@"[global::Windows.UI.Xaml.Data.Bindable]");
}

AnalyzerSuppressionsGenerator.Generate(builder, _analyzerSuppressions);

var internalDependencyObject = _isUnoSolution && !typeSymbol.IsSealed ? ", IDependencyObjectInternal" : "";

using (builder.BlockInvariant($"partial class {typeSymbol.Name} : IDependencyObjectStoreProvider, IWeakReferenceProvider{internalDependencyObject}"))
Expand Down

0 comments on commit 1d4fb90

Please sign in to comment.