Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ public override void Initialize(AnalysisContext context)
continue;
}

// We can safely ignore properties that already have [ObservableProperty]
if (typeSymbol.HasAttributeWithType(observablePropertySymbol))
// We can safely ignore properties that already have [ObservableProperty].
// This is because in that case, the other analyzer will already emit an error.
if (propertySymbol.HasAttributeWithType(observablePropertySymbol))
{
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,28 @@ public string Name
await CSharpAnalyzerWithLanguageVersionTest<UseObservablePropertyOnSemiAutoPropertyAnalyzer>.VerifyAnalyzerAsync(source, LanguageVersion.Preview);
}

[TestMethod]
public async Task UseObservablePropertyOnSemiAutoPropertyAnalyzer_ValidProperty_WithObservableProperty_DoesNotWarn()
{
const string source = """
using CommunityToolkit.Mvvm.ComponentModel;

namespace MyApp;

public partial class SampleViewModel : ObservableObject
{
[ObservableProperty]
public string Name
{
get => field;
set => SetProperty(ref field, value);
}
}
""";

await CSharpAnalyzerWithLanguageVersionTest<UseObservablePropertyOnSemiAutoPropertyAnalyzer>.VerifyAnalyzerAsync(source, LanguageVersion.Preview);
}

[TestMethod]
public async Task UseObservablePropertyOnSemiAutoPropertyAnalyzer_ValidProperty_Warns()
{
Expand Down