Repository: dotnet/efcore
File: src/EFCore.Analyzers/UninitializedDbSetDiagnosticSuppressor.cs (C#)

Code before:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;

namespace Microsoft.EntityFrameworkCore;

[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class UninitializedDbSetDiagnosticSuppressor : DiagnosticSuppressor
{
    private static readonly SuppressionDescriptor _suppressUninitializedDbSetRule = new(
        id: "SPR1001",
        suppressedDiagnosticId: "CS8618",
        justification: "DbSet properties on DbContext subclasses are automatically populated by the DbContext constructor");

    /// <inheritdoc />
    public override ImmutableArray<SuppressionDescriptor> SupportedSuppressions { get; }
        = ImmutableArray.Create(_suppressUninitializedDbSetRule);

    /// <inheritdoc />
    public override void ReportSuppressions(SuppressionAnalysisContext context)
    {
        INamedTypeSymbol? dbSetTypeSymbol = null;
        INamedTypeSymbol? dbContextTypeSymbol = null;

        foreach (var diagnostic in context.ReportedDiagnostics)
        {
            // We have an warning about an uninitialized non-nullable property.
            // Get the node, and make sure it's a property who's type syntactically contains DbSet (fast check before getting the
            // semantic model, which is heavier).
            if (diagnostic.Location.SourceTree is not { } sourceTree
                || sourceTree.GetRoot().FindNode(diagnostic.Location.SourceSpan) is not PropertyDeclarationSyntax propertyDeclarationSyntax
                || !propertyDeclarationSyntax.Type.ToString().Contains("DbSet"))
            {

Review comment (suggestion):
nit: I usually like to seal analyzers, codefixes, and suppressors. This is a common pattern in dotnet/roslyn-analyzers as well:

https://github.com/dotnet/roslyn-analyzers/blob/ffd024eb265e97e639a2879d869cf82b5b958992/src/Roslyn.Diagnostics.Analyzers/Core/NamedTypeFullNameNotNullSuppressor.cs#L14


```suggestion
public sealed class UninitializedDbSetDiagnosticSuppressor : DiagnosticSuppressor
```

Code after:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;

namespace Microsoft.EntityFrameworkCore;

[DiagnosticAnalyzer(LanguageNames.CSharp)]
public sealed class UninitializedDbSetDiagnosticSuppressor : DiagnosticSuppressor
{
    private static readonly SuppressionDescriptor _suppressUninitializedDbSetRule = new(
        id: "SPR1001",
        suppressedDiagnosticId: "CS8618",
        justification: AnalyzerStrings.UninitializedDbSetWarningSuppressionJustification);

    /// <inheritdoc />
    public override ImmutableArray<SuppressionDescriptor> SupportedSuppressions { get; }
        = ImmutableArray.Create(_suppressUninitializedDbSetRule);

    /// <inheritdoc />
    public override void ReportSuppressions(SuppressionAnalysisContext context)
    {
        INamedTypeSymbol? dbSetTypeSymbol = null;
        INamedTypeSymbol? dbContextTypeSymbol = null;

        foreach (var diagnostic in context.ReportedDiagnostics)
        {
            // We have an warning about an uninitialized non-nullable property.
            // Get the node, and make sure it's a property who's type syntactically contains DbSet (fast check before getting the
            // semantic model, which is heavier).
            if (diagnostic.Location.SourceTree is not { } sourceTree
                || sourceTree.GetRoot().FindNode(diagnostic.Location.SourceSpan) is not PropertyDeclarationSyntax propertyDeclarationSyntax
                || !propertyDeclarationSyntax.Type.ToString().Contains("DbSet"))
            {