Skip to content

[release/9.0] Fixing Analyzer issues, servicing, Part 2: Actual Fixes #13182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: servicing/RefactorAnalyzerTests9.0Rel
Choose a base branch
from

Conversation

KlausLoeffelmann
Copy link
Member

@KlausLoeffelmann KlausLoeffelmann commented Mar 25, 2025

Part 2 of servicing Analyzer fixes back to release/9.0.

This PR contains the actual fixes along with the added tests based on the back ported infrastructure from .NET 10.

See Part 1, Changing the Infrastructure, here:
#13072

Microsoft Reviewers: Open in CodeFlow

Please note, that these fixes have been done and checked, so the respective other language applied, both in C# and Visual Basic, and then Unit Tests had been added to cover those scenarios.

From here, once these are OK'ed, we will back-port them (again, if you will, because the originally came from .NET 10 main), to .NET 10, and the new Clipboard Analyzer's tests will then be updated to integrate into the new test infra.

And after that, they can go into main/net10.

@KlausLoeffelmann KlausLoeffelmann force-pushed the FixAnalyzerIssues9.0Rel branch 2 times, most recently from 19e5925 to fe3dd24 Compare March 25, 2025 00:12
@KlausLoeffelmann KlausLoeffelmann changed the title [release/9.0] Fixing Analyzer issues, servicing, Part 1: Actual Fixes [release/9.0] Fixing Analyzer issues, servicing, Part 2: Actual Fixes Mar 25, 2025
@KlausLoeffelmann KlausLoeffelmann changed the base branch from main to release/9.0 March 25, 2025 00:31
@dotnet-policy-service dotnet-policy-service bot added the draft draft PR label Mar 25, 2025
Copy link

codecov bot commented Mar 31, 2025

Codecov Report

Attention: Patch coverage is 95.00000% with 4 lines in your changes missing coverage. Please review.

Project coverage is 74.79265%. Comparing base (44f90e2) to head (4436879).
Report is 20 commits behind head on release/9.0.

Additional details and impacted files
@@                  Coverage Diff                  @@
##           release/9.0      #13182         +/-   ##
=====================================================
- Coverage     74.83821%   74.79265%   -0.04557%     
=====================================================
  Files             3022        2997         -25     
  Lines           630460      629261       -1199     
  Branches         46797       46742         -55     
=====================================================
- Hits            471825      470641       -1184     
- Misses          155247      155258         +11     
+ Partials          3388        3362         -26     
Flag Coverage Δ
Debug 74.79265% <95.00000%> (+4.24119%) ⬆️
integration 18.00682% <ø> (-0.00378%) ⬇️
production 47.78797% <ø> (-0.07921%) ⬇️
test 96.99183% <95.00000%> (-0.04999%) ⬇️
unit 44.79785% <ø> (-0.08361%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@KlausLoeffelmann KlausLoeffelmann force-pushed the FixAnalyzerIssues9.0Rel branch from c6effd1 to 7b2aaa0 Compare April 3, 2025 08:21
@Tanya-Solyanik Tanya-Solyanik added area-Analyzers/CodeFixes A Roslyn Analyzer is either needed for the context, needs to be scope extended or fixed. and removed area-Infrastructure labels Apr 3, 2025
@KlausLoeffelmann KlausLoeffelmann marked this pull request as ready for review April 4, 2025 17:30
@KlausLoeffelmann KlausLoeffelmann requested a review from a team as a code owner April 4, 2025 17:30
@dotnet-policy-service dotnet-policy-service bot removed the draft draft PR label Apr 4, 2025
@KlausLoeffelmann KlausLoeffelmann added the 🚫 * NO-MERGE * The PR is not ready for merge yet (see discussion for detailed reasons) label Apr 4, 2025
@@ -12,6 +12,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
<GenerateResourceWarnOnBinaryFormatterUse>false</GenerateResourceWarnOnBinaryFormatterUse>
<IsTestUtilityProject>true</IsTestUtilityProject>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this property needed? Do we not set shipping/notshipping properties based on the Test suffix?

@KlausLoeffelmann KlausLoeffelmann changed the base branch from release/9.0 to servicing/RefactorAnalyzerTests9.0Rel April 8, 2025 17:55
Net8_0,
Net9_0
Net6_0 = 0x00000006,
Net7_0 = 0x00000007,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned that eventually & will go out of support and will not be installed on the CI machines. Can we test only against 9 in the servicing branches?


using Microsoft.CodeAnalysis.Testing;

// File-Cherry-Picked and modified a bit from Tanya Solyanik's Commit ec6a9f8,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed, we put notes like this when code is shared with other repos, and might go out of sync. In he same repo we can always look up history in the main branch

public static class WinFormsReferencesFactory
{
private const string RefPackageName = "Microsoft.NETCore.App.Ref";
private const string PrivatePackagePath = "artifacts\\packages\\Debug\\NonShipping\\Microsoft.Private.Winforms.9.0.3-dev.nupkg";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how this works -
it assumes someone had built Debug and it assumes specific version...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait... we shouldn't run against the current binary in the artifacts folder in the release branch, everything is already shipped...

if (objectTypeInfo.Type is not INamedTypeSymbol objectType
|| !IsAncestorOrSelfOfType(objectType, "System.Windows.Forms.Control"))
// For implicit calls, we check the containing type of the method itself.
if (containingType is null || !IsAncestorOrSelfOfType(containingType, "System.Windows.Forms.Control"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also check if this binary references winforms? THeoretically it's possible to have user assembly that defines the same type.


// Does the property belong to a class which derives from Component?
// We never flag a property named Site of type of ISite
if (propertySymbol is null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use pattern matching


using System.Windows.Forms;

public static class Program
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file really needed?

<Compile Remove="Analyzer\AvoidPassingTaskWithoutCancellationToken\TestData\InvokeAsyncOnControl\AnalyzerTestCode.vb" />
<Compile Remove="Analyzer\MissingPropertySerializationConfiguration\TestData\CustomControlScenarios\AnalyzerTestCode.vb" />
<Compile Remove="Analyzer\MissingPropertySerializationConfiguration\TestData\CustomControlScenarios\CodeFixTestCode.vb" />
<Compile Remove="Analyzer\MissingPropertySerializationConfiguration\TestData\CustomControlScenarios\FixedTestCode.vb" />
<Compile Remove="Analyzer\MissingPropertySerializationConfiguration\TestData\CustomControlScenarios\Program.vb" />
<Compile Remove="Analyzer\MissingPropertySerializationConfiguration\TestData\EdgeCaseScenarios\AnalyzerTestCode.vb" />
<Compile Remove="Analyzer\MissingPropertySerializationConfiguration\TestData\EdgeCaseScenarios\Program.vb" />
<Compile Remove="D:\git\winforms\eng\CodeAnalysisSource.vb" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops

@@ -11,11 +11,16 @@
</PropertyGroup>

<ItemGroup>
<Compile Remove="Analyzer\AvoidPassingTaskWithoutCancellationToken\TestData\ImplicitInvokeAsyncOnControl\AnalyzerTestCode.vb" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use DefaultItemExcludesInProjectFolder property

@@ -50,11 +55,16 @@
</ItemGroup>

<ItemGroup>
<None Include="Analyzer\AvoidPassingTaskWithoutCancellationToken\TestData\ImplicitInvokeAsyncOnControl\AnalyzerTestCode.vb" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this for?

</ItemGroup>


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra white line

|| propertySymbol.DeclaredAccessibility < Accessibility.Internal)
{
return;
}

// Skip overridden properties since the base property should already have the appropriate serialization configuration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to iterate over the base properties?

if (propertySymbol.SetMethod is null
// Is the property read/write and at least internal and doesn't have a private setter?
if (propertySymbol.SetMethod is not IMethodSymbol propertySetter
|| propertySetter.DeclaredAccessibility == Accessibility.Private
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is checking DeclaredAccessibility sufficient? It should be the default accessibility.

if (propertySymbol.SetMethod is null
// Is the property read/write and at least internal and doesn't have a private setter?
if (propertySymbol.SetMethod is not IMethodSymbol propertySetter
|| propertySetter.DeclaredAccessibility == Accessibility.Private
|| propertySymbol.DeclaredAccessibility < Accessibility.Internal)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this check still needed?


## Table of Contents
1. [Project Structure](#project-structure)
2. [Language-Specific Considerations](#language-specific-considerations)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you set number as 1. for all these lines, the actual numbers will be auto-generated.

}

// Skip static properties since they are not serialized by the designer
if (propertySymbol.IsStatic)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please front-load this check to exit fast.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Analyzers/CodeFixes A Roslyn Analyzer is either needed for the context, needs to be scope extended or fixed. 🚫 * NO-MERGE * The PR is not ready for merge yet (see discussion for detailed reasons)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants