Skip to content

Commit 1d4fb90

Browse files
committed
fix(codegen): Don't warn on CA1001 by default (disposable fields) for generated code
1 parent 3fe3862 commit 1d4fb90

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/SourceGenerators/Uno.UI.SourceGenerators/Content/Uno.UI.SourceGenerators.props

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@
169169
<IncludeXamlNamespaces Condition="'$(XamarinProjectType)'=='net461'" Include="not_netstdref" />
170170

171171
<!--
172-
A list of analyzer suppressions to include in every generated class.
173-
This is required for roslyn analyzers that do not support the GeneratedCodeAttribute.
174-
-->
172+
A list of analyzer suppressions to include in every generated class.
173+
This is required for roslyn analyzers that do not support the GeneratedCodeAttribute.
174+
-->
175175
<XamlGeneratorAnalyzerSuppressions Include="nventive.Usage-NV0056" />
176176
<XamlGeneratorAnalyzerSuppressions Include="nventive.Usage-NV0058" />
177177
<XamlGeneratorAnalyzerSuppressions Include="nventive.Usage-NV1003" />
@@ -180,6 +180,12 @@
180180
<XamlGeneratorAnalyzerSuppressions Include="nventive.Usage-NV2003" />
181181
<XamlGeneratorAnalyzerSuppressions Include="nventive.Usage-NV2004" />
182182
<XamlGeneratorAnalyzerSuppressions Include="nventive.Usage-NV2005" />
183+
184+
<!--
185+
Ignore disposable fields, Uno manages those on its own.
186+
https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1001
187+
-->
188+
<XamlGeneratorAnalyzerSuppressions Include="dotnet-CA1001" />
183189
</ItemGroup>
184190

185191
<PropertyGroup>

src/SourceGenerators/Uno.UI.SourceGenerators/DependencyObject/DependencyObjectGenerator.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ private class SerializationMethodsGenerator : SymbolVisitor
4949
private readonly INamedTypeSymbol? _iFrameworkElementSymbol;
5050
private readonly INamedTypeSymbol? _frameworkElementSymbol;
5151
private readonly bool _isUnoSolution;
52+
private readonly string[] _analyzerSuppressions;
5253

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

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

169+
AnalyzerSuppressionsGenerator.Generate(builder, _analyzerSuppressions);
170+
167171
var internalDependencyObject = _isUnoSolution && !typeSymbol.IsSealed ? ", IDependencyObjectInternal" : "";
168172

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

0 commit comments

Comments
 (0)