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

Mosify rule S2198: Add C# #1534

Merged
merged 6 commits into from Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions rules/S2198/csharp/comments-and-links.adoc
@@ -0,0 +1,3 @@
=== on 31 Jan 2023, 15:54:54 Grigorios Paidis wrote:

The rule is complementary to https://learn.microsoft.com/en-us/dotnet/csharp/misc/cs0652?f1url=%3FappId%3Droslyn%26k%3Dk(CS0652)[CS0652]. Thus, it only extends the functionality of this Compiler Warning.
24 changes: 22 additions & 2 deletions rules/S2198/csharp/rule.adoc
@@ -1,4 +1,20 @@
include::../rule.adoc[]
Certain mathematical comparisons will always return the same value, and should simply not be made.

These comparisons will return either always `true` or always `false` depending on the kind of comparison:

* Comparing a `char` with a numeric constant that is outside of the range of `char`.
* Comparing a `float` with a numeric constant that is outside of the range of `float`.
* Comparing a `long` with a numeric constant that is outside of the range of `long`.
* Comparing a `ulong` with a numeric constant that is outside of the range of `ulong`.

== Noncompliant Code Example

[source,text]
----
float f = 42.0f;
if (f <= double.MaxValue) { } // Noncompliant
----

ifdef::env-github,rspecator-view[]

'''
Expand All @@ -7,4 +23,8 @@ ifdef::env-github,rspecator-view[]

include::../message.adoc[]

endif::env-github,rspecator-view[]
== Comments And Links
(visible only on this page)

include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]
2 changes: 1 addition & 1 deletion rules/S2198/rule.adoc
Expand Up @@ -13,7 +13,7 @@ These will always return ``++true++``:

* comparing ``++aByte <= Byte.MAX_VALUE++`` and ``++aByte >= Byte.MIN_VALUE++``
* comparing ``++anInt <= Integer.MAX_VALUE++`` and ``++anInt >= Integer.MIN_VALUE++``
* comparing ``++aLong <= Long.MAX_VALUE++`` and ``++aLong >= Long.MIN_VALLUE++``
* comparing ``++aLong <= Long.MAX_VALUE++`` and ``++aLong >= Long.MIN_VALUE++``


== Noncompliant Code Example
Expand Down