-
-
Notifications
You must be signed in to change notification settings - Fork 962
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
feat: Roslyn Diagnostics Analyzer for empty constructor #2104
Conversation
sources/targets/Stride.Core.targets
Outdated
<!-- 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> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
- 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). - since these generates a lot of warnings in the build log, those analyzers are disabled by default (unless
StrideEnableCodeAnalysis
is also set totrue
. - 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:
- Either we keep the stylecop rule, in which case we can add another exception for PolySharp in that "allow-list".
- We decide we don't want stylecop anymore and we just remove all of that.
a. we do keep the firstStrideCodeAnalysis
section to use the proper ruleset
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 😅
<PackageReference Include="PolySharp"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 )
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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:
netstandard2.0
is a requirement for analyzers/source generators. Nothing we can do about.- 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.
sources/core/Stride.Core.CompilerServices/Stride.Core.CompilerServices.csproj
Outdated
Show resolved
Hide resolved
sources/core/Stride.Core.CompilerServices.Tests/Stride.Core.CompilerServices.Tests.csproj
Show resolved
Hide resolved
0f37ffa
to
2387b1a
Compare
Note: make sure to validate and merge #2105 first. |
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 |
sources/core/Stride.Core.CompilerServices/Analyzers/STRDIAG010InvalidConstructor.cs
Show resolved
Hide resolved
sources/core/Stride.Core.CompilerServices/Analyzers/STRDIAG010InvalidConstructor.cs
Outdated
Show resolved
Hide resolved
sources/core/Stride.Core.CompilerServices/Analyzers/STRDIAG010InvalidConstructor.cs
Outdated
Show resolved
Hide resolved
sources/core/Stride.Core.CompilerServices/Analyzers/STRDIAG010InvalidConstructor.cs
Outdated
Show resolved
Hide resolved
79e993f
to
3540261
Compare
i will reopen when i know whats wrong with git lfs |
This reverts commit 79e993f.
i think its ready to merge, should i change the name of the PR to use the new tags |
There was a problem hiding this 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/core/Stride.Core.CompilerServices/Common/SymbolExtensions.cs
Outdated
Show resolved
Hide resolved
completed the changes |
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 |
Thanks ! |
stride3d/stride-docs#295 |
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
Checklist