Skip to content

Commit

Permalink
Update RSPEC before 9.23 release (#8976)
Browse files Browse the repository at this point in the history
  • Loading branch information
mary-georgiou-sonarsource authored Mar 22, 2024
1 parent 8a64975 commit 9478382
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions analyzers/rspec/cs/S1192.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ <h3>Exceptions</h3>
<li> literals used in attributes </li>
</ul>
<h2>How to fix it</h2>
<p>Instead, 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>
<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>
<pre data-diff-id="1" data-diff-type="noncompliant">
Expand Down
20 changes: 10 additions & 10 deletions analyzers/rspec/cs/S1481.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ <h2>Why is this an issue?</h2>
<h3>What is the potential impact?</h3>
<p>Having unused local variables in your code can lead to several issues:</p>
<ul>
<li> Decreased Readability: 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> Misunderstanding: 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> Potential for Bugs: 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> Maintenance Issues: 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> Memory Usage: 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>
<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>
Expand Down
2 changes: 1 addition & 1 deletion analyzers/rspec/cs/S2955.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h4>Compliant solution</h4>
<pre data-diff-id="1" data-diff-type="compliant">
bool IsDefault&lt;T&gt;(T value)
{
if(object.Equals(value, default(T)))
if (EqualityComparer&lt;T&gt;.Default.Equals(value, default(T)))
{
// ...
}
Expand Down
24 changes: 12 additions & 12 deletions analyzers/rspec/cs/S6934.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ <h2>Why is this an issue?</h2>

public class PersonController
{
// Conventional routing:
// Matches e.g. /Person/Index/123
public IActionResult Index(int? id) =&gt; View();
// Conventional routing:
// Matches e.g. /Person/Index/123
public IActionResult Index(int? id) =&gt; View();

// Attribute routing:
// Matches e.g. /Age/Ascending (and model binds "Age" to sortBy and "Ascending" to direction)
// but does not match /Person/List/Age/Ascending
[HttpGet(template: "{sortBy}/{direction}")]
public IActionResult List(string sortBy, SortOrder direction) =&gt; View();
// Attribute routing:
// Matches e.g. /Age/Ascending (and model binds "Age" to sortBy and "Ascending" to direction)
// but does not match /Person/List/Age/Ascending
[HttpGet(template: "{sortBy}/{direction}")]
public IActionResult List(string sortBy, SortOrder direction) =&gt; View();
}
</pre>
<h2>How to fix it in ASP.NET Core</h2>
Expand All @@ -39,7 +39,7 @@ <h2>How to fix it in ASP.NET Core</h2>
<h3>Code examples</h3>
<h4>Noncompliant code example</h4>
<pre data-diff-id="1" data-diff-type="noncompliant">
public class PersonController: Controller
public class PersonController : Controller
{
// Matches /Person/Index/123
public IActionResult Index(int? id) =&gt; View();
Expand All @@ -53,7 +53,7 @@ <h4>Noncompliant code example</h4>
<h4>Compliant solution</h4>
<pre data-diff-id="1" data-diff-type="compliant">
[Route("[controller]/{action=Index}")]
public class PersonController: Controller
public class PersonController : Controller
{
// Matches /Person/Index/123
[Route("{id?}")]
Expand All @@ -73,15 +73,15 @@ <h4>Compliant solution</h4>
defaults: new { action = "List" } ); // Matches Person/List/Age/Ascending

// Option 2. Use a binding, that does not depend on route templates
public class PersonController: Controller
public class PersonController : Controller
{
// Matches Person/List?sortBy=Age&amp;direction=Ascending
[HttpGet] // Compliant: Parameters are bound from the query string
public IActionResult List(string sortBy, SortOrder direction) =&gt; View();
}

// Option 3. Use an absolute route
public class PersonController: Controller
public class PersonController : Controller
{
// Matches Person/List/Age/Ascending
[HttpGet("/[controller]/[action]/{sortBy}/{direction}")] // Illustrate the expected route by starting with "/"
Expand Down
4 changes: 2 additions & 2 deletions analyzers/rspec/vbnet/S1192.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ <h3>Exceptions</h3>
<li> literals used in attributes </li>
</ul>
<h2>How to fix it</h2>
<p>Instead, 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>
<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>
<pre data-diff-id="1" data-diff-type="noncompliant">
Expand Down
20 changes: 10 additions & 10 deletions analyzers/rspec/vbnet/S1481.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ <h2>Why is this an issue?</h2>
<h3>What is the potential impact?</h3>
<p>Having unused local variables in your code can lead to several issues:</p>
<ul>
<li> Decreased Readability: 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> Misunderstanding: 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> Potential for Bugs: 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> Maintenance Issues: 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> Memory Usage: 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>
<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>
Expand Down
2 changes: 1 addition & 1 deletion analyzers/src/SonarAnalyzer.CSharp/sonarpedia.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"languages": [
"CSH"
],
"latest-update": "2024-03-20T08:56:52.732098400Z",
"latest-update": "2024-03-22T15:44:44.508271500Z",
"options": {
"no-language-in-filenames": true
}
Expand Down
2 changes: 1 addition & 1 deletion analyzers/src/SonarAnalyzer.VisualBasic/sonarpedia.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"languages": [
"VBNET"
],
"latest-update": "2024-03-20T08:59:07.028699300Z",
"latest-update": "2024-03-22T15:45:04.138667400Z",
"options": {
"no-language-in-filenames": true
}
Expand Down

0 comments on commit 9478382

Please sign in to comment.