From e73f3b3a40e8907cdeac8f0c48325dc6907054eb Mon Sep 17 00:00:00 2001 From: Gregory Paidis Date: Tue, 31 Jan 2023 16:02:34 +0100 Subject: [PATCH 1/6] Change description and add some comments --- rules/S2198/csharp/comments-and-links.adoc | 3 +++ rules/S2198/csharp/rule.adoc | 29 ++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 rules/S2198/csharp/comments-and-links.adoc diff --git a/rules/S2198/csharp/comments-and-links.adoc b/rules/S2198/csharp/comments-and-links.adoc new file mode 100644 index 00000000000..fd842728f7a --- /dev/null +++ b/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. \ No newline at end of file diff --git a/rules/S2198/csharp/rule.adoc b/rules/S2198/csharp/rule.adoc index 79d6542388c..89b817381b4 100644 --- a/rules/S2198/csharp/rule.adoc +++ b/rules/S2198/csharp/rule.adoc @@ -1,4 +1,25 @@ -include::../rule.adoc[] +Certain mathematical comparisons will always return the same value, and should simply not be made. + +This comparison will always return ``++false++``: + +* comparing a ``++float++`` with a ``++double++`` constant that's outside the ``++float++`` range + +These will always return ``++true++``: + +* comparing ``++aByte <= Byte.MaxValue++`` and ``++aByte >= Byte.MinValue++`` +* comparing ``++anInt <= int.MaxValue++`` and ``++anInt >= int.MinValue++`` +* comparing ``++aLong <= long.MaxValue++`` and ``++aLong >= long.MinValue++`` + + +== Noncompliant Code Example + +[source,text] +---- +float f = 42.0f; +const double d = float.MaxValue + 1; +if (f <= d) { } // Noncompliant +---- + ifdef::env-github,rspecator-view[] ''' @@ -7,4 +28,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[] \ No newline at end of file From 551bf66a6674d5d1acbf2697e9fb21746995bd2d Mon Sep 17 00:00:00 2001 From: Gregory Paidis Date: Wed, 8 Feb 2023 15:58:45 +0100 Subject: [PATCH 2/6] Update the description of what the C# implementation actually does for now --- rules/S2198/csharp/rule.adoc | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/rules/S2198/csharp/rule.adoc b/rules/S2198/csharp/rule.adoc index 89b817381b4..94948373a45 100644 --- a/rules/S2198/csharp/rule.adoc +++ b/rules/S2198/csharp/rule.adoc @@ -1,22 +1,18 @@ Certain mathematical comparisons will always return the same value, and should simply not be made. -This comparison will always return ``++false++``: - -* comparing a ``++float++`` with a ``++double++`` constant that's outside the ``++float++`` range - -These will always return ``++true++``: - -* comparing ``++aByte <= Byte.MaxValue++`` and ``++aByte >= Byte.MinValue++`` -* comparing ``++anInt <= int.MaxValue++`` and ``++anInt >= int.MinValue++`` -* comparing ``++aLong <= long.MaxValue++`` and ``++aLong >= long.MinValue++`` +These comparisons will always return ``++false++``: +* comparing a ``++char++`` with a numeric constant that's outside the ``++char++`` range +* comparing a ``++float++`` with a numeric constant that's outside the ``++float++`` range +* comparing a ``++long++`` with a numeric constant that's outside the ``++long++`` range +* comparing a ``++ulong++`` with a numeric constant that's outside the ``++ulong++`` range == Noncompliant Code Example [source,text] ---- float f = 42.0f; -const double d = float.MaxValue + 1; +const double d = double.MaxValue; if (f <= d) { } // Noncompliant ---- From ca0aee31f931159d1dca250469b40552c78c7753 Mon Sep 17 00:00:00 2001 From: Gregory Paidis Date: Wed, 8 Feb 2023 16:01:33 +0100 Subject: [PATCH 3/6] Fix a typo --- rules/S2198/rule.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/S2198/rule.adoc b/rules/S2198/rule.adoc index f96a2f620b0..33f65d75fb5 100644 --- a/rules/S2198/rule.adoc +++ b/rules/S2198/rule.adoc @@ -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 From 1a274cfda40df1a307028e175790971b180d0536 Mon Sep 17 00:00:00 2001 From: Gregory Paidis Date: Wed, 15 Feb 2023 10:25:44 +0100 Subject: [PATCH 4/6] Small formatting change on S2198 --- rules/S2198/csharp/rule.adoc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rules/S2198/csharp/rule.adoc b/rules/S2198/csharp/rule.adoc index 94948373a45..0c645c8728a 100644 --- a/rules/S2198/csharp/rule.adoc +++ b/rules/S2198/csharp/rule.adoc @@ -2,10 +2,10 @@ Certain mathematical comparisons will always return the same value, and should s These comparisons will always return ``++false++``: -* comparing a ``++char++`` with a numeric constant that's outside the ``++char++`` range -* comparing a ``++float++`` with a numeric constant that's outside the ``++float++`` range -* comparing a ``++long++`` with a numeric constant that's outside the ``++long++`` range -* comparing a ``++ulong++`` with a numeric constant that's outside the ``++ulong++`` range +* comparing a `char` with a numeric constant that's outside the `char` range +* comparing a `float` with a numeric constant that's outside the `float` range +* comparing a `long` with a numeric constant that's outside the `long` range +* comparing a `ulong` with a numeric constant that's outside the `ulong` range == Noncompliant Code Example From 847189ba49f2e10f12a49a1bac0a7ce604d5247c Mon Sep 17 00:00:00 2001 From: Gregory Paidis Date: Wed, 15 Feb 2023 11:55:39 +0100 Subject: [PATCH 5/6] Small formatting changes on S2198 --- rules/S2198/csharp/rule.adoc | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/rules/S2198/csharp/rule.adoc b/rules/S2198/csharp/rule.adoc index 0c645c8728a..201a15ee05a 100644 --- a/rules/S2198/csharp/rule.adoc +++ b/rules/S2198/csharp/rule.adoc @@ -1,19 +1,18 @@ Certain mathematical comparisons will always return the same value, and should simply not be made. -These comparisons will always return ``++false++``: +These comparisons will always return `false`: -* comparing a `char` with a numeric constant that's outside the `char` range -* comparing a `float` with a numeric constant that's outside the `float` range -* comparing a `long` with a numeric constant that's outside the `long` range -* comparing a `ulong` with a numeric constant that's outside the `ulong` range +* 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; -const double d = double.MaxValue; -if (f <= d) { } // Noncompliant +if (f <= double.MaxValue) { } // Noncompliant ---- ifdef::env-github,rspecator-view[] From 40f7740a57d32d70c51d057041ad1669b2365b38 Mon Sep 17 00:00:00 2001 From: Gregory Paidis Date: Wed, 15 Feb 2023 13:39:31 +0100 Subject: [PATCH 6/6] Small formatting change on S2198 --- rules/S2198/csharp/rule.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/S2198/csharp/rule.adoc b/rules/S2198/csharp/rule.adoc index 201a15ee05a..e7708f030e5 100644 --- a/rules/S2198/csharp/rule.adoc +++ b/rules/S2198/csharp/rule.adoc @@ -1,6 +1,6 @@ Certain mathematical comparisons will always return the same value, and should simply not be made. -These comparisons will always return `false`: +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`.