Skip to content
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

feat: Roslyn Diagnostics Analyzer for empty constructor #2104

Merged
merged 32 commits into from
May 30, 2024

Conversation

IXLLEGACYIXL
Copy link
Collaborator

@IXLLEGACYIXL IXLLEGACYIXL commented Jan 13, 2024

PR Details

Adds a Warning for not having an Empty Constructor

Description

Diagnostics Analyzer for #2098 to throw at Compile Time a warning when an empty constructor is missing.

Types of changes

  • Docs change / refactoring / dependency upgrade ( i have to make with vaso a new diagnostics website )
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My change requires a change to the documentation.
  • I have added tests to cover my changes.
  • All new and existing tests passed. ( 66 fail as same with master )
  • I have built and run the editor to try this change out.

@IXLLEGACYIXL IXLLEGACYIXL marked this pull request as draft January 13, 2024 20:55
Comment on lines 43 to 56
<!-- Disable analyzers unless StrideEnableCodeAnalysis is set (note: PackageReference can't depend on external Condition) -->
<Target Name="DisableAnalyzersForStrideBuild"
BeforeTargets="CoreCompile"
Condition="'$(StrideEnableCodeAnalysis)' != 'true'">
<ItemGroup>
<!-- We want to include Stride analyzers by default -->
<AnalyzersNotToRemove Include="@(Analyzer)" Condition="$([System.String]::Copy(%(FullPath)).Contains('Stride'))" />
<!-- We want to include source generators by default -->
<AnalyzersNotToRemove Include="@(Analyzer)" Condition="$([System.String]::Copy(%(FullPath)).Contains('Generator'))" />
<AnalyzersNotToRemove Include="@(Analyzer)" Condition="$([System.String]::Copy(%(FullPath)).Contains('SourceGeneration'))" />
<AnalyzersToRemove Include="@(Analyzer)" Exclude="@(AnalyzersNotToRemove)" />
<Analyzer Remove="@(AnalyzersToRemove)"/>
</ItemGroup>
</Target>
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't be removed.

Copy link
Collaborator Author

@IXLLEGACYIXL IXLLEGACYIXL Jan 13, 2024

Choose a reason for hiding this comment

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

it doesnt make a difference, stride compiles fine without it

i dont know why it is there , do you know why it is there?
i can launch my game with it just fine

Copy link
Member

Choose a reason for hiding this comment

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

Don't make changes that are not needed. It was there for a reason, and unless your changes require it to be removed it shouldn't. A PR should have the minimal changes that are required for a given feature, nothing more.

If there is an argument to be made about removing that part, it should be on its own PR and discussed there.
If as you said "it doesn't make a difference", then leave it.

I believe one of the reason this was added was to speed-up the build by disabling analysis that is not required (esp. during CI), as well as removing a lot of warnings that would make the logs harder to read in case a certain build needs investigating.

Copy link
Member

@Kryptos-FR Kryptos-FR Jan 13, 2024

Choose a reason for hiding this comment

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

After discussion on Discord, it appears that the Stylecop settings might be some Xenko leftovers. Maybe @xen2 can shine a light on this. But basically:

  1. we are adding a package reference for Stylecop assembly for all projects that have <StrideCodeAnalysis>true</StrideCodeAnalysis>. This seems to be most core and engine projects (not applied to editor).
  2. since these generates a lot of warnings in the build log, those analyzers are disabled by default (unless StrideEnableCodeAnalysis is also set to true.
  3. however, some analyzers/generators still need to be enabled at all time. Hence this "complex" rule with a allow-list of analyzers to not remove.

We have two options:

  1. Either we keep the stylecop rule, in which case we can add another exception for PolySharp in that "allow-list".
  2. We decide we don't want stylecop anymore and we just remove all of that.
    a. we do keep the first StrideCodeAnalysis section to use the proper ruleset

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

currently stylecop is added to each project, but no project has the StrideEnableCodeAnalysis so it gets removed immediately after

Copy link
Member

Choose a reason for hiding this comment

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

I think it was initially meant as an optional command line parameters when running a build.
Something like: msbuild -p:StrideEnableCodeAnalysis=true ...

Anyway, if #2105 is approved and merged, we won't need to discuss it anymore 😅

Comment on lines +26 to +30
<PackageReference Include="PolySharp">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

Copy link
Member

Choose a reason for hiding this comment

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

Where is it used? Is it required at runtime?

Copy link
Collaborator Author

@IXLLEGACYIXL IXLLEGACYIXL Jan 13, 2024

Choose a reason for hiding this comment

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

https://github.com/stride3d/stride/pull/2104/files#diff-015a4d048579b446685ff8c8dbddb5302ff100cd3fbfc1df1cef57c74a4032b6R66

its used here for pattern matching as i got told that i should do it that way ( funny thing is that this part is the only one that doesnt work )

Copy link
Member

Choose a reason for hiding this comment

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

Patter-matching is a feature of the language, it doesn't require an additional dependency. Your code seems to compile without Polysharp what does it add?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

grafik
System.Index and System.Index.GetOffset

ive changed it to a foreach loop now and added the analyzer removal back in

Copy link
Member

Choose a reason for hiding this comment

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

Just to keep a trace of what we discussed on Discord:

  1. netstandard2.0 is a requirement for analyzers/source generators. Nothing we can do about.
  2. because of that, certain languages features aren't available (like index/spread operations on collections in C# 12), unless we use a library such as PolySharp to fill the gaps.

@IXLLEGACYIXL IXLLEGACYIXL force-pushed the analyzer_empty_constructor branch from 0f37ffa to 2387b1a Compare January 13, 2024 23:29
@IXLLEGACYIXL IXLLEGACYIXL mentioned this pull request Jan 13, 2024
8 tasks
@Kryptos-FR
Copy link
Member

Note: make sure to validate and merge #2105 first.

@IXLLEGACYIXL
Copy link
Collaborator Author

for the tests, i freshly cloned stride and now im back to the standard 24 tests that fail normally, so i just had a corrupted clone

that is fine

@IXLLEGACYIXL IXLLEGACYIXL changed the title [WIP] Analyzer empty constructor Analyzer empty constructor Jan 15, 2024
@IXLLEGACYIXL IXLLEGACYIXL force-pushed the analyzer_empty_constructor branch from 79e993f to 3540261 Compare April 23, 2024 11:54
@IXLLEGACYIXL
Copy link
Collaborator Author

i will reopen when i know whats wrong with git lfs

This reverts commit 79e993f.
@IXLLEGACYIXL IXLLEGACYIXL reopened this Apr 23, 2024
@IXLLEGACYIXL
Copy link
Collaborator Author

i think its ready to merge, should i change the name of the PR to use the new tags

@IXLLEGACYIXL IXLLEGACYIXL marked this pull request as ready for review April 28, 2024 17:06
Copy link
Collaborator

@Eideren Eideren left a comment

Choose a reason for hiding this comment

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

Looks great, thanks, just two small notes

sources/targets/Stride.Core.targets Outdated Show resolved Hide resolved
@IXLLEGACYIXL
Copy link
Collaborator Author

completed the changes

@IXLLEGACYIXL
Copy link
Collaborator Author

the name of the PR should be changed to meet the tags for the new system that vaso made but i dont really know what it should be named to meet the categories

@VaclavElias VaclavElias added area-Core Issue of the engine unrelated to other defined areas engineering and removed area-Core Issue of the engine unrelated to other defined areas labels May 23, 2024
@IXLLEGACYIXL IXLLEGACYIXL changed the title Analyzer empty constructor engineering : Roslyn Diagnostics Analyzer for empty constructor May 23, 2024
@IXLLEGACYIXL IXLLEGACYIXL changed the title engineering : Roslyn Diagnostics Analyzer for empty constructor Roslyn Diagnostics Analyzer for empty constructor May 23, 2024
@IXLLEGACYIXL IXLLEGACYIXL changed the title Roslyn Diagnostics Analyzer for empty constructor feat: Roslyn Diagnostics Analyzer for empty constructor May 23, 2024
@Eideren Eideren merged commit 4cf0d08 into stride3d:master May 30, 2024
13 checks passed
@Eideren
Copy link
Collaborator

Eideren commented May 30, 2024

Thanks !

@IXLLEGACYIXL
Copy link
Collaborator Author

stride3d/stride-docs#295
the docs PR for this analyzer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants