Skip to content

Commit

Permalink
S2198: Add C# (#1534)
Browse files Browse the repository at this point in the history
* Change description and add some comments

* Update the description of what the C# implementation actually does for now

* Fix a typo

* Small formatting change on S2198

* Small formatting changes on S2198

* Small formatting change on S2198
  • Loading branch information
gregory-paidis-sonarsource committed Feb 15, 2023
1 parent a8b5a83 commit 972f4dc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
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

0 comments on commit 972f4dc

Please sign in to comment.