Skip to content

Commit e4e67bf

Browse files
SONARSCALA-119 Update rule metadata (#111)
Co-authored-by: tomasz-tylenda-sonarsource <tomasz-tylenda-sonarsource@users.noreply.github.com>
1 parent 2bd382a commit e4e67bf

File tree

18 files changed

+137
-117
lines changed

18 files changed

+137
-117
lines changed

sonar-scala-plugin/sonarpedia.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"languages": [
44
"SCALA"
55
],
6-
"latest-update": "2026-01-08T15:29:44.574249187Z",
6+
"latest-update": "2026-03-02T10:56:52.285760582Z",
77
"options": {
88
"no-language-in-filenames": true,
99
"preserve-filenames": true

sonar-scala-plugin/src/main/resources/org/sonar/l10n/scala/rules/scala/S107.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ <h2>Why is this an issue?</h2>
88
</pre>
99
<p>The solution can be to:</p>
1010
<ul>
11-
<li> Split the function into smaller ones </li>
11+
<li>Split the function into smaller ones</li>
1212
</ul>
1313
<pre>
1414
// Each function does a part of what the original setCoordinates function was doing, so confusion risks are lower
@@ -21,7 +21,7 @@ <h2>Why is this an issue?</h2>
2121
}
2222
</pre>
2323
<ul>
24-
<li> Find a better data structure for the parameters that group data in a way that makes sense for the specific application domain </li>
24+
<li>Find a better data structure for the parameters that group data in a way that makes sense for the specific application domain</li>
2525
</ul>
2626
<pre>
2727
class Point(var x: Int, var y: Int, var z: Int) { // In geometry, Point is a logical structure to group data

sonar-scala-plugin/src/main/resources/org/sonar/l10n/scala/rules/scala/S1134.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ <h2>Why is this an issue?</h2>
88
<h2>Resources</h2>
99
<h3>Documentation</h3>
1010
<ul>
11-
<li> CWE - <a href="https://cwe.mitre.org/data/definitions/546">CWE-546 - Suspicious Comment</a> </li>
11+
<li>CWE - <a href="https://cwe.mitre.org/data/definitions/546">CWE-546 - Suspicious Comment</a></li>
1212
</ul>
1313

sonar-scala-plugin/src/main/resources/org/sonar/l10n/scala/rules/scala/S1135.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ <h3>What is the potential impact?</h3>
1717
developers.</p>
1818
<h2>Resources</h2>
1919
<ul>
20-
<li> CWE - <a href="https://cwe.mitre.org/data/definitions/546">CWE-546 - Suspicious Comment</a> </li>
20+
<li>CWE - <a href="https://cwe.mitre.org/data/definitions/546">CWE-546 - Suspicious Comment</a></li>
2121
</ul>
2222

sonar-scala-plugin/src/main/resources/org/sonar/l10n/scala/rules/scala/S1144.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ <h3>Compliant solution</h3>
2222
<h3>Exceptions</h3>
2323
<p>This rule doesn’t raise issues for:</p>
2424
<ul>
25-
<li> annotated methods </li>
26-
<li> methods with parameters that are annotated with one of the following: </li>
27-
<li> <code>@javax.enterprise.event.Observes</code> </li>
28-
<li> <code>@javax.enterprise.event.ObservesAsync</code> </li>
29-
<li> <code>@jakarta.enterprise.event.Observes</code> </li>
30-
<li> <code>@jakarta.enterprise.event.ObservesAsync</code> </li>
25+
<li>annotated methods</li>
26+
<li>methods with parameters that are annotated with one of the following:</li>
27+
<li><code>@javax.enterprise.event.Observes</code></li>
28+
<li><code>@javax.enterprise.event.ObservesAsync</code></li>
29+
<li><code>@jakarta.enterprise.event.Observes</code></li>
30+
<li><code>@jakarta.enterprise.event.ObservesAsync</code></li>
3131
</ul>
3232
<p>The rule does not take reflection into account, which means that issues will be raised on <code>private</code> methods that are only accessed using
3333
the reflection API.</p>

sonar-scala-plugin/src/main/resources/org/sonar/l10n/scala/rules/scala/S1145.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ <h2>Why is this an issue?</h2>
33
statements with conditions that are always true are completely redundant, and make the code less readable.</p>
44
<p>There are three possible causes for the presence of such code:</p>
55
<ul>
6-
<li> An if statement was changed during debugging and that debug code has been committed. </li>
7-
<li> Some value was left unset. </li>
8-
<li> Some logic is not doing what the programmer thought it did. </li>
6+
<li>An if statement was changed during debugging and that debug code has been committed.</li>
7+
<li>Some value was left unset.</li>
8+
<li>Some logic is not doing what the programmer thought it did.</li>
99
</ul>
1010
<p>In any of these cases, unconditional <code>if</code> statements should be removed.</p>
1111
<h3>Noncompliant code example</h3>
@@ -25,8 +25,8 @@ <h3>Compliant solution</h3>
2525
</pre>
2626
<h2>Resources</h2>
2727
<ul>
28-
<li> CWE - <a href="https://cwe.mitre.org/data/definitions/489">CWE-489 - Active Debug Code</a> </li>
29-
<li> CWE - <a href="https://cwe.mitre.org/data/definitions/570">CWE-570 - Expression is Always False</a> </li>
30-
<li> CWE - <a href="https://cwe.mitre.org/data/definitions/571">CWE-571 - Expression is Always True</a> </li>
28+
<li>CWE - <a href="https://cwe.mitre.org/data/definitions/489">CWE-489 - Active Debug Code</a></li>
29+
<li>CWE - <a href="https://cwe.mitre.org/data/definitions/570">CWE-570 - Expression is Always False</a></li>
30+
<li>CWE - <a href="https://cwe.mitre.org/data/definitions/571">CWE-571 - Expression is Always True</a></li>
3131
</ul>
3232

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
<p>Local variables and function parameters should be named consistently to communicate intent and improve maintainability. Rename your local variable
22
or function parameter to follow your project’s naming convention to address this issue.</p>
33
<h2>Why is this an issue?</h2>
4-
<p>A naming convention in software development is a set of guidelines for naming code elements like variables, functions, and classes.<br> Local
5-
variables and function parameters hold the meaning of the written code. Their names should be meaningful and follow a consistent and easily
6-
recognizable pattern.<br> Adhering to a consistent naming convention helps to make the code more readable and understandable, which makes it easier to
7-
maintain and debug. It also ensures consistency in the code, especially when multiple developers are working on the same project.</p>
4+
<p>A naming convention in software development is a set of guidelines for naming code elements like variables, functions, and classes.
5+
<br>
6+
Local variables and function parameters hold the meaning of the written code. Their names should be meaningful and follow a consistent and easily
7+
recognizable pattern.
8+
<br>
9+
Adhering to a consistent naming convention helps to make the code more readable and understandable, which makes it easier to maintain and debug. It
10+
also ensures consistency in the code, especially when multiple developers are working on the same project.</p>
811
<p>This rule checks that local variable and function parameter names match a provided regular expression.</p>
912
<h3>What is the potential impact?</h3>
1013
<p>Inconsistent naming of local variables and function parameters can lead to several issues in your code:</p>
1114
<ul>
12-
<li> <strong>Reduced Readability</strong>: Inconsistent local variable and function parameter names make the code harder to read and understand;
13-
consequently, it is more difficult to identify the purpose of each variable, spot errors, or comprehend the logic. </li>
14-
<li> <strong>Difficulty in Identifying Variables</strong>: The local variables and function parameters that don’t adhere to a standard naming
15-
convention are challenging to identify; thus, the coding process slows down, especially when dealing with a large codebase. </li>
16-
<li> <strong>Increased Risk of Errors</strong>: Inconsistent or unclear local variable and function parameter names lead to misunderstandings about
17-
what the variable represents. This ambiguity leads to incorrect assumptions and, consequently, bugs in the code. </li>
18-
<li> <strong>Collaboration Difficulties</strong>: In a team setting, inconsistent naming conventions lead to confusion and miscommunication among
19-
team members. </li>
20-
<li> <strong>Difficulty in Code Maintenance</strong>: Inconsistent naming leads to an inconsistent codebase. The code is difficult to understand,
21-
and making changes feels like refactoring constantly, as you face different naming methods. Ultimately, it makes the codebase harder to maintain.
22-
</li>
15+
<li><strong>Reduced Readability</strong>: Inconsistent local variable and function parameter names make the code harder to read and understand;
16+
consequently, it is more difficult to identify the purpose of each variable, spot errors, or comprehend the logic.</li>
17+
<li><strong>Difficulty in Identifying Variables</strong>: The local variables and function parameters that don’t adhere to a standard naming
18+
convention are challenging to identify; thus, the coding process slows down, especially when dealing with a large codebase.</li>
19+
<li><strong>Increased Risk of Errors</strong>: Inconsistent or unclear local variable and function parameter names lead to misunderstandings about
20+
what the variable represents. This ambiguity leads to incorrect assumptions and, consequently, bugs in the code.</li>
21+
<li><strong>Collaboration Difficulties</strong>: In a team setting, inconsistent naming conventions lead to confusion and miscommunication among
22+
team members.</li>
23+
<li><strong>Difficulty in Code Maintenance</strong>: Inconsistent naming leads to an inconsistent codebase. The code is difficult to understand, and
24+
making changes feels like refactoring constantly, as you face different naming methods. Ultimately, it makes the codebase harder to maintain.</li>
2325
</ul>
2426
<p>In summary, not adhering to a naming convention for local variables and function parameters can lead to confusion, errors, and inefficiencies,
2527
making the code harder to read, understand, and maintain.</p>
@@ -45,12 +47,12 @@ <h4>Compliant solution</h4>
4547
<h2>Resources</h2>
4648
<h3>Documentation</h3>
4749
<ul>
48-
<li> Scala documentation - <a href="https://docs.scala-lang.org/style/naming-conventions.html">Style guide: naming conventions</a> </li>
49-
<li> Wikipedia - <a href="https://en.wikipedia.org/wiki/Naming_convention_(programming)">Naming Convention (programming)</a> </li>
50+
<li>Scala documentation - <a href="https://docs.scala-lang.org/style/naming-conventions.html">Style guide: naming conventions</a></li>
51+
<li>Wikipedia - <a href="https://en.wikipedia.org/wiki/Naming_convention_(programming)">Naming Convention (programming)</a></li>
5052
</ul>
5153
<h3>Related rules</h3>
5254
<ul>
53-
<li> {rule:scala:S100} - Function names should comply with a naming convention </li>
54-
<li> {rule:scala:S101} - Class names should comply with a naming convention </li>
55+
<li>{rule:scala:S100} - Function names should comply with a naming convention</li>
56+
<li>{rule:scala:S101} - Class names should comply with a naming convention</li>
5557
</ul>
5658

sonar-scala-plugin/src/main/resources/org/sonar/l10n/scala/rules/scala/S1186.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ <h2>Why is this an issue?</h2>
33
functionality and are misleading to others as they might think the method implementation fulfills a specific and identified requirement.</p>
44
<p>There are several reasons for a method not to have a body:</p>
55
<ul>
6-
<li> It is an unintentional omission, and should be fixed to prevent an unexpected behavior in production. </li>
7-
<li> It is not yet, or never will be, supported. In this case an exception should be thrown. </li>
8-
<li> The method is an intentionally-blank override. In this case a nested comment should explain the reason for the blank override. </li>
6+
<li>It is an unintentional omission, and should be fixed to prevent an unexpected behavior in production.</li>
7+
<li>It is not yet, or never will be, supported. In this case an exception should be thrown.</li>
8+
<li>The method is an intentionally-blank override. In this case a nested comment should explain the reason for the blank override.</li>
99
</ul>
1010
<h2>How to fix it</h2>
1111
<h3>Code examples</h3>

sonar-scala-plugin/src/main/resources/org/sonar/l10n/scala/rules/scala/S126.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ <h2>Why is this an issue?</h2>
44
<p>The requirement for a final <code>else</code> statement is defensive programming.</p>
55
<p>The <code>else</code> statement should either take appropriate action or contain a suitable comment as to why no action is taken. This is
66
consistent with the requirement to have a final <code>case _</code> clause in a <code>match</code>.</p>
7+
<p>In Scala, this rule also applies when an <code>if</code> statement without an <code>else</code> clause appears on the right-hand side of an
8+
assignment. Since Scala treats <code>if</code> as an expression that returns a value, omitting the <code>else</code> clause results in the assignment
9+
receiving <code>Unit</code> (represented as <code>()</code>) when the condition is false, which is typically unintended and can lead to type errors or
10+
unexpected behavior.</p>
711
<h3>Noncompliant code example</h3>
812
<pre>
913
if (x == 0) {
@@ -12,6 +16,11 @@ <h3>Noncompliant code example</h3>
1216
doSomethingElse
1317
}
1418
</pre>
19+
<pre>
20+
val result = if (x == 0) {
21+
"zero"
22+
}
23+
</pre>
1524
<h3>Compliant solution</h3>
1625
<pre>
1726
if (x == 0) {
@@ -22,6 +31,13 @@ <h3>Compliant solution</h3>
2231
throw new IllegalStateException
2332
}
2433
</pre>
34+
<pre>
35+
val result = if (x == 0) {
36+
"zero"
37+
} else {
38+
"not zero"
39+
}
40+
</pre>
2541
<h3>Exceptions</h3>
2642
<p>When all branches of an <code>if</code>-<code>else if</code> end with <code>return</code>, <code>break</code> or <code>throw</code>, the code that
2743
comes after the <code>if</code> implicitly behaves as if it was in an <code>else</code> clause. This rule will therefore ignore that case.</p>
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<p>Hardcoding IP addresses is security-sensitive. It has led in the past to the following vulnerabilities:</p>
22
<ul>
3-
<li> <a href="https://www.cve.org/CVERecord?id=CVE-2006-5901">CVE-2006-5901</a> </li>
4-
<li> <a href="https://www.cve.org/CVERecord?id=CVE-2005-3725">CVE-2005-3725</a> </li>
3+
<li><a href="https://www.cve.org/CVERecord?id=CVE-2006-5901">CVE-2006-5901</a></li>
4+
<li><a href="https://www.cve.org/CVERecord?id=CVE-2005-3725">CVE-2005-3725</a></li>
55
</ul>
66
<p>Today’s services have an ever-changing architecture due to their scaling and redundancy needs. It is a mistake to think that a service will always
77
have the same IP address. When it does change, the hardcoded IP will have to be modified too. This will have an impact on the product development,
88
delivery, and deployment:</p>
99
<ul>
10-
<li> The developers will have to do a rapid fix every time this happens, instead of having an operation team change a configuration file. </li>
11-
<li> It misleads to use the same address in every environment (dev, sys, qa, prod). </li>
10+
<li>The developers will have to do a rapid fix every time this happens, instead of having an operation team change a configuration file.</li>
11+
<li>It misleads to use the same address in every environment (dev, sys, qa, prod).</li>
1212
</ul>
1313
<p>Last but not least it has an effect on application security. Attackers might be able to decompile the code and thereby discover a potentially
1414
sensitive address. They can perform a Denial of Service attack on the service, try to get access to the system, or try to spoof the IP address to
@@ -17,8 +17,8 @@
1717
<h2>Ask Yourself Whether</h2>
1818
<p>The disclosed IP address is sensitive, e.g.:</p>
1919
<ul>
20-
<li> Can give information to an attacker about the network topology. </li>
21-
<li> It’s a personal (assigned to an identifiable person) IP address. </li>
20+
<li>Can give information to an attacker about the network topology.</li>
21+
<li>It’s a personal (assigned to an identifiable person) IP address.</li>
2222
</ul>
2323
<p>There is a risk if you answered yes to any of these questions.</p>
2424
<h2>Recommended Secure Coding Practices</h2>
@@ -38,20 +38,20 @@ <h2>Compliant Solution</h2>
3838
<h2>Exceptions</h2>
3939
<p>No issue is reported for the following cases because they are not considered sensitive:</p>
4040
<ul>
41-
<li> Loopback addresses 127.0.0.0/8 in CIDR notation (from 127.0.0.0 to 127.255.255.255) </li>
42-
<li> Broadcast address 255.255.255.255 </li>
43-
<li> Non-routable address 0.0.0.0 </li>
44-
<li> Strings of the form <code>2.5.&lt;number&gt;.&lt;number&gt;</code> as they <a href="https://en.wikipedia.org/wiki/Object_identifier">often
45-
match Object Identifiers</a> (OID) </li>
46-
<li> Addresses in the ranges 192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24, reserved for documentation purposes by <a
47-
href="https://datatracker.ietf.org/doc/html/rfc5737">RFC 5737</a> </li>
48-
<li> Addresses in the range 2001:db8::/32, reserved for documentation purposes by <a href="https://datatracker.ietf.org/doc/html/rfc3849">RFC
49-
3849</a> </li>
41+
<li>Loopback addresses 127.0.0.0/8 in CIDR notation (from 127.0.0.0 to 127.255.255.255)</li>
42+
<li>Broadcast address 255.255.255.255</li>
43+
<li>Non-routable address 0.0.0.0</li>
44+
<li>Strings of the form <code>2.5.&lt;number&gt;.&lt;number&gt;</code> as they <a href="https://en.wikipedia.org/wiki/Object_identifier">often match
45+
Object Identifiers</a> (OID)</li>
46+
<li>Addresses in the ranges 192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24, reserved for documentation purposes by <a
47+
href="https://datatracker.ietf.org/doc/html/rfc5737">RFC 5737</a></li>
48+
<li>Addresses in the range 2001:db8::/32, reserved for documentation purposes by <a href="https://datatracker.ietf.org/doc/html/rfc3849">RFC
49+
3849</a></li>
5050
</ul>
5151
<h2>See</h2>
5252
<ul>
53-
<li> OWASP - <a href="https://owasp.org/Top10/A01_2021-Broken_Access_Control/">Top 10 2021 Category A1 - Broken Access Control</a> </li>
54-
<li> OWASP - <a href="https://owasp.org/www-project-top-ten/2017/A3_2017-Sensitive_Data_Exposure">Top 10 2017 Category A3 - Sensitive Data
55-
Exposure</a> </li>
53+
<li>OWASP - <a href="https://owasp.org/Top10/A01_2021-Broken_Access_Control/">Top 10 2021 Category A1 - Broken Access Control</a></li>
54+
<li>OWASP - <a href="https://owasp.org/www-project-top-ten/2017/A3_2017-Sensitive_Data_Exposure">Top 10 2017 Category A3 - Sensitive Data
55+
Exposure</a></li>
5656
</ul>
5757

0 commit comments

Comments
 (0)