-
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
CA1416 Fix Version comparison ambiguity #4943
CA1416 Fix Version comparison ambiguity #4943
Conversation
Codecov Report
@@ Coverage Diff @@
## release/6.0.1xx-preview3 #4943 +/- ##
==========================================================
Coverage 95.57% 95.57%
==========================================================
Files 1175 1176 +1
Lines 269300 269402 +102
Branches 16314 16323 +9
==========================================================
+ Hits 257377 257494 +117
+ Misses 9804 9787 -17
- Partials 2119 2121 +2 |
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 are still few comparisons left:
Line 724 in 6628ba6
if (supportedVersion > unsupportedVersion) |
Line 727 in 6628ba6
csAttribute.UnsupportedFirst != null && csAttribute.UnsupportedFirst > supportedVersion)) |
Line 801 in 6628ba6
else if (supportedVersion > csAttribute.UnsupportedFirst) |
Line 823 in 6628ba6
if (unsupportedVersion != null && unsupportedVersion > supportedVersion) |
Line 1159 in 6628ba6
if (attribute.UnsupportedFirst == null || attribute.UnsupportedFirst > attribute.SupportedFirst) |
(and few more)
Was that intended?
...tAnalyzers/Core/Microsoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzer.cs
Show resolved
Hide resolved
...tAnalyzers/Core/Microsoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzer.cs
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.
Is there a way to ban the comparison operators for Version
?
Yes the comparisons with
That should be runtime related question, anyway, i don't think so because I heard there was a long discussion (idk when/where though) about the Version comparisons and if this behavior is correct or should be fixed etc, and ended up not fixing. I guess it didn't fix it because the existing behavior was made sense for some other scenarios |
I meant using the BannedApiAnalyzer to warn if we use @mavasani @Evangelink Do you know whether BannedApiAnalyzer supports this? |
Yes, we can ban usage of specific APIs in NetAnalyzers projects by adding the documentation comment IDs of the APIs to https://github.com/dotnet/roslyn-analyzers/blob/dc515b0412abf13d9d2b8e34543c61c9abbee87b/src/NetAnalyzers/BannedSymbols.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.
@buyaa-n I left a couple of questions.
Can you please address @Youssef1313 's question about the other comparisons that were not modified?
Also, let's try to explore the suggestion to ban <=
and >=
for Version
instances. Maybe we can find a way to ban them only inside the PlatformCompatibilityAnalyzer
class.
...ft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzerTests.GuardedCallsTests.cs
Show resolved
Hide resolved
That question is answered here, in short,
From what I have seen and what @mavasani answered seems we cannot do that for only |
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.
LGTM. All questions answered.
Followed up with @mavasani, we cannot ban version comparison only for PlatformCompatibilityAnalyzer, i don't think we should ban Version comparison in the entire project, so gonna merge the PR |
Fixes #4932
The comparison operations of the Version type is a bit strange:
Because of that now
[SupportedOSPlatform("windows10.0.17763.0")]
is not equal to[SupportedOSPlatform("windows10.0.17763")]
becauseVersion.Revision
will be defaulted to-1
.Accordingly API with
[SupportedOSPlatform("windows10.0.17763.0")]
attribute cannot be guarded withOperatingSystem.IsWindowsVersionAtLeast(10, 0, 17763)
Added extension method for version comparison