dotnet / roslyn-analyzers

MIT License
1.58k stars 465 forks source link

CA1812 (at least) is not being reported #7281

Closed Youssef1313 closed 6 months ago

Youssef1313 commented 6 months ago

Analyzer

Diagnostic ID: CA1812

Analyzer source

NuGet: 9.0.0-preview.24072.1

Describe the bug

On current Uno's master. Add an unused internal class anywhere, for example:

image

And add the following lines to .globalconfig:

# CA1812: Avoid uninstantiated internal classes
dotnet_diagnostic.CA1812.severity = error
dotnet_code_quality.CA1812.ignore_internalsvisibleto = true

Do a build (IDE or command-line produces the same result) → No warning/error when there should be one.

Expected behavior

Diagnostic produced.

Actual behavior

No diagnostic produced.

Additional context

I noticed we haven't been seeing any CAxxxx diagnostics for quite too long. So, this might not be specific to CA1812.

Analyzers passed to Csc:

Analyzers
    C:\Users\PC\.nuget\packages\microsoft.codeanalysis.bannedapianalyzers\3.3.4\analyzers\dotnet\cs\Microsoft.CodeAnalysis.BannedApiAnalyzers.dll
        NuGetPackageVersion = 3.3.4
        NuGetPackageId = Microsoft.CodeAnalysis.BannedApiAnalyzers
    C:\Users\PC\.nuget\packages\microsoft.codeanalysis.bannedapianalyzers\3.3.4\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.BannedApiAnalyzers.dll
        NuGetPackageVersion = 3.3.4
        NuGetPackageId = Microsoft.CodeAnalysis.BannedApiAnalyzers
    C:\Users\PC\.nuget\packages\microsoft.codeanalysis.csharp.codestyle\4.9.0-3.final\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes.dll
        NuGetPackageVersion = 4.9.0-3.final
        NuGetPackageId = Microsoft.CodeAnalysis.CSharp.CodeStyle
    C:\Users\PC\.nuget\packages\microsoft.codeanalysis.csharp.codestyle\4.9.0-3.final\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.CodeStyle.dll
        NuGetPackageVersion = 4.9.0-3.final
        NuGetPackageId = Microsoft.CodeAnalysis.CSharp.CodeStyle
    C:\Users\PC\.nuget\packages\microsoft.codeanalysis.csharp.codestyle\4.9.0-3.final\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CodeStyle.Fixes.dll
        NuGetPackageVersion = 4.9.0-3.final
        NuGetPackageId = Microsoft.CodeAnalysis.CSharp.CodeStyle
    C:\Users\PC\.nuget\packages\microsoft.codeanalysis.csharp.codestyle\4.9.0-3.final\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CodeStyle.dll
        NuGetPackageVersion = 4.9.0-3.final
        NuGetPackageId = Microsoft.CodeAnalysis.CSharp.CodeStyle
    C:\Users\PC\.nuget\packages\microsoft.codeanalysis.netanalyzers\9.0.0-preview.24072.1\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.NetAnalyzers.dll
        NuGetPackageVersion = 9.0.0-preview.24072.1
        NuGetPackageId = Microsoft.CodeAnalysis.NetAnalyzers
    C:\Users\PC\.nuget\packages\microsoft.codeanalysis.netanalyzers\9.0.0-preview.24072.1\analyzers\dotnet\cs\Microsoft.CodeAnalysis.NetAnalyzers.dll
        NuGetPackageVersion = 9.0.0-preview.24072.1
        NuGetPackageId = Microsoft.CodeAnalysis.NetAnalyzers
    C:\Users\PC\Desktop\uno\src\SourceGenerators\Uno.UI.SourceGenerators.Internal\bin\Debug\netstandard2.0\Uno.UI.SourceGenerators.Internal.dll
        ReferenceSourceTarget = ProjectReference
        MSBuildSourceProjectFile = C:\Users\PC\Desktop\uno\src\SourceGenerators\Uno.UI.SourceGenerators.Internal\Uno.UI.SourceGenerators.Internal.csproj
        HasSingleTargetFramework = true
        TargetFrameworkIdentifier = .NETStandard
        ReferenceOutputAssembly = false
        OutputItemType = Analyzer
        TargetPlatformMonikers = Windows,Version=7.0
        TargetPlatformMoniker = Windows,Version=7.0
        BuildReference = true
        Platform = AnyCPU
        CopyUpToDateMarker = C:\Users\PC\Desktop\uno\src\SourceGenerators\Uno.UI.SourceGenerators.Internal\obj\Debug\netstandard2.0\Uno.UI.SourceGenerators.Internal.csproj.CopyComplete
        AdditionalPropertiesFromProject = <AdditionalProjectProperties>
  <TargetFramework Name="netstandard2.0">
    <SelfContained></SelfContained>
    <_IsExecutable></_IsExecutable>
    <IsRidAgnostic>true</IsRidAgnostic>
    <ShouldBeValidatedAsExecutableReference></ShouldBeValidatedAsExecutableReference>
    <_SelfContainedWasSpecified></_SelfContainedWasSpecified>
  </TargetFramework>
</AdditionalProjectProperties>
        TargetFrameworkMonikers = .NETStandard,Version=v2.0
        TargetFrameworks = netstandard2.0
        IsRidAgnostic = true
        MSBuildSourceTargetName = GetTargetFrameworks
        NearestTargetFramework = netstandard2.0
        UndefineProperties = ;TargetFramework;RuntimeIdentifier;SelfContained
        TargetPlatformIdentifier = Windows
        TargetFrameworkVersion = 2.0
        Platforms = AnyCPU
        Targets = 
        OriginalItemSpec = ..\SourceGenerators\Uno.UI.SourceGenerators.Internal\Uno.UI.SourceGenerators.Internal.csproj
    C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.17\analyzers/dotnet/cs/Microsoft.Interop.JavaScript.JSImportGenerator.dll
        FileVersion = 7.0.10.11508
        NuGetPackageVersion = 7.0.17
        Private = false
        PublicKeyToken = b03f5f7f11d50a3a
        FrameworkReferenceVersion = 7.0.17
        ExternallyResolved = true
        NuGetPackageId = Microsoft.NETCore.App.Ref
        FrameworkReferenceName = Microsoft.NETCore.App
        AssemblyVersion = 7.0.10.11508
    C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.17\analyzers/dotnet/cs/Microsoft.Interop.LibraryImportGenerator.dll
        FileVersion = 7.0.10.11508
        NuGetPackageVersion = 7.0.17
        Private = false
        PublicKeyToken = b03f5f7f11d50a3a
        FrameworkReferenceVersion = 7.0.17
        ExternallyResolved = true
        NuGetPackageId = Microsoft.NETCore.App.Ref
        FrameworkReferenceName = Microsoft.NETCore.App
        AssemblyVersion = 7.0.10.11508
    C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.17\analyzers/dotnet/cs/Microsoft.Interop.SourceGeneration.dll
        FileVersion = 7.0.10.11508
        NuGetPackageVersion = 7.0.17
        Private = false
        PublicKeyToken = b03f5f7f11d50a3a
        FrameworkReferenceVersion = 7.0.17
        ExternallyResolved = true
        NuGetPackageId = Microsoft.NETCore.App.Ref
        FrameworkReferenceName = Microsoft.NETCore.App
        AssemblyVersion = 7.0.10.11508
    C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.17\analyzers/dotnet/cs/System.Text.Json.SourceGeneration.dll
        FileVersion = 7.0.10.11508
        NuGetPackageVersion = 7.0.17
        Private = false
        PublicKeyToken = cc7b13ffcd2ddd51
        FrameworkReferenceVersion = 7.0.17
        ExternallyResolved = true
        NuGetPackageId = Microsoft.NETCore.App.Ref
        FrameworkReferenceName = Microsoft.NETCore.App
        AssemblyVersion = 7.0.10.11508
    C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.17\analyzers/dotnet/cs/System.Text.RegularExpressions.Generator.dll
        FileVersion = 7.0.10.11508
        NuGetPackageVersion = 7.0.17
        Private = false
        PublicKeyToken = b03f5f7f11d50a3a
        FrameworkReferenceVersion = 7.0.17
        ExternallyResolved = true
        NuGetPackageId = Microsoft.NETCore.App.Ref
        FrameworkReferenceName = Microsoft.NETCore.App
        AssemblyVersion = 7.0.10.11508
    C:\Users\PC\Desktop\uno\src\SourceGenerators\Uno.UI.SourceGenerators\Content\..\bin\Debug\netstandard2.0\Microsoft.ApplicationInsights.dll
    C:\Users\PC\Desktop\uno\src\SourceGenerators\Uno.UI.SourceGenerators\Content\..\bin\Debug\netstandard2.0\Microsoft.DotNet.PlatformAbstractions.dll
    C:\Users\PC\Desktop\uno\src\SourceGenerators\Uno.UI.SourceGenerators\Content\..\bin\Debug\netstandard2.0\Uno.UI.SourceGenerators.dll
    C:\Users\PC\Desktop\uno\src\SourceGenerators\Uno.UI.SourceGenerators\Content\..\bin\Debug\netstandard2.0\Uno.Xaml.dll

Analyzer config files:

AnalyzerConfigFiles
    C:\Users\PC\Desktop\uno\.editorconfig
    C:\Users\PC\Desktop\uno\src\Uno.UI\Microsoft\.editorconfig
    C:\Users\PC\Desktop\uno\src\Uno.UI\Microsoft\UI\Xaml\.editorconfig
    C:\Users\PC\Desktop\uno\.globalconfig
    C:\Users\PC\.nuget\packages\microsoft.codeanalysis.csharp.codestyle\4.9.0-3.final\build\config\analysislevelstyle_default.globalconfig
    obj\Uno.UI.Skia\Debug\net7.0\Uno.UI.Skia.d-bfalse.GeneratedMSBuildEditorConfig.editorconfig
    C:\Users\PC\.nuget\packages\microsoft.codeanalysis.netanalyzers\9.0.0-preview.24072.1\buildTransitive\config\analysislevel_9_default.globalconfig
    C:\Users\PC\.nuget\packages\microsoft.codeanalysis.netanalyzers\9.0.0-preview.24072.1\buildTransitive\config\analysislevelglobalization_9_all.globalconfig
    C:\Users\PC\.nuget\packages\microsoft.codeanalysis.netanalyzers\9.0.0-preview.24072.1\buildTransitive\config\analysislevelperformance_9_all.globalconfig

TreatWarningsAsErrors is passed as "True".

Youssef1313 commented 6 months ago

My bad. I had an existing entry for CA1812.

Though I had to dig into the compiler code to understand why this wasn't working.