-
Notifications
You must be signed in to change notification settings - Fork 468
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
New Analyzer: Warn when calling Enumerable.Cast<T>/OfType<T> with incompatible types #4328
Conversation
...zers/Core/Microsoft.NetCore.Analyzers/Runtime/DoNotCallEnumerableCastThatWillFailAnalyzer.cs
Outdated
Show resolved
Hide resolved
...zers/Core/Microsoft.NetCore.Analyzers/Runtime/DoNotCallEnumerableCastThatWillFailAnalyzer.cs
Outdated
Show resolved
Hide resolved
That should be all the warnings resolved except for the rule id. Not sure how those are are assigned. |
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/MicrosoftNetCoreAnalyzersResources.resx
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/MicrosoftNetCoreAnalyzersResources.resx
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/MicrosoftNetCoreAnalyzersResources.resx
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/MicrosoftNetCoreAnalyzersResources.resx
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/MicrosoftNetCoreAnalyzersResources.resx
Outdated
Show resolved
Hide resolved
...ests/Microsoft.NetCore.Analyzers/Runtime/DoNotCallEnumerableCastThatWillFailAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
...ests/Microsoft.NetCore.Analyzers/Runtime/DoNotCallEnumerableCastThatWillFailAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
...ests/Microsoft.NetCore.Analyzers/Runtime/DoNotCallEnumerableCastThatWillFailAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
...zers/Core/Microsoft.NetCore.Analyzers/Runtime/DoNotCallEnumerableCastThatWillFailAnalyzer.cs
Outdated
Show resolved
Hide resolved
...ests/Microsoft.NetCore.Analyzers/Runtime/DoNotCallEnumerableCastThatWillFailAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/MicrosoftNetCoreAnalyzersResources.resx
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/MicrosoftNetCoreAnalyzersResources.resx
Outdated
Show resolved
Hide resolved
3714416
to
4aacc97
Compare
...zers/Core/Microsoft.NetCore.Analyzers/Runtime/DoNotCallEnumerableCastThatWillFailAnalyzer.cs
Outdated
Show resolved
Hide resolved
...zers/Core/Microsoft.NetCore.Analyzers/Runtime/DoNotCallEnumerableCastThatWillFailAnalyzer.cs
Outdated
Show resolved
Hide resolved
...zers/Core/Microsoft.NetCore.Analyzers/Runtime/DoNotCallEnumerableCastThatWillFailAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/MicrosoftNetCoreAnalyzersResources.resx
Outdated
Show resolved
Hide resolved
...zers/Core/Microsoft.NetCore.Analyzers/Runtime/DoNotCallEnumerableCastThatWillFailAnalyzer.cs
Outdated
Show resolved
Hide resolved
...zers/Core/Microsoft.NetCore.Analyzers/Runtime/DoNotCallEnumerableCastThatWillFailAnalyzer.cs
Outdated
Show resolved
Hide resolved
...zers/Core/Microsoft.NetCore.Analyzers/Runtime/DoNotCallEnumerableCastThatWillFailAnalyzer.cs
Outdated
Show resolved
Hide resolved
...zers/Core/Microsoft.NetCore.Analyzers/Runtime/DoNotCallEnumerableCastThatWillFailAnalyzer.cs
Outdated
Show resolved
Hide resolved
...ests/Microsoft.NetCore.Analyzers/Runtime/DoNotCallEnumerableCastThatWillFailAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
...ests/Microsoft.NetCore.Analyzers/Runtime/DoNotCallEnumerableCastThatWillFailAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
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.
@fowl2 The analyzer proposal has not yet been approved, please wait until the proposal goes through API review
The proposal has been approved so we can unblock the PR, @buyaa-n |
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.
Overall looks good @fowl2 thank you for your contribution, added few comment, and seems we could add some more unit tests.
Not sure if you read our Definition of done list, it would be great if you could try testing the new analyzer with runtime repo, please let us know if you would like to give it a try
...zers/Core/Microsoft.NetCore.Analyzers/Runtime/DoNotCallEnumerableCastThatWillFailAnalyzer.cs
Outdated
Show resolved
Hide resolved
...zers/Core/Microsoft.NetCore.Analyzers/Runtime/DoNotCallEnumerableCastThatWillFailAnalyzer.cs
Outdated
Show resolved
Hide resolved
...zers/Core/Microsoft.NetCore.Analyzers/Runtime/DoNotCallEnumerableCastThatWillFailAnalyzer.cs
Outdated
Show resolved
Hide resolved
...ests/Microsoft.NetCore.Analyzers/Runtime/DoNotCallEnumerableCastThatWillFailAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
...zers/Core/Microsoft.NetCore.Analyzers/Runtime/DoNotCallEnumerableCastThatWillFailAnalyzer.cs
Outdated
Show resolved
Hide resolved
...zers/Core/Microsoft.NetCore.Analyzers/Runtime/DoNotCallEnumerableCastThatWillFailAnalyzer.cs
Outdated
Show resolved
Hide resolved
...zers/Core/Microsoft.NetCore.Analyzers/Runtime/DoNotCallEnumerableCastThatWillFailAnalyzer.cs
Outdated
Show resolved
Hide resolved
Please retarget this PR to https://github.com/dotnet/roslyn-analyzers/tree/release/6.0.1xx-preview1 |
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.
Please retarget this PR to https://github.com/dotnet/roslyn-analyzers/tree/release/6.0.1xx-preview1
@fowl2 could you address the comments? Do you need a help with anything? Also please retarget to https://github.com/dotnet/roslyn-analyzers/tree/release/6.0.1xx |
@buyaa-n sorry I haven't had time to look at this - looks like I'll have some spare time this week to get back to you |
@fowl2 could you give us an update? It would be great to have this analyzer. Do you expect to have more time? |
ping @fowl2 again, are you planning to work on it? |
Can you try the instructions here? |
Yes that's what I was trying. See my previous comment :) |
Sorry for the late reply @fowl2, apparently the repo's dogfooding analyzer is updated
The current version is roslyn-analyzers/eng/Versions.props Line 49 in 92d7d36
So you can use/copy DLLs from |
9c692d5
to
e8942ab
Compare
done:
to be:
|
…ith incompatible types
I've rebased to main, changed to new diagnostic ID (again) and updated to the new Ran out of time/cpu again trying to run it against |
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.
Ran out of time/cpu again trying to run it against runtime and rosyln, could I ask someone else have a go to help get this over the line? :)
Tested with runtime looks good and no diagnostic found, thank you. We can skip testing with roslyn.
Overall looks great to me, left a few questions
Warn if use of
Enumerable.Cast<T>
would always fail at runtime orOfType<T>()
would provably result in an empty sequence, because we can see that the input type in the sequence will never be the specified type.RuleId: CA2021
Category: Reliability
related: #3608, dotnet/runtime#33770
release/7.0.1xxmain