-
Notifications
You must be signed in to change notification settings - Fork 688
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONARJAVA-4661 Update Rules Metadata (#4496)
A batch of updates from the LaYC update
- Loading branch information
Showing
58 changed files
with
734 additions
and
444 deletions.
There are no files selected for viewing
29 changes: 17 additions & 12 deletions
29
java-checks/src/main/resources/org/sonar/l10n/java/rules/java/S106.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 25 additions & 5 deletions
30
java-checks/src/main/resources/org/sonar/l10n/java/rules/java/S1066.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
java-checks/src/main/resources/org/sonar/l10n/java/rules/java/S1066.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 13 additions & 13 deletions
26
java-checks/src/main/resources/org/sonar/l10n/java/rules/java/S1110.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
<h2>Why is this an issue?</h2> | ||
<p>The use of parentheses, even those not required to enforce a desired order of operations, can clarify the intent behind a piece of code. But | ||
redundant pairs of parentheses could be misleading, and should be removed.</p> | ||
<h3>Noncompliant code example</h3> | ||
<p>Parentheses can disambiguate the order of operations in complex expressions and make the code easier to understand.</p> | ||
<pre> | ||
int x = (y / 2 + 1); //Compliant even if the parenthesis are ignored by the compiler | ||
a = (b * c) + (d * e); // Compliant: the intent is clear. | ||
</pre> | ||
<p>Redundant parentheses are parenthesis that do not change the behavior of the code, and do not clarify the intent. They can mislead and complexify | ||
the code. They should be removed.</p> | ||
<h3>Noncompliant code example</h3> | ||
<pre data-diff-id="1" data-diff-type="noncompliant"> | ||
int x = ((y / 2 + 1)); // Noncompliant | ||
|
||
if (a && ((x+y > 0))) { // Noncompliant | ||
//... | ||
if (a && ((x + y > 0))) { // Noncompliant | ||
return ((x + 1)); // Noncompliant | ||
} | ||
|
||
return ((x + 1)); // Noncompliant | ||
</pre> | ||
<h3>Compliant solution</h3> | ||
<pre> | ||
<pre data-diff-id="1" data-diff-type="compliant"> | ||
int x = (y / 2 + 1); | ||
|
||
if (a && (x+y > 0)) { | ||
//... | ||
if (a && (x + y > 0)) { | ||
return (x + 1); | ||
} | ||
|
||
return (x + 1); | ||
</pre> | ||
|
30 changes: 15 additions & 15 deletions
30
java-checks/src/main/resources/org/sonar/l10n/java/rules/java/S1116.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 21 additions & 7 deletions
28
java-checks/src/main/resources/org/sonar/l10n/java/rules/java/S1117.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,36 @@ | ||
<h2>Why is this an issue?</h2> | ||
<p>Overriding or shadowing a variable declared in an outer scope can strongly impact the readability, and therefore the maintainability, of a piece of | ||
code. Further, it could lead maintainers to introduce bugs because they think they’re using one variable but are really using another.</p> | ||
<p>Shadowing occurs when a local variable has the same name as a variable or a field in an outer scope.</p> | ||
<p>This can lead to three main problems:</p> | ||
<ul> | ||
<li> Confusion: The same name can refer to different variables in different parts of the scope, making the code hard to read and understand. </li> | ||
<li> Unintended Behavior: You might accidentally use the wrong variable, leading to hard-to-detect bugs. </li> | ||
<li> Maintenance Issues: If the inner variable is removed or renamed, the code’s behavior might change unexpectedly because the outer variable is | ||
now being used. </li> | ||
</ul> | ||
<p>To avoid these problems, rename the shadowing, shadowed, or both identifiers to accurately represent their purpose with unique and meaningful | ||
names.</p> | ||
<p>This rule focuses on variables in methods that shadow a field.</p> | ||
<h3>Noncompliant code example</h3> | ||
<pre> | ||
class Foo { | ||
public int myField; | ||
|
||
public void doSomething() { | ||
int myField = 0; // Noncompliant | ||
... | ||
// ... | ||
} | ||
} | ||
</pre> | ||
<h2>Resources</h2> | ||
<h3>Documentation</h3> | ||
<ul> | ||
<li> <a href="https://wiki.sei.cmu.edu/confluence/display/c/DCL01-C.+Do+not+reuse+variable+names+in+subscopes">CERT, DCL01-C.</a> - Do not reuse | ||
variable names in subscopes </li> | ||
<li> <a href="https://wiki.sei.cmu.edu/confluence/display/java/DCL51-J.+Do+not+shadow+or+obscure+identifiers+in+subscopes">CERT, DCL51-J.</a> - Do | ||
not shadow or obscure identifiers in subscopes </li> | ||
<li> CERT - <a href="https://wiki.sei.cmu.edu/confluence/display/java/DCL51-J.+Do+not+shadow+or+obscure+identifiers+in+subscopes">DCL51-J. Do not | ||
shadow or obscure identifiers in subscopes</a> </li> | ||
</ul> | ||
<h3>Related rules</h3> | ||
<ul> | ||
<li> {rule:java:S2176} - Class names should not shadow interfaces or superclasses </li> | ||
<li> {rule:java:S2387} - Child class fields should not shadow parent class fields </li> | ||
<li> {rule:java:S4977} - Type parameters should not shadow other type parameters </li> | ||
</ul> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.