Skip to content

Commit de72f19

Browse files
authored
Fix to disable RXUISG0016 analyzer for read-only properties (#70)
Closes #66
1 parent f3bf34d commit de72f19

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

src/ReactiveUI.SourceGenerators.Execute/TestViewModel.cs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,47 @@ public TestViewModel()
142142
public static TestViewModel Instance { get; } = new();
143143

144144
/// <summary>
145-
/// Gets or sets the test property.
145+
/// Gets the internal test property. Should not prompt to replace with INPC Reactive Property.
146146
/// </summary>
147147
/// <value>
148148
/// The test property.
149149
/// </value>
150150
[JsonInclude]
151-
public string? TestProperty { get; set; } = "Test";
151+
public string? TestInternalSetProperty { get; internal set; } = "Test";
152+
153+
/// <summary>
154+
/// Gets the test private set property. Should not prompt to replace with INPC Reactive Property.
155+
/// </summary>
156+
/// <value>
157+
/// The test private set property.
158+
/// </value>
159+
[JsonInclude]
160+
public string? TestPrivateSetProperty { get; private set; } = "Test";
161+
162+
/// <summary>
163+
/// Gets or sets the test automatic property.
164+
/// </summary>
165+
/// <value>
166+
/// The test automatic property.
167+
/// </value>
168+
[JsonInclude]
169+
public string? TestAutoProperty { get; set; } = "Test, should prompt to replace with INPC Reactive Property";
170+
171+
/// <summary>
172+
/// Gets or sets the reactive command test property. Should not prompt to replace with INPC Reactive Property.
173+
/// </summary>
174+
/// <value>
175+
/// The reactive command test property.
176+
/// </value>
177+
public ReactiveCommand<Unit, Unit>? ReactiveCommandTestProperty { get; set; }
178+
179+
/// <summary>
180+
/// Gets or sets the reactive property test property. Should not prompt to replace with INPC Reactive Property.
181+
/// </summary>
182+
/// <value>
183+
/// The reactive property test property.
184+
/// </value>
185+
public ReactiveProperty<int>? ReactivePropertyTestProperty { get; set; }
152186

153187
/// <summary>
154188
/// Gets the can execute test1.

src/ReactiveUI.SourceGenerators/Diagnostics/CodeAnalyzers/PropertyToReactiveFieldAnalyzer.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context)
5252
}
5353

5454
var isAutoProperty = propertyDeclaration.ExpressionBody == null && (propertyDeclaration.AccessorList?.Accessors.All(a => a.Body == null && a.ExpressionBody == null) != false);
55+
var hasCorrectModifiers = propertyDeclaration.Modifiers.Any(SyntaxKind.PublicKeyword) && !propertyDeclaration.Modifiers.Any(SyntaxKind.StaticKeyword);
56+
var doesNotHavePrivateSetOrInternalSet = propertyDeclaration.AccessorList?.Accessors.Any(a => a.Modifiers.Any(SyntaxKind.PrivateKeyword) || a.Modifiers.Any(SyntaxKind.InternalKeyword)) == false;
57+
var isNotReactiveCommand = !propertyDeclaration.Type.ToString().Contains("ReactiveCommand");
58+
var isNotReactiveProperty = !propertyDeclaration.Type.ToString().Contains("ReactiveProperty");
5559

56-
if (isAutoProperty && propertyDeclaration.Modifiers.Any(SyntaxKind.PublicKeyword) && !propertyDeclaration.Modifiers.Any(SyntaxKind.StaticKeyword))
60+
if (isAutoProperty && hasCorrectModifiers && doesNotHavePrivateSetOrInternalSet && isNotReactiveCommand && isNotReactiveProperty)
5761
{
5862
var diagnostic = Diagnostic.Create(DiagnosticDescriptors.PropertyToReactiveFieldRule, propertyDeclaration.GetLocation());
5963
context.ReportDiagnostic(diagnostic);

0 commit comments

Comments
 (0)