Skip to content

SLVS-2964 fix: resolve 5 SonarQube code quality issues - #6729

Open
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260523-050120-89f09713
Open

SLVS-2964 fix: resolve 5 SonarQube code quality issues#6729
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260523-050120-89f09713

Conversation

@sonarqube-agent

Copy link
Copy Markdown
Contributor

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

Fixed multiple code quality violations including making three methods static to clarify independence from instance state, removing unnecessary null checks on guaranteed non-null values, and replacing a null return with an empty collection. These changes improve code clarity, performance, and maintainability while eliminating false positive warnings.

View Project in SonarCloud


Fixed Issues

csharpsquid:S2325 - Make 'ShouldHideIssue' a static method. • MINORView issue

Location: src/Integration.Vsix/ErrorList/IssuesSnapshot.cs:262

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 ShouldHideIssue method. The static analysis rule flagged this method because it does not access any instance data, meaning it can and should be marked as static. Adding the static modifier clarifies that the method is independent of instance state, avoids the overhead of passing an implicit this reference, and improves readability and testability.

--- a/src/Integration.Vsix/ErrorList/IssuesSnapshot.cs
+++ b/src/Integration.Vsix/ErrorList/IssuesSnapshot.cs
@@ -262,1 +262,1 @@ private string GetErrorCategory(IAnalysisIssue issue)
-        private bool ShouldHideIssue(IAnalysisIssueVisualization issue)
+        private static bool ShouldHideIssue(IAnalysisIssueVisualization issue)
csharpsquid:S2325 - Make 'Convert' a static method. • MINORView issue

Location: src/IssueViz/Models/AnalysisIssueVisualizationConverter.cs:100

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' modifier to the Convert method that takes IEnumerable as a parameter at line 100. The static analysis flagged this method because it does not access any instance data and should be marked as static. Adding the 'static' keyword makes it clear that the method doesn't depend on instance state, avoids the overhead of passing an instance reference, and directly resolves the code smell warning.

--- a/src/IssueViz/Models/AnalysisIssueVisualizationConverter.cs
+++ b/src/IssueViz/Models/AnalysisIssueVisualizationConverter.cs
@@ -100,1 +100,1 @@ private IReadOnlyList<IAnalysisIssueFlowVisualization> Convert(IEnumerable<IAnal
-        private IReadOnlyList<IAnalysisIssueLocationVisualization> Convert(IEnumerable<IAnalysisIssueLocation> locations)
+        private static IReadOnlyList<IAnalysisIssueLocationVisualization> Convert(IEnumerable<IAnalysisIssueLocation> locations)
csharpsquid:S2589 - Remove this unnecessary check for null. • MAJORView issue

Location: src/Integration.Vsix/SonarLintTagger/CancellableJobRunner.cs:163

Why is this an issue?

Control flow constructs like if-statements allow the programmer to direct the flow of a program depending on a boolean expression. However, if the condition is always true or always false, only one of the branches will ever be executed. In that case, the control flow construct and the condition no longer serve a purpose; they become gratuitous.

What changed

Removes the unnecessary null-conditional operator (?.) on cancellationSource.Dispose() at line 163. The static analyzer determined that cancellationSource can never be null at this point in the code, making the null check gratuitous. Replacing cancellationSource?.Dispose() with cancellationSource.Dispose() eliminates the unnecessary null check and resolves the code smell.

--- a/src/Integration.Vsix/SonarLintTagger/CancellableJobRunner.cs
+++ b/src/Integration.Vsix/SonarLintTagger/CancellableJobRunner.cs
@@ -163,1 +163,1 @@ private async System.Threading.Tasks.Task ExecuteAsync()
-                cancellationSource?.Dispose();
+                cancellationSource.Dispose();
csharpsquid:S2589 - Remove this unnecessary check for null. • MAJORView issue

Location: src/Integration.Vsix/SonarLintTagger/CancellableJobRunner.cs:177

Why is this an issue?

Control flow constructs like if-statements allow the programmer to direct the flow of a program depending on a boolean expression. However, if the condition is always true or always false, only one of the branches will ever be executed. In that case, the control flow construct and the condition no longer serve a purpose; they become gratuitous.

What changed

Removes the unnecessary null-conditional operator (?.) on cancellationSource.Cancel() at line 177. The static analyzer determined that cancellationSource can never be null at this point in the code, making the null check gratuitous. Replacing cancellationSource?.Cancel() with cancellationSource.Cancel() eliminates the unnecessary null check and resolves the code smell.

--- a/src/Integration.Vsix/SonarLintTagger/CancellableJobRunner.cs
+++ b/src/Integration.Vsix/SonarLintTagger/CancellableJobRunner.cs
@@ -177,1 +177,1 @@ public void Cancel()
-                    cancellationSource?.Cancel();
+                    cancellationSource.Cancel();
csharpsquid:S1168 - Return an empty collection instead of null. • MAJORView issue

Location: src/Integration/WPF/NotifyErrorViewModelBase.cs:43

Why is this an issue?

Returning null or default instead of an actual collection forces the method callers to explicitly test for null, making the code more complex and less readable.

What changed

Adds the using System.Linq import, which is required to use Enumerable.Empty<string>() in the fix that replaces the return null statement. Without this import, the Enumerable class would not be available.

--- a/src/Integration/WPF/NotifyErrorViewModelBase.cs
+++ b/src/Integration/WPF/NotifyErrorViewModelBase.cs
@@ -22,0 +23,1 @@
+using System.Linq;

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


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZFqcxYr7Cab0JIMjah2 for csharpsquid:S2325 rule
- AWMB0jMNmtQEh111EJCt for csharpsquid:S1168 rule
- AZC2zPMC3yATU8exn0Z2 for csharpsquid:S2589 rule
- AYqIsIc9RlgCy-_ohqpM for csharpsquid:S2589 rule
- AZFqcxBW7Cab0JIMjahj for csharpsquid:S2325 rule

Generated by SonarQube Agent (task: ef450648-78d7-4bd0-8bc9-1228593e4023)
@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod Bot changed the title fix: resolve 5 SonarQube code quality issues SLVS-2964 fix: resolve 5 SonarQube code quality issues May 23, 2026
@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented May 23, 2026

Copy link
Copy Markdown

SLVS-2964

@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