From 947838298a5a0f91ec4780bccd205bac809f68b9 Mon Sep 17 00:00:00 2001 From: Mary Georgiou <89914005+mary-georgiou-sonarsource@users.noreply.github.com> Date: Fri, 22 Mar 2024 17:05:05 +0100 Subject: [PATCH] Update RSPEC before 9.23 release (#8976) --- analyzers/rspec/cs/S1192.html | 4 ++-- analyzers/rspec/cs/S1481.html | 20 ++++++++-------- analyzers/rspec/cs/S2955.html | 2 +- analyzers/rspec/cs/S6934.html | 24 +++++++++---------- analyzers/rspec/vbnet/S1192.html | 4 ++-- analyzers/rspec/vbnet/S1481.html | 20 ++++++++-------- .../src/SonarAnalyzer.CSharp/sonarpedia.json | 2 +- .../SonarAnalyzer.VisualBasic/sonarpedia.json | 2 +- 8 files changed, 39 insertions(+), 39 deletions(-) diff --git a/analyzers/rspec/cs/S1192.html b/analyzers/rspec/cs/S1192.html index c25c973215d..74bf1f1993c 100644 --- a/analyzers/rspec/cs/S1192.html +++ b/analyzers/rspec/cs/S1192.html @@ -9,8 +9,8 @@

Exceptions

  • literals used in attributes
  • How to fix it

    -

    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.

    +

    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.

    Code examples

    Noncompliant code example

    diff --git a/analyzers/rspec/cs/S1481.html b/analyzers/rspec/cs/S1481.html
    index b22f3e7ac10..07a41e89113 100644
    --- a/analyzers/rspec/cs/S1481.html
    +++ b/analyzers/rspec/cs/S1481.html
    @@ -5,16 +5,16 @@ 

    Why is this an issue?

    What is the potential impact?

    Having unused local variables in your code can lead to several issues:

    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.

    diff --git a/analyzers/rspec/cs/S2955.html b/analyzers/rspec/cs/S2955.html index e2760182f5f..1bcc3add3cd 100644 --- a/analyzers/rspec/cs/S2955.html +++ b/analyzers/rspec/cs/S2955.html @@ -27,7 +27,7 @@

    Compliant solution

     bool IsDefault<T>(T value)
     {
    -  if(object.Equals(value, default(T)))
    +  if (EqualityComparer<T>.Default.Equals(value, default(T)))
       {
         // ...
       }
    diff --git a/analyzers/rspec/cs/S6934.html b/analyzers/rspec/cs/S6934.html
    index 6df28d9a091..ea29955ba48 100644
    --- a/analyzers/rspec/cs/S6934.html
    +++ b/analyzers/rspec/cs/S6934.html
    @@ -20,15 +20,15 @@ 

    Why is this an issue?

    public class PersonController { - // Conventional routing: - // Matches e.g. /Person/Index/123 - public IActionResult Index(int? id) => View(); + // Conventional routing: + // Matches e.g. /Person/Index/123 + public IActionResult Index(int? id) => 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) => 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) => View(); }

    How to fix it in ASP.NET Core

    @@ -39,7 +39,7 @@

    How to fix it in ASP.NET Core

    Code examples

    Noncompliant code example

    -public class PersonController: Controller
    +public class PersonController : Controller
     {
         // Matches /Person/Index/123
         public IActionResult Index(int? id) => View();
    @@ -53,7 +53,7 @@ 

    Noncompliant code example

    Compliant solution

     [Route("[controller]/{action=Index}")]
    -public class PersonController: Controller
    +public class PersonController : Controller
     {
         // Matches /Person/Index/123
         [Route("{id?}")]
    @@ -73,7 +73,7 @@ 

    Compliant solution

    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&direction=Ascending [HttpGet] // Compliant: Parameters are bound from the query string @@ -81,7 +81,7 @@

    Compliant solution

    } // 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 "/" diff --git a/analyzers/rspec/vbnet/S1192.html b/analyzers/rspec/vbnet/S1192.html index 5ddafb1c473..13b7b617553 100644 --- a/analyzers/rspec/vbnet/S1192.html +++ b/analyzers/rspec/vbnet/S1192.html @@ -9,8 +9,8 @@

    Exceptions

  • literals used in attributes
  • How to fix it

    -

    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.

    +

    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.

    Code examples

    Noncompliant code example

    diff --git a/analyzers/rspec/vbnet/S1481.html b/analyzers/rspec/vbnet/S1481.html
    index 6745290be5a..b10cd305ec5 100644
    --- a/analyzers/rspec/vbnet/S1481.html
    +++ b/analyzers/rspec/vbnet/S1481.html
    @@ -5,16 +5,16 @@ 

    Why is this an issue?

    What is the potential impact?

    Having unused local variables in your code can lead to several issues:

      -
    • 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.
    • -
    • 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.
    • -
    • 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.
    • -
    • 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.
    • -
    • 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.
    • +
    • 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.
    • +
    • 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.
    • +
    • 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.
    • +
    • 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.
    • +
    • 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.

    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.

    diff --git a/analyzers/src/SonarAnalyzer.CSharp/sonarpedia.json b/analyzers/src/SonarAnalyzer.CSharp/sonarpedia.json index f0dedbc73d7..5d16242d7fc 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/sonarpedia.json +++ b/analyzers/src/SonarAnalyzer.CSharp/sonarpedia.json @@ -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 } diff --git a/analyzers/src/SonarAnalyzer.VisualBasic/sonarpedia.json b/analyzers/src/SonarAnalyzer.VisualBasic/sonarpedia.json index 5e95be941ff..98e0ce82ce0 100644 --- a/analyzers/src/SonarAnalyzer.VisualBasic/sonarpedia.json +++ b/analyzers/src/SonarAnalyzer.VisualBasic/sonarpedia.json @@ -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 }