-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NO-JIRA] Update rule metadata (#14)
- Loading branch information
Showing
23 changed files
with
270 additions
and
82 deletions.
There are no files selected for viewing
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
36 changes: 23 additions & 13 deletions
36
sonar-ruby-plugin/src/main/resources/org/sonar/l10n/ruby/rules/ruby/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
sonar-ruby-plugin/src/main/resources/org/sonar/l10n/ruby/rules/ruby/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
2 changes: 1 addition & 1 deletion
2
sonar-ruby-plugin/src/main/resources/org/sonar/l10n/ruby/rules/ruby/S107.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
4 changes: 2 additions & 2 deletions
4
sonar-ruby-plugin/src/main/resources/org/sonar/l10n/ruby/rules/ruby/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
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
55 changes: 53 additions & 2 deletions
55
sonar-ruby-plugin/src/main/resources/org/sonar/l10n/ruby/rules/ruby/S117.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,4 +1,55 @@ | ||
<p>Functions and block parameters should be named consistently to communicate intent and improve maintainability. Rename your function or block | ||
parameter to follow your project’s naming convention to address this issue.</p> | ||
<h2>Why is this an issue?</h2> | ||
<p>Shared naming conventions allow teams to collaborate effectively. This rule raises an issue when a function or block parameter name does not match | ||
the provided regular expression.</p> | ||
<p>A naming convention in software development is a set of guidelines for naming code elements like variables, functions, and classes.<br> Functions | ||
and block parameters hold the meaning of the written code. Their names should be meaningful and follow a consistent and easily recognizable | ||
pattern.<br> Adhering to a consistent naming convention helps to make the code more readable and understandable, which makes it easier to maintain and | ||
debug. It also ensures consistency in the code, especially when multiple developers are working on the same project.</p> | ||
<p>This rule checks that function and block parameter names match a provided regular expression.</p> | ||
<h3>What is the potential impact?</h3> | ||
<p>Inconsistent naming of functions and block parameters can lead to several issues in your code:</p> | ||
<ul> | ||
<li> <strong>Reduced Readability</strong>: Inconsistent function and block parameter names make the code harder to read and understand; | ||
consequently, it is more difficult to identify the purpose of each variable, spot errors, or comprehend the logic. </li> | ||
<li> <strong>Difficulty in Identifying Variables</strong>: The functions and block parameters that don’t adhere to a standard naming convention are | ||
challenging to identify; thus, the coding process slows down, especially when dealing with a large codebase. </li> | ||
<li> <strong>Increased Risk of Errors</strong>: Inconsistent or unclear function and block parameter names lead to misunderstandings about what the | ||
variable represents. This ambiguity leads to incorrect assumptions and, consequently, bugs in the code. </li> | ||
<li> <strong>Collaboration Difficulties</strong>: In a team setting, inconsistent naming conventions lead to confusion and miscommunication among | ||
team members. </li> | ||
<li> <strong>Difficulty in Code Maintenance</strong>: Inconsistent naming leads to an inconsistent codebase. The code is difficult to understand, | ||
and making changes feels like refactoring constantly, as you face different naming methods. Ultimately, it makes the codebase harder to maintain. | ||
</li> | ||
</ul> | ||
<p>In summary, not adhering to a naming convention for functions and block parameters can lead to confusion, errors, and inefficiencies, making the | ||
code harder to read, understand, and maintain.</p> | ||
<h2>How to fix it</h2> | ||
<p>First, familiarize yourself with the particular naming convention of the project in question. Then, update the name to match the convention, as | ||
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> | ||
<h3>Code examples</h3> | ||
<h4>Noncompliant code example</h4> | ||
<p>With the default regular expression <code>^(@{0,2}[\da-z_]+[!?=]?)|([*+-/%=!><~]+)|(\[]=?)$</code>:</p> | ||
<pre data-diff-id="1" data-diff-type="noncompliant"> | ||
def show_something(text_Param) # Noncompliant | ||
localVar = "" # Noncompliant | ||
puts text_Param + localVar | ||
end | ||
</pre> | ||
<h4>Compliant solution</h4> | ||
<pre data-diff-id="1" data-diff-type="compliant"> | ||
def show_something(text_param) | ||
local_var = "" | ||
puts text_param + local_var | ||
end | ||
</pre> | ||
<h2>Resources</h2> | ||
<h3>Documentation</h3> | ||
<ul> | ||
<li> Wikipedia - <a href="https://en.wikipedia.org/wiki/Naming_convention_(programming)">Naming Convention (programming)</a> </li> | ||
</ul> | ||
<h3>Related rules</h3> | ||
<ul> | ||
<li> {rule:ruby:S100} - Method names should comply with a naming convention </li> | ||
<li> {rule:ruby:S101} - Class names should comply with a naming convention </li> | ||
</ul> | ||
|
2 changes: 1 addition & 1 deletion
2
sonar-ruby-plugin/src/main/resources/org/sonar/l10n/ruby/rules/ruby/S117.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
5 changes: 4 additions & 1 deletion
5
sonar-ruby-plugin/src/main/resources/org/sonar/l10n/ruby/rules/ruby/S1172.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,3 +1,6 @@ | ||
<h2>Why is this an issue?</h2> | ||
<p>Unused parameters are misleading. Whatever the values passed to such parameters, the behavior will be the same.</p> | ||
<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 | ||
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 | ||
such parameters, the function’s behavior will be the same, but the programmer’s intention won’t be clearly expressed anymore. Therefore, removing | ||
function parameters that are not being utilized is considered best practice.</p> | ||
|
31 changes: 30 additions & 1 deletion
31
sonar-ruby-plugin/src/main/resources/org/sonar/l10n/ruby/rules/ruby/S1186.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,8 +1,37 @@ | ||
<h2>Why is this an issue?</h2> | ||
<p>There are several reasons for a method not to have a method body:</p> | ||
<p>An empty method is generally considered bad practice and can lead to confusion, readability, and maintenance issues. Empty methods bring no | ||
functionality and are misleading to others as they might think the method implementation fulfills a specific and identified requirement.</p> | ||
<p>There are several reasons for a method not to have a body:</p> | ||
<ul> | ||
<li> It is an unintentional omission, and should be fixed to prevent an unexpected behavior in production. </li> | ||
<li> It is not yet, or never will be, supported. In this case an exception should be thrown. </li> | ||
<li> The method is an intentionally-blank override. In this case a nested comment should explain the reason for the blank override. </li> | ||
</ul> | ||
<h2>How to fix it</h2> | ||
<h3>Code examples</h3> | ||
<h4>Noncompliant code example</h4> | ||
<pre data-diff-id="1" data-diff-type="noncompliant"> | ||
def shouldNotBeEmpty() # Noncompliant - method is empty | ||
end | ||
|
||
def notImplemented() # Noncompliant - method is empty | ||
end | ||
|
||
def emptyOnPurpose() # Noncompliant - method is empty | ||
end | ||
</pre> | ||
<h4>Compliant solution</h4> | ||
<pre data-diff-id="1" data-diff-type="compliant"> | ||
def shouldNotBeEmpty() | ||
doSomething() | ||
end | ||
|
||
def notImplemented() | ||
raise NotImplementedError, 'notImplemented() cannot be performed because ...' | ||
end | ||
|
||
def emptyOnPurpose() | ||
# comment explaining why the method is empty | ||
end | ||
</pre> | ||
|
30 changes: 17 additions & 13 deletions
30
sonar-ruby-plugin/src/main/resources/org/sonar/l10n/ruby/rules/ruby/S1192.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,25 +1,29 @@ | ||
<h2>Why is this an issue?</h2> | ||
<p>Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.</p> | ||
<p>On the other hand, constants can be referenced from many places, but only need to be updated in a single place.</p> | ||
<h3>Noncompliant code example</h3> | ||
<p>Duplicated string literals make the process of refactoring complex and error-prone, as any change would need to be propagated on all | ||
occurrences.</p> | ||
<h3>Exceptions</h3> | ||
<p>To prevent generating some false-positives, literals having 5 or less characters are excluded as well as literals containing only letters, digits | ||
and '_'.</p> | ||
<h2>How to fix it</h2> | ||
<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 | ||
place.</p> | ||
<h3>Code examples</h3> | ||
<h4>Noncompliant code example</h4> | ||
<p>With the default threshold of 3:</p> | ||
<pre> | ||
<pre data-diff-id="1" data-diff-type="noncompliant"> | ||
def foo() | ||
prepare('action random1') #Noncompliant - "action random1" is duplicated 3 times | ||
execute('action random1') | ||
release('action random1') | ||
end | ||
</pre> | ||
<h3>Compliant solution</h3> | ||
<pre> | ||
<h4>Compliant solution</h4> | ||
<pre data-diff-id="1" data-diff-type="compliant"> | ||
def foo() | ||
action1 = 'action random1' | ||
prepare(action1) | ||
execute(action1) | ||
release(action1) | ||
ACTION1 = 'action random1' | ||
prepare(ACTION1) | ||
execute(ACTION1) | ||
release(ACTION1) | ||
end | ||
</pre> | ||
<h3>Exceptions</h3> | ||
<p>To prevent generating some false-positives, literals having 5 or less characters are excluded as well as literals containing only letters, digits | ||
and '_'.</p> | ||
|
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
13 changes: 10 additions & 3 deletions
13
sonar-ruby-plugin/src/main/resources/org/sonar/l10n/ruby/rules/ruby/S134.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,5 +1,12 @@ | ||
<h2>Why is this an issue?</h2> | ||
<p>Nested <code>if</code>, <code>for</code>, <code>while</code>, <code>until</code>, <code>case</code> and <code>begin...rescue</code> statements are | ||
key ingredients for making what’s known as "Spaghetti code".</p> | ||
<p>Such code is hard to read, refactor and therefore maintain.</p> | ||
<p>Nested control flow statements <code>if</code>, <code>for</code>, <code>while</code>, <code>until</code>, <code>case</code> and | ||
<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 | ||
understand and maintain.</p> | ||
<p>When numerous control structures are placed inside one another, the code becomes a tangled, complex web. This significantly reduces the code’s | ||
readability and maintainability, and it also complicates the testing process.</p> | ||
<h2>Resources</h2> | ||
<ul> | ||
<li> <a href="https://en.wikipedia.org/wiki/Guard_(computer_science)">Guard clauses in programming</a> - one of the approaches to reducing the depth | ||
of nesting </li> | ||
</ul> | ||
|
38 changes: 36 additions & 2 deletions
38
sonar-ruby-plugin/src/main/resources/org/sonar/l10n/ruby/rules/ruby/S1481.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,4 +1,38 @@ | ||
<h2>Why is this an issue?</h2> | ||
<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 | ||
not wonder what the variable is used for.</p> | ||
<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, | ||
contributing to unnecessary complexity and leading to confusion when reading the code. Therefore, it should be removed from your code to maintain | ||
clarity and efficiency.</p> | ||
<h3>What is the potential impact?</h3> | ||
<p>Having unused local variables in your code can lead to several issues:</p> | ||
<ul> | ||
<li> <strong>Decreased Readability</strong>: Unused variables can make your code more difficult to read. They add extra lines and complexity, which | ||
can distract from the main logic of the code. </li> | ||
<li> <strong>Misunderstanding</strong>: When other developers read your code, they may wonder why a variable is declared but not used. This can lead | ||
to confusion and misinterpretation of the code’s intent. </li> | ||
<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 | ||
declared a variable intending to use it in a calculation, but then forgot to do so, your program might not work as expected. </li> | ||
<li> <strong>Maintenance Issues</strong>: Unused variables can make code maintenance more difficult. If a programmer sees an unused variable, they | ||
might think it is a mistake and try to 'fix' the code, potentially introducing new bugs. </li> | ||
<li> <strong>Memory Usage</strong>: Although modern compilers are smart enough to ignore unused variables, not all compilers do this. In such cases, | ||
unused variables take up memory space, leading to inefficient use of resources. </li> | ||
</ul> | ||
<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 | ||
or inefficient memory use. Therefore, it is best to remove them.</p> | ||
<h2>How to fix it</h2> | ||
<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 | ||
just need to remove it.</p> | ||
<h3>Code examples</h3> | ||
<h4>Noncompliant code example</h4> | ||
<pre data-diff-id="1" data-diff-type="noncompliant"> | ||
def number_of_minutes(hours) | ||
seconds = 0 # Noncompliant - seconds is unused | ||
hours * 60 | ||
end | ||
</pre> | ||
<h4>Compliant solution</h4> | ||
<pre data-diff-id="1" data-diff-type="compliant"> | ||
def number_of_minutes(hours) | ||
hours * 60 | ||
end | ||
</pre> | ||
|
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.