Skip to content

Commit f930b06

Browse files
authored
[NO-JIRA] Update rule metadata (#14)
1 parent f5d8e45 commit f930b06

23 files changed

+270
-82
lines changed

sonar-ruby-plugin/sonarpedia.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"languages": [
44
"RUBY"
55
],
6-
"latest-update": "2023-10-02T13:52:14.395024Z",
6+
"latest-update": "2024-09-13T13:59:33.064714Z",
77
"options": {
88
"no-language-in-filenames": true,
99
"preserve-filenames": true

sonar-ruby-plugin/src/main/resources/org/sonar/l10n/ruby/rules/ruby/S1066.html

+23-13
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,41 @@
11
<h2>Why is this an issue?</h2>
2-
<p>Merging collapsible <code>if</code> statements increases the code’s readability.</p>
3-
<h3>Noncompliant code example</h3>
2+
<p>Nested code - blocks of code inside blocks of code - is eventually necessary, but increases complexity. This is why keeping the code as flat as
3+
possible, by avoiding unnecessary nesting, is considered a good practice.</p>
4+
<p>Merging <code>if</code> statements when possible will decrease the nesting of the code and improve its readability.</p>
5+
<p>Code like</p>
46
<pre>
5-
if !filename.nil?
6-
if File.file?(filename) || File.directory?(filename)
7+
if a then
8+
unless b then # Noncompliant
79
# ...
810
end
911
end
10-
11-
if a then
12-
unless b then
12+
</pre>
13+
<p>Will be more readable as</p>
14+
<pre>
15+
if a &amp;&amp; !b then # Compliant
16+
# ...
17+
end
18+
</pre>
19+
<h2>How to fix it</h2>
20+
<p>If merging the conditions seems to result in a more complex code, extracting the condition or part of it in a named function or variable is a
21+
better approach to fix readability.</p>
22+
<h3>Code examples</h3>
23+
<h4>Noncompliant code example</h4>
24+
<pre>
25+
if !filename.nil?
26+
if File.file?(filename) || File.directory?(filename) # Noncompliant
1327
# ...
1428
end
1529
end
1630
</pre>
17-
<h3>Compliant solution</h3>
31+
<h4>Compliant solution</h4>
1832
<pre>
1933
def isFileOrDirectory(filename)
2034
File.file?(filename) || File.directory?(filename)
2135
end
2236
# ...
2337

24-
if !filename.nil? &amp;&amp; isFileOrDirectory(filename)
25-
# ...
26-
end
27-
28-
if a &amp;&amp; !b then
38+
if !filename.nil? &amp;&amp; isFileOrDirectory(filename) # Compliant
2939
# ...
3040
end
3141
</pre>

sonar-ruby-plugin/src/main/resources/org/sonar/l10n/ruby/rules/ruby/S1066.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"title": "Collapsible \"if\" statements should be merged",
2+
"title": "Mergeable \"if\" statements should be combined",
33
"type": "CODE_SMELL",
44
"code": {
55
"impacts": {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<h2>Why is this an issue?</h2>
2-
<p>Functions with a long parameter list are difficult to use, as maintainers must figure out the role of each parameter and keep track of their
2+
<p>Functions with a long parameter list are difficult to use because maintainers must figure out the role of each parameter and keep track of their
33
position.</p>
44
<pre>
55
def modify(x1, y1, z1, x2, y2, z2) # Noncompliant

sonar-ruby-plugin/src/main/resources/org/sonar/l10n/ruby/rules/ruby/S1110.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<h2>Why is this an issue?</h2>
2-
<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
3-
redundant pairs of parentheses could be misleading, and should be removed.</p>
2+
<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. However,
3+
redundant pairs of parentheses could be misleading and should be removed.</p>
44
<h3>Noncompliant code example</h3>
55
<pre>
66
x = (y / 2 + 1) # Compliant even if the parenthesis are ignored by the compiler

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ <h2>Why is this an issue?</h2>
1010
<h2>Resources</h2>
1111
<h3>Documentation</h3>
1212
<ul>
13-
<li> <a href="https://cwe.mitre.org/data/definitions/546">MITRE, CWE-546 - Suspicious Comment</a> </li>
13+
<li> CWE - <a href="https://cwe.mitre.org/data/definitions/546">CWE-546 - Suspicious Comment</a> </li>
1414
</ul>
1515

Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<h2>Why is this an issue?</h2>
2-
<p>Developers often use <code>TOOO</code> tags to mark areas in the code where additional work or improvements are needed but are not implemented
3-
immediately. However, these <code>TODO</code> tags sometimes get overlooked or forgotten, leading to incomplete or unfinished code. This code smell
4-
class aims to identify and address such unattended <code>TODO</code> tags to ensure a clean and maintainable codebase. This description will explore
5-
why this is a problem and how it can be fixed to improve the overall code quality.</p>
2+
<p>Developers often use <code>TODO</code> tags to mark areas in the code where additional work or improvements are needed but are not implemented
3+
immediately. However, these <code>TODO</code> tags sometimes get overlooked or forgotten, leading to incomplete or unfinished code. This rule aims to
4+
identify and address unattended <code>TODO</code> tags to ensure a clean and maintainable codebase. This description explores why this is a problem
5+
and how it can be fixed to improve the overall code quality.</p>
66
<h3>What is the potential impact?</h3>
77
<p>Unattended <code>TODO</code> tags in code can have significant implications for the development process and the overall codebase.</p>
88
<p>Incomplete Functionality: When developers leave <code>TODO</code> tags without implementing the corresponding code, it results in incomplete
@@ -11,8 +11,8 @@ <h3>What is the potential impact?</h3>
1111
Delayed bug fixes can result in more severe issues and increase the effort required to resolve them later.</p>
1212
<p>Impact on Collaboration: In team-based development environments, unattended <code>TODO</code> tags can hinder collaboration. Other team members
1313
might not be aware of the intended changes, leading to conflicts or redundant efforts in the codebase.</p>
14-
<p>Codebase Bloat: Accumulation of unattended <code>TODO</code> tags over time can clutter the codebase and make it difficult to distinguish between
15-
work in progress and completed code. This bloat can make it challenging to maintain an organized and efficient codebase.</p>
14+
<p>Codebase Bloat: The accumulation of unattended <code>TODO</code> tags over time can clutter the codebase and make it difficult to distinguish
15+
between work in progress and completed code. This bloat can make it challenging to maintain an organized and efficient codebase.</p>
1616
<p>Addressing this code smell is essential to ensure a maintainable, readable, reliable codebase and promote effective collaboration among
1717
developers.</p>
1818
<h3>Noncompliant code example</h3>
@@ -23,6 +23,6 @@ <h3>Noncompliant code example</h3>
2323
</pre>
2424
<h2>Resources</h2>
2525
<ul>
26-
<li> <a href="https://cwe.mitre.org/data/definitions/546">MITRE, CWE-546</a> - Suspicious Comment </li>
26+
<li> CWE - <a href="https://cwe.mitre.org/data/definitions/546">CWE-546 - Suspicious Comment</a> </li>
2727
</ul>
2828

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ <h3>Compliant solution</h3>
2525
</pre>
2626
<h2>Resources</h2>
2727
<ul>
28-
<li> <a href="https://cwe.mitre.org/data/definitions/489">MITRE, CWE-489</a> - Active Debug Code </li>
29-
<li> <a href="https://cwe.mitre.org/data/definitions/570">MITRE, CWE-570</a> - Expression is Always False </li>
30-
<li> <a href="https://cwe.mitre.org/data/definitions/571">MITRE, CWE-571</a> - Expression is Always True </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

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,55 @@
1+
<p>Functions and block parameters should be named consistently to communicate intent and improve maintainability. Rename your function or block
2+
parameter to follow your project’s naming convention to address this issue.</p>
13
<h2>Why is this an issue?</h2>
2-
<p>Shared naming conventions allow teams to collaborate effectively. This rule raises an issue when a function or block parameter name does not match
3-
the provided regular expression.</p>
4+
<p>A naming convention in software development is a set of guidelines for naming code elements like variables, functions, and classes.<br> Functions
5+
and block parameters hold the meaning of the written code. Their names should be meaningful and follow a consistent and easily recognizable
6+
pattern.<br> Adhering to a consistent naming convention helps to make the code more readable and understandable, which makes it easier to maintain and
7+
debug. It also ensures consistency in the code, especially when multiple developers are working on the same project.</p>
8+
<p>This rule checks that function and block parameter names match a provided regular expression.</p>
9+
<h3>What is the potential impact?</h3>
10+
<p>Inconsistent naming of functions and block parameters can lead to several issues in your code:</p>
11+
<ul>
12+
<li> <strong>Reduced Readability</strong>: Inconsistent function and block 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 functions and block parameters that don’t adhere to a standard naming convention are
15+
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 function and block parameter names lead to misunderstandings about what the
17+
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>
23+
</ul>
24+
<p>In summary, not adhering to a naming convention for functions and block parameters can lead to confusion, errors, and inefficiencies, making the
25+
code harder to read, understand, and maintain.</p>
26+
<h2>How to fix it</h2>
27+
<p>First, familiarize yourself with the particular naming convention of the project in question. Then, update the name to match the convention, as
28+
well as all usages of the name. For many IDEs, you can use built-in renaming and refactoring features to update all usages at once.</p>
29+
<h3>Code examples</h3>
30+
<h4>Noncompliant code example</h4>
31+
<p>With the default regular expression <code>^(@{0,2}[\da-z_]+[!?=]?)|([*+-/%=!&gt;&lt;~]+)|(\[]=?)$</code>:</p>
32+
<pre data-diff-id="1" data-diff-type="noncompliant">
33+
def show_something(text_Param) # Noncompliant
34+
localVar = "" # Noncompliant
35+
puts text_Param + localVar
36+
end
37+
</pre>
38+
<h4>Compliant solution</h4>
39+
<pre data-diff-id="1" data-diff-type="compliant">
40+
def show_something(text_param)
41+
local_var = ""
42+
puts text_param + local_var
43+
end
44+
</pre>
45+
<h2>Resources</h2>
46+
<h3>Documentation</h3>
47+
<ul>
48+
<li> Wikipedia - <a href="https://en.wikipedia.org/wiki/Naming_convention_(programming)">Naming Convention (programming)</a> </li>
49+
</ul>
50+
<h3>Related rules</h3>
51+
<ul>
52+
<li> {rule:ruby:S100} - Method names should comply with a naming convention </li>
53+
<li> {rule:ruby:S101} - Class names should comply with a naming convention </li>
54+
</ul>
455

sonar-ruby-plugin/src/main/resources/org/sonar/l10n/ruby/rules/ruby/S117.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"title": "function and block parameter names should comply with a naming convention",
2+
"title": "Function and block parameter names should comply with a naming convention",
33
"type": "CODE_SMELL",
44
"code": {
55
"impacts": {
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
<h2>Why is this an issue?</h2>
2-
<p>Unused parameters are misleading. Whatever the values passed to such parameters, the behavior will be the same.</p>
2+
<p>A typical code smell known as unused function parameters refers to parameters declared in a function but not used anywhere within the function’s
3+
body. While this might seem harmless at first glance, it can lead to confusion and potential errors in your code. Disregarding the values passed to
4+
such parameters, the function’s behavior will be the same, but the programmer’s intention won’t be clearly expressed anymore. Therefore, removing
5+
function parameters that are not being utilized is considered best practice.</p>
36

Original file line numberDiff line numberDiff line change
@@ -1,8 +1,37 @@
11
<h2>Why is this an issue?</h2>
2-
<p>There are several reasons for a method not to have a method body:</p>
2+
<p>An empty method is generally considered bad practice and can lead to confusion, readability, and maintenance issues. Empty methods bring no
3+
functionality and are misleading to others as they might think the method implementation fulfills a specific and identified requirement.</p>
4+
<p>There are several reasons for a method not to have a body:</p>
35
<ul>
46
<li> It is an unintentional omission, and should be fixed to prevent an unexpected behavior in production. </li>
57
<li> It is not yet, or never will be, supported. In this case an exception should be thrown. </li>
68
<li> The method is an intentionally-blank override. In this case a nested comment should explain the reason for the blank override. </li>
79
</ul>
10+
<h2>How to fix it</h2>
11+
<h3>Code examples</h3>
12+
<h4>Noncompliant code example</h4>
13+
<pre data-diff-id="1" data-diff-type="noncompliant">
14+
def shouldNotBeEmpty() # Noncompliant - method is empty
15+
end
16+
17+
def notImplemented() # Noncompliant - method is empty
18+
end
19+
20+
def emptyOnPurpose() # Noncompliant - method is empty
21+
end
22+
</pre>
23+
<h4>Compliant solution</h4>
24+
<pre data-diff-id="1" data-diff-type="compliant">
25+
def shouldNotBeEmpty()
26+
doSomething()
27+
end
28+
29+
def notImplemented()
30+
raise NotImplementedError, 'notImplemented() cannot be performed because ...'
31+
end
32+
33+
def emptyOnPurpose()
34+
# comment explaining why the method is empty
35+
end
36+
</pre>
837

Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
<h2>Why is this an issue?</h2>
2-
<p>Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.</p>
3-
<p>On the other hand, constants can be referenced from many places, but only need to be updated in a single place.</p>
4-
<h3>Noncompliant code example</h3>
2+
<p>Duplicated string literals make the process of refactoring complex and error-prone, as any change would need to be propagated on all
3+
occurrences.</p>
4+
<h3>Exceptions</h3>
5+
<p>To prevent generating some false-positives, literals having 5 or less characters are excluded as well as literals containing only letters, digits
6+
and '_'.</p>
7+
<h2>How to fix it</h2>
8+
<p>Use constants to replace the duplicated string literals. Constants can be referenced from many places, but only need to be updated in a single
9+
place.</p>
10+
<h3>Code examples</h3>
11+
<h4>Noncompliant code example</h4>
512
<p>With the default threshold of 3:</p>
6-
<pre>
13+
<pre data-diff-id="1" data-diff-type="noncompliant">
714
def foo()
815
prepare('action random1') #Noncompliant - "action random1" is duplicated 3 times
916
execute('action random1')
1017
release('action random1')
1118
end
1219
</pre>
13-
<h3>Compliant solution</h3>
14-
<pre>
20+
<h4>Compliant solution</h4>
21+
<pre data-diff-id="1" data-diff-type="compliant">
1522
def foo()
16-
action1 = 'action random1'
17-
prepare(action1)
18-
execute(action1)
19-
release(action1)
23+
ACTION1 = 'action random1'
24+
prepare(ACTION1)
25+
execute(ACTION1)
26+
release(ACTION1)
2027
end
2128
</pre>
22-
<h3>Exceptions</h3>
23-
<p>To prevent generating some false-positives, literals having 5 or less characters are excluded as well as literals containing only letters, digits
24-
and '_'.</p>
2529

sonar-ruby-plugin/src/main/resources/org/sonar/l10n/ruby/rules/ruby/S131.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ <h3>Compliant solution</h3>
2323
</pre>
2424
<h2>Resources</h2>
2525
<ul>
26-
<li> <a href="https://cwe.mitre.org/data/definitions/478">MITRE, CWE-478</a> - Missing Default Case in Switch Statement </li>
26+
<li> CWE - <a href="https://cwe.mitre.org/data/definitions/478">CWE-478 - Missing Default Case in Switch Statement</a> </li>
2727
</ul>
2828

sonar-ruby-plugin/src/main/resources/org/sonar/l10n/ruby/rules/ruby/S1313.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ <h2>Exceptions</h2>
4848
</ul>
4949
<h2>See</h2>
5050
<ul>
51-
<li> <a href="https://owasp.org/Top10/A01_2021-Broken_Access_Control/">OWASP Top 10 2021 Category A1</a> - Broken Access Control </li>
52-
<li> <a href="https://www.owasp.org/www-project-top-ten/2017/A3_2017-Sensitive_Data_Exposure">OWASP Top 10 2017 Category A3</a> - Sensitive Data
53-
Exposure </li>
51+
<li> OWASP - <a href="https://owasp.org/Top10/A01_2021-Broken_Access_Control/">Top 10 2021 Category A1 - Broken Access Control</a> </li>
52+
<li> OWASP - <a href="https://owasp.org/www-project-top-ten/2017/A3_2017-Sensitive_Data_Exposure">Top 10 2017 Category A3 - Sensitive Data
53+
Exposure</a> </li>
5454
</ul>
5555

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
<h2>Why is this an issue?</h2>
2-
<p>Nested <code>if</code>, <code>for</code>, <code>while</code>, <code>until</code>, <code>case</code> and <code>begin...rescue</code> statements are
3-
key ingredients for making what’s known as "Spaghetti code".</p>
4-
<p>Such code is hard to read, refactor and therefore maintain.</p>
2+
<p>Nested control flow statements <code>if</code>, <code>for</code>, <code>while</code>, <code>until</code>, <code>case</code> and
3+
<code>begin...rescue</code> are often key ingredients in creating what’s known as "Spaghetti code". This code smell can make your program difficult to
4+
understand and maintain.</p>
5+
<p>When numerous control structures are placed inside one another, the code becomes a tangled, complex web. This significantly reduces the code’s
6+
readability and maintainability, and it also complicates the testing process.</p>
7+
<h2>Resources</h2>
8+
<ul>
9+
<li> <a href="https://en.wikipedia.org/wiki/Guard_(computer_science)">Guard clauses in programming</a> - one of the approaches to reducing the depth
10+
of nesting </li>
11+
</ul>
512

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,38 @@
11
<h2>Why is this an issue?</h2>
2-
<p>If a local variable is declared but not used, it is dead code and should be removed. Doing so will improve maintainability because developers will
3-
not wonder what the variable is used for.</p>
2+
<p>An unused local variable is a variable that has been declared but is not used anywhere in the block of code where it is defined. It is dead code,
3+
contributing to unnecessary complexity and leading to confusion when reading the code. Therefore, it should be removed from your code to maintain
4+
clarity and efficiency.</p>
5+
<h3>What is the potential impact?</h3>
6+
<p>Having unused local variables in your code can lead to several issues:</p>
7+
<ul>
8+
<li> <strong>Decreased Readability</strong>: Unused variables can make your code more difficult to read. They add extra lines and complexity, which
9+
can distract from the main logic of the code. </li>
10+
<li> <strong>Misunderstanding</strong>: When other developers read your code, they may wonder why a variable is declared but not used. This can lead
11+
to confusion and misinterpretation of the code’s intent. </li>
12+
<li> <strong>Potential for Bugs</strong>: If a variable is declared but not used, it might indicate a bug or incomplete code. For example, if you
13+
declared a variable intending to use it in a calculation, but then forgot to do so, your program might not work as expected. </li>
14+
<li> <strong>Maintenance Issues</strong>: Unused variables can make code maintenance more difficult. If a programmer sees an unused variable, they
15+
might think it is a mistake and try to 'fix' the code, potentially introducing new bugs. </li>
16+
<li> <strong>Memory Usage</strong>: Although modern compilers are smart enough to ignore unused variables, not all compilers do this. In such cases,
17+
unused variables take up memory space, leading to inefficient use of resources. </li>
18+
</ul>
19+
<p>In summary, unused local variables can make your code less readable, more confusing, and harder to maintain, and they can potentially lead to bugs
20+
or inefficient memory use. Therefore, it is best to remove them.</p>
21+
<h2>How to fix it</h2>
22+
<p>The fix for this issue is straightforward. Once you ensure the unused variable is not part of an incomplete implementation leading to bugs, you
23+
just need to remove it.</p>
24+
<h3>Code examples</h3>
25+
<h4>Noncompliant code example</h4>
26+
<pre data-diff-id="1" data-diff-type="noncompliant">
27+
def number_of_minutes(hours)
28+
seconds = 0 # Noncompliant - seconds is unused
29+
hours * 60
30+
end
31+
</pre>
32+
<h4>Compliant solution</h4>
33+
<pre data-diff-id="1" data-diff-type="compliant">
34+
def number_of_minutes(hours)
35+
hours * 60
36+
end
37+
</pre>
438

sonar-ruby-plugin/src/main/resources/org/sonar/l10n/ruby/rules/ruby/S1763.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ <h3>Compliant solution</h3>
1919
</pre>
2020
<h2>Resources</h2>
2121
<ul>
22-
<li> <a href="https://cwe.mitre.org/data/definitions/561">MITRE, CWE-561</a> - Dead Code </li>
22+
<li> CWE - <a href="https://cwe.mitre.org/data/definitions/561">CWE-561 - Dead Code</a> </li>
2323
</ul>
2424

0 commit comments

Comments
 (0)