fix: resolve SonarQube code smells by adding static modifiers#1
Open
sonarqube-agent[bot] wants to merge 1 commit into
Open
fix: resolve SonarQube code smells by adding static modifiers#1sonarqube-agent[bot] wants to merge 1 commit into
sonarqube-agent[bot] wants to merge 1 commit into
Conversation
Fixed issues: - AZYzDoMrLMIqqoo4hBif for csharpsquid:S2325 rule - AZYzDoMrLMIqqoo4hBid for csharpsquid:S2325 rule - AZYzDoOpLMIqqoo4hBij for csharpsquid:S1118 rule Generated by SonarQube Agent (task: 9fd0b8e3-f7bf-4e42-b154-b243b572c10c)
SonarQube reviewer guide
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Fixed 3 SonarQube issues by marking the Program class and ConfigureServices/Configure methods as static. These changes prevent unintended instantiation of utility classes and clarify that methods have no instance dependencies, improving code clarity and performance.
View Project in SonarCloud
Fixed Issues
csharpsquid:S1118 - Add a 'protected' constructor or the 'static' keyword to the class declaration. • MAJOR • View issue
Location:
Program.cs:13Why is this an issue?
Whenever there are portions of code that are duplicated and do not depend on the state of their container class, they can be centralized inside a "utility class". A utility class is a class that only has static members, hence it should not be instantiated.
What changed
This hunk adds the 'static' keyword to the Program class declaration, changing it from 'public class Program' to 'public static class Program'. The static analysis rule flags utility classes (classes with only static members) that can be instantiated because they lack a protected constructor or the 'static' modifier. By marking the class as static, the compiler prevents instantiation, which resolves the code smell about the utility class missing either a protected constructor or the static keyword.
csharpsquid:S2325 - Make 'ConfigureServices' a static method. • MINOR • View issue
Location:
Startup.cs:25Why is this an issue?
Methods and properties that don’t access instance data should be marked as
staticfor the following reasons:What changed
This hunk adds the
statickeyword to theConfigureServicesmethod on line 25 of Startup.cs. The static analysis flagged this method because it doesn't access any instance data, so it should be marked asstaticfor clarity, performance, and testability. Addingstaticresolves this warning.csharpsquid:S2325 - Make 'Configure' a static method. • MINOR • View issue
Location:
Startup.cs:39Why is this an issue?
Methods and properties that don’t access instance data should be marked as
staticfor the following reasons:What changed
This hunk adds the
statickeyword to theConfiguremethod on line 39 of Startup.cs. The static analysis flagged this method because it doesn't access any instance data, so it should be marked asstaticfor clarity, performance, and testability. Addingstaticresolves this warning.SonarQube Remediation Agent uses AI. Check for mistakes.