Skip to content

Commit

Permalink
SONARJAVA-4327 Improve rule description, add Java exception (#1533)
Browse files Browse the repository at this point in the history
  • Loading branch information
johann-beleites-sonarsource authored Feb 6, 2023
1 parent d0ea589 commit ff343a5
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 14 deletions.
10 changes: 10 additions & 0 deletions rules/S3937/compliant.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
== Compliant Solution

[source,text]
----
int thousand = 1000;
int tenThousand = 10_000;
int tenThousandWithout = 10000;
int duos = 1_00_00;
int million = 100_000_000;
----
4 changes: 4 additions & 0 deletions rules/S3937/csharp/rule.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
include::../rule.adoc[]

include::../noncompliant.adoc[]

include::../compliant.adoc[]

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

'''
Expand Down
9 changes: 9 additions & 0 deletions rules/S3937/java/exceptions.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
== Exceptions

No issue will be raised on binary numbers (starting with `0b` or `0B`). Binary number bits are often grouped corresponding to certain meanings, resulting in irregular bit group sizes.

[source,java]
----
int configValue1 = 0b00_000_10_1; // Compliant
int configValue2 = 0B00_000_10_1; // Compliant
----
7 changes: 7 additions & 0 deletions rules/S3937/java/rule.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
include::../rule.adoc[]

include::../noncompliant.adoc[]

include::../compliant.adoc[]

include::exceptions.adoc[]


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

'''
Expand Down
8 changes: 8 additions & 0 deletions rules/S3937/noncompliant.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
== Noncompliant Code Example

[source,text]
----
int thousand = 100_0
int tenThousand = 100_00;
int million = 1_000_00_000;
----
15 changes: 1 addition & 14 deletions rules/S3937/rule.adoc
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
The use of punctuation characters to separate subgroups in a number can make the number more readable. For instance consider 1,000,000,000 versus 1000000000. But when the grouping is irregular, such as 1,000,00,000; it indicates an error.
The use of punctuation characters to separate subgroups in a number can make the number more readable. For instance consider 1,000,000,000 versus 1000000000. But when the grouping is irregular, such as 1,000,00,000; it indicates an error.


This rule raises an issue when underscores (``++_++``) are used to break a number into irregular subgroups.


== Noncompliant Code Example

[source,text]
----
int duos = 1_00_00;
int million = 1_000_00_000; // Noncompliant
int thousand = 1000;
int tenThousand = 100_00; // Noncompliant
----


0 comments on commit ff343a5

Please sign in to comment.