-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Update dependencies from dotnet/roslyn-analyzers, config new analyzers #99343
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
21c5639
Reapply "[main] Update dependencies from dotnet/roslyn-analyzers (#98…
buyaa-n 5501a04
Configure new analyzers severity in src and test projects
buyaa-n b560232
Merge branch 'main' into analyzer-conf
buyaa-n 0f19341
Fix some of CA2263 warnings
buyaa-n 386ec50
Merge branch 'analyzer-conf' of github.com:buyaa-n/runtime into analy…
buyaa-n 84c469f
Revert 2 fixes that build for .NET framework
buyaa-n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is there a problem / difficulty with this diagnostic that prevents us from having it be a warning?
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 is a some cases where the suggested API is calling the type overload internally, I assume we would not like to flag them, let me know if you have other suggestion. There also some that looks could be more efficient and should be fixed, I will update them with this PR, overall around 200 findings with duplicates
CA2263 findings.txt
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 we should go through and prepare the change to fix them, and then evaluate any cases we believe are problematic. Two reasons:
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.
(That can/should certainly be separate from this PR.)
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.
Sure, I did evaluate them and concluded that those are not issue with the analyzer and also not worth fixing in the runtime, here is the reasons, please let me know if you have any comment/suggestion:
Excluded these cases from fixing:
Type
overload, like:public T CreateDelegate<T>() where T : Delegate => (T)CreateDelegate(typeof(T));
. I think there is nothing to fix in the analyzer, unless we want to check the implementation, which I did not think worth a fix, because the analyzer suggestion is more about AOT compliance, external applications should change to use the generic overload if they care about AOT or similar toolingType
overload). For example:Marshal.SizeOf<T>()
,Marshal.PtrToStructure<T>(nint)
etc. By my evaluation these doesn't look worth fixing, but not that sure with my evaluation. No fix needed for the analyzer with the same reason as above, from AOT perspective this is not false positive.Here are the all cases that I did not fix: CA2263 findings_NotFixed.txt
I have fixed the ones that worth fixing, PTAL
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.
Then this rule should start with "IDE" prefix https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/categories#style-rules. I think "IDE" rules should not added in
roslyn-analyzers
repo, probably inroslyn
?Not sure we could move there ...
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.
In some cases, the fix suggested by the analyzer may result in a minor performance improvement. Example: Replacing
Enum.GetName
withEnumGetName<TEnum>
will avoid boxing. I am not aware of anything else.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.
Yes, and that is why I fixed those cases with this PR, thought the cases where the generic overload implementation just calling the
Type
overload, will have some perf degradation, for other case likeMarshal.SizeOf<T>()
andMarshal.SizeOf(Type)
the perf impact was not obvious, so did not fix. Anyway, I don't think with the analyzer we could evaluate the perf impact.Based on your and @stephentoub's feedback I put up a PR that fixes all cases excluding the projects that target down-level platforms and
System.Linq.Expression
.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 that is the case, so what we should do with the analyzer now?
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.
The fact that it catches things like changing Enum calls from non-generic to generic makes me still excited about it. I was just fixing up an internal codebase and found it useful specifically for that.