Skip to content

fix: resolve SonarQube code smells by adding static modifiers#1

Open
sonarqube-agent[bot] wants to merge 1 commit into
mainfrom
remediate-main-20260525-010128-33f2a885
Open

fix: resolve SonarQube code smells by adding static modifiers#1
sonarqube-agent[bot] wants to merge 1 commit into
mainfrom
remediate-main-20260525-010128-33f2a885

Conversation

@sonarqube-agent

Copy link
Copy Markdown

This PR was automatically created by the Remediation Agent's Scheduled backlog remediation feature.

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. • MAJORView issue

Location: Program.cs:13

Why 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.

--- a/Program.cs
+++ b/Program.cs
@@ -13,1 +13,1 @@ namespace pipelines_dotnet_core
-    public class Program
+    public static class Program
csharpsquid:S2325 - Make 'ConfigureServices' a static method. • MINORView issue

Location: Startup.cs:25

Why is this an issue?

Methods and properties that don’t access instance data should be marked as static for the following reasons:

What changed

This hunk adds the static keyword to the ConfigureServices method 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 as static for clarity, performance, and testability. Adding static resolves this warning.

--- a/Startup.cs
+++ b/Startup.cs
@@ -25,1 +25,1 @@ namespace pipelines_dotnet_core
-        public void ConfigureServices(IServiceCollection services)
+        public static void ConfigureServices(IServiceCollection services)
csharpsquid:S2325 - Make 'Configure' a static method. • MINORView issue

Location: Startup.cs:39

Why is this an issue?

Methods and properties that don’t access instance data should be marked as static for the following reasons:

What changed

This hunk adds the static keyword to the Configure method 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 as static for clarity, performance, and testability. Adding static resolves this warning.

--- a/Startup.cs
+++ b/Startup.cs
@@ -39,1 +39,1 @@ namespace pipelines_dotnet_core
-        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
+        public static void Configure(IApplicationBuilder app, IHostingEnvironment env)

Have a suggestion or found an issue? Share your feedback here.


SonarQube Remediation Agent uses AI. Check for mistakes.

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)
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant