Skip to content

Commit efbcbb6

Browse files
committed
fixed adoc structure to match template, addressed pr comments
1 parent 654cc0c commit efbcbb6

File tree

2 files changed

+6
-30
lines changed

2 files changed

+6
-30
lines changed

rules/S8346/java/metadata.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
"sqKey": "S8346",
1414
"scope": "All",
1515
"defaultQualityProfiles": ["Sonar way"],
16-
"quickfix": "partial",
16+
"quickfix": "targeted",
1717
"code": {
1818
"impacts": {
1919
"MAINTAINABILITY": "HIGH",
20-
"RELIABILITY": "MEDIUM",
21-
"SECURITY": "LOW"
20+
"RELIABILITY": "MEDIUM"
2221
},
2322
"attribute": "CONVENTIONAL"
2423
}

rules/S8346/java/rule.adoc

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
[#floating-point-inc-dec, severity=major, tags=maintainability,pitfall,floating-point]
2-
=== Increment and decrement operators shouldn't be used with floating-point variables
1+
This rule raise an issue when increment (`{plus}{plus}`) or decrement (`--`) operators are used with floating-point variables.
2+
3+
== Why is this an issue?
34

45
Increment and decrement operators (`{plus}{plus}` and `--`) shouldn't be used with floating-point variables (like `float` or `double`).
56
While the language allows it, the usage is not idiomatic, and most developers intuitively expect `x{plus}{plus}` to apply to integer types.
67
Using it on a float violates this common expectation and can lead to misleading code.
78

8-
9-
10-
11-
// If you want to factorize the description uncomment the following line and create the file.
12-
//include::../description.adoc[]
13-
14-
== Why is this an issue?
9+
=== What is the potential impact?
1510

1611
Floating-point arithmetic has some non-intuitive properties, which can lead to unexpected bugs.
1712
For example, the following loop will not terminate:
@@ -26,7 +21,6 @@ for (float x = 16_000_000; x < 17_000_000; x++) {
2621

2722
This happens because `float` has only 24 bits of precision (mantissa) and once a number gets large enough, adding `1.0` becomes insignificant.
2823
The increment operation effectively does nothing.
29-
3024
The problem would not occur if `int` is used instead of `float`, even though both types occupy 32 bits:
3125

3226
[source,java]
@@ -40,13 +34,11 @@ for (int x = 16_000_000; x < 17_000_000; x++) {
4034
Using the compound assignment operators (`{plus}=` and `-=`) makes the intent clearer and avoids the surprising use of `{plus}{plus}` and `--` on floating-point types.
4135

4236
== How to fix it
43-
//== How to fix it in FRAMEWORK NAME
4437

4538
=== Code examples
4639

4740
==== Noncompliant code example
4841

49-
5042
[source,java]
5143
----
5244
float x = 0f;
@@ -66,18 +58,3 @@ double y = 1.0;
6658
x += 1.0;
6759
y -= 1.0;
6860
----
69-
70-
//=== How does this work?
71-
72-
//=== Pitfalls
73-
74-
//=== Going the extra mile
75-
76-
77-
//== Resources
78-
//=== Documentation
79-
//=== Articles & blog posts
80-
//=== Conference presentations
81-
//=== Standards
82-
//=== External coding guidelines
83-
//=== Benchmarks

0 commit comments

Comments
 (0)