Skip to content

Commit b40c64f

Browse files
SONARJAVA-4499 Update rules metadata (#4392)
* SONARJAVA-4499 Update rules metadata, rename sections * SONARJAVA-4499 Update rules metadata, deprecated rules * SONARJAVA-4499 Update rules metadata, "See Also" sections * SONARJAVA-4499 S2384 description updated to match the implementation * SONARJAVA-4499 Fix S2755 rule description invalid section * SONARJAVA-4499 Migrate S3981 rule description to the educational format
1 parent 48fa169 commit b40c64f

File tree

588 files changed

+1944
-1364
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

588 files changed

+1944
-1364
lines changed

java-checks/src/main/resources/org/sonar/l10n/java/rules/java/S100.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
<h2>Why is this an issue?</h2>
12
<p>Shared naming conventions allow teams to collaborate efficiently. This rule checks that all method names match a provided regular expression.</p>
2-
<h2>Noncompliant Code Example</h2>
3+
<h3>Noncompliant code example</h3>
34
<p>With default provided regular expression <code>^[a-z][a-zA-Z0-9]*$</code>:</p>
45
<pre>
56
public int DoSomething(){...}
67
</pre>
7-
<h2>Compliant Solution</h2>
8+
<h3>Compliant solution</h3>
89
<pre>
910
public int doSomething(){...}
1011
</pre>
11-
<h2>Exceptions</h2>
12+
<h3>Exceptions</h3>
1213
<p>Overriding methods are excluded.</p>
1314
<pre>
1415
@Override

java-checks/src/main/resources/org/sonar/l10n/java/rules/java/S101.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
<h2>Why is this an issue?</h2>
12
<p>Shared coding conventions allow teams to collaborate effectively. This rule allows to check that all class names match a provided regular
23
expression.</p>
3-
<h2>Noncompliant Code Example</h2>
4+
<h3>Noncompliant code example</h3>
45
<p>With default provided regular expression <code>^[A-Z][a-zA-Z0-9]*$</code>:</p>
56
<pre>
67
class my_class {...}
78
</pre>
8-
<h2>Compliant Solution</h2>
9+
<h3>Compliant solution</h3>
910
<pre>
1011
class MyClass {...}
1112
</pre>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
<h2>Why is this an issue?</h2>
12
<p>Having to scroll horizontally makes it harder to get a quick overview and understanding of any piece of code.</p>
23

java-checks/src/main/resources/org/sonar/l10n/java/rules/java/S104.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<h2>Why is this an issue?</h2>
12
<p>A source file that grows too much tends to aggregate too many responsibilities and inevitably becomes harder to understand and therefore to
23
maintain. Above a specific threshold, it is strongly advised to refactor it into smaller pieces of code which focus on well defined tasks. Those
34
smaller files will not only be easier to understand but also probably easier to test.</p>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<h2>Why is this an issue?</h2>
12
<p>Developers should not need to configure the tab width of their text editors in order to be able to read source code.</p>
23
<p>So the use of the tabulation character must be banned.</p>
34

java-checks/src/main/resources/org/sonar/l10n/java/rules/java/S106.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<h2>Why is this an issue?</h2>
12
<p>When logging a message there are several important requirements which must be fulfilled:</p>
23
<ul>
34
<li> The user must be able to easily retrieve the logs </li>
@@ -7,15 +8,15 @@
78
</ul>
89
<p>If a program directly writes to the standard outputs, there is absolutely no way to comply with those requirements. That’s why defining and using a
910
dedicated logger is highly recommended.</p>
10-
<h2>Noncompliant Code Example</h2>
11+
<h3>Noncompliant code example</h3>
1112
<pre>
1213
System.out.println("My Message"); // Noncompliant
1314
</pre>
14-
<h2>Compliant Solution</h2>
15+
<h3>Compliant solution</h3>
1516
<pre>
1617
logger.log("My Message");
1718
</pre>
18-
<h2>See</h2>
19+
<h2>Resources</h2>
1920
<ul>
2021
<li> <a href="https://owasp.org/Top10/A09_2021-Security_Logging_and_Monitoring_Failures/">OWASP Top 10 2021 Category A9</a> - Security Logging and
2122
Monitoring Failures </li>

java-checks/src/main/resources/org/sonar/l10n/java/rules/java/S1065.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
<h2>Why is this an issue?</h2>
12
<p>If a label is declared but not used in the program, it can be considered as dead code and should therefore be removed.</p>
23
<p>This will improve maintainability as developers will not wonder what this label is used for.</p>
3-
<h2>Noncompliant Code Example</h2>
4+
<h3>Noncompliant code example</h3>
45
<pre>
56
void foo() {
67
outer: //label is not used.
@@ -9,15 +10,15 @@ <h2>Noncompliant Code Example</h2>
910
}
1011
}
1112
</pre>
12-
<h2>Compliant Solution</h2>
13+
<h3>Compliant solution</h3>
1314
<pre>
1415
void foo() {
1516
for(int i = 0; i&lt;10; i++) {
1617
break;
1718
}
1819
}
1920
</pre>
20-
<h2>See</h2>
21+
<h2>Resources</h2>
2122
<ul>
2223
<li> <a href="https://wiki.sei.cmu.edu/confluence/x/5dUxBQ">CERT, MSC12-C.</a> - Detect and remove code that has no effect or is never executed
2324
</li>

java-checks/src/main/resources/org/sonar/l10n/java/rules/java/S1066.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
<h2>Why is this an issue?</h2>
12
<p>Merging collapsible <code>if</code> statements increases the code’s readability.</p>
2-
<h2>Noncompliant Code Example</h2>
3+
<h3>Noncompliant code example</h3>
34
<pre>
45
if (file != null) {
56
if (file.isFile() || file.isDirectory()) {
67
/* ... */
78
}
89
}
910
</pre>
10-
<h2>Compliant Solution</h2>
11+
<h3>Compliant solution</h3>
1112
<pre>
1213
if (file != null &amp;&amp; isFileOrDirectory(file)) {
1314
/* ... */
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
<h2>Why is this an issue?</h2>
12
<p>The complexity of an expression is defined by the number of <code>&amp;&amp;</code>, <code>||</code> and <code>condition ? ifTrue : ifFalse</code>
23
operators it contains.</p>
34
<p>A single expression’s complexity should not become too high to keep the code readable.</p>
4-
<h2>Noncompliant Code Example</h2>
5+
<h3>Noncompliant code example</h3>
56
<p>With the default threshold value of 3:</p>
67
<pre>
78
if (((condition1 &amp;&amp; condition2) || (condition3 &amp;&amp; condition4)) &amp;&amp; condition5) { ... }
89
</pre>
9-
<h2>Compliant Solution</h2>
10+
<h3>Compliant solution</h3>
1011
<pre>
1112
if ( (myFirstCondition() || mySecondCondition()) &amp;&amp; myLastCondition()) { ... }
1213
</pre>
13-
<h2>Exceptions</h2>
14+
<h3>Exceptions</h3>
1415
<p>No issue is reported inside <code>equals</code> methods, because it is common to compare all the fields of a class for equality inside this kind of
1516
method.</p>
1617

java-checks/src/main/resources/org/sonar/l10n/java/rules/java/S1068.html

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
<h2>Why is this an issue?</h2>
12
<p>If a <code>private</code> field is declared but not used in the program, it can be considered dead code and should therefore be removed. This will
23
improve maintainability because developers will not wonder what the variable is used for.</p>
34
<p>Note that this rule does not take reflection into account, which means that issues will be raised on <code>private</code> fields that are only
45
accessed using the reflection API.</p>
5-
<h2>Noncompliant Code Example</h2>
6+
<h3>Noncompliant code example</h3>
67
<pre>
78
public class MyClass {
89
private int foo = 42;
@@ -13,22 +14,19 @@ <h2>Noncompliant Code Example</h2>
1314

1415
}
1516
</pre>
16-
<h2>Compliant Solution</h2>
17+
<h3>Compliant solution</h3>
1718
<pre>
1819
public class MyClass {
1920
public int compute(int a) {
2021
return a * 42;
2122
}
2223
}
2324
</pre>
24-
<h2>Exceptions</h2>
25+
<h3>Exceptions</h3>
2526
<p>The rule admits 3 exceptions:</p>
2627
<ul>
2728
<li> Serialization id fields </li>
28-
<li> Annotated fields </li>
29-
<li> Fields from classes with native methods </li>
3029
</ul>
31-
<h3>Serialization id fields</h3>
3230
<p>The Java serialization runtime associates with each serializable class a version number, called <code>serialVersionUID</code>, which is used during
3331
deserialization to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible with respect to
3432
serialization.</p>
@@ -39,15 +37,19 @@ <h3>Serialization id fields</h3>
3937
private static final long serialVersionUID = 42L;
4038
}
4139
</pre>
42-
<h3>Annotated fields</h3>
40+
<ul>
41+
<li> Annotated fields </li>
42+
</ul>
4343
<p>The unused field in this class will not be reported by the rule as it is annotated.</p>
4444
<pre>
4545
public class MyClass {
4646
@SomeAnnotation
4747
private int unused;
4848
}
4949
</pre>
50-
<h3>Fields from classes with native methods</h3>
50+
<ul>
51+
<li> Fields from classes with native methods </li>
52+
</ul>
5153
<p>The unused field in this class will not be reported by the rule as it might be used by native code.</p>
5254
<pre>
5355
public class MyClass {

0 commit comments

Comments
 (0)