Resolve 5 SonarQube issues across C# and Python code - #237
Open
sonarqube-agent[bot] wants to merge 1 commit into
Open
Resolve 5 SonarQube issues across C# and Python code#237sonarqube-agent[bot] wants to merge 1 commit into
sonarqube-agent[bot] wants to merge 1 commit into
Conversation
Fixed issues: - AZ9rJA3GkdvHrJAQ8SGY for python:PrintStatementUsage rule - AZ9rJA7PkdvHrJAQ8SJ_ for csharpsquid:S2583 rule - AZ9rJA7PkdvHrJAQ8SJ- for csharpsquid:S1118 rule - AZ9rJA29kdvHrJAQ8SGB for python:S125 rule - AZ9rJA29kdvHrJAQ8SGC for python:S125 rule Generated by SonarQube Agent (task: bd97710f-a7f8-4fa5-bc5b-c03a0640b7cf)
|
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.



This PR fixes 5 MAJOR SonarQube violations: making a utility class static to prevent unintended instantiation, removing an always-true conditional that left unreachable code, converting Python 2 print statements to Python 3 functions, and deleting commented-out code that cluttered the codebase. These changes improve code quality by eliminating dead code paths, enforcing proper class design patterns, and ensuring compatibility with modern Python standards.
View Project in SonarCloud
Fixed Issues
csharpsquid:S1118 - Add a 'protected' constructor or the 'static' keyword to the class declaration. • MAJOR • View issue
Location:
sonar-scanner-dotnet/CSharpProject/SomeConsoleApplication/Program.cs:4Why 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 changes
public class Programtopublic static class Program, adding thestatickeyword to the class declaration. This fixes the issue where a utility class (one with only static members) had an implicit public constructor, allowing it to be instantiated. By making the class static, instantiation is prevented, which addresses the code smell about adding a protected constructor or the static keyword to the class declaration.csharpsquid:S2583 - Change this condition so that it does not always evaluate to 'True'. Some code paths are unreachable. • MAJOR • View issue
Location:
sonar-scanner-dotnet/CSharpProject/SomeConsoleApplication/Program.cs:9Why is this an issue?
Conditional expressions which are always
trueorfalsecan lead to unreachable code.What changed
This hunk removes the always-true conditional expression (
var iAmTrue = true; if (iAmTrue) { ... } else { ... }) and replaces it with justConsole.WriteLine("true");. The variableiAmTruewas alwaystrue, making the condition always evaluate toTrueand theelsebranch (containingConsole.WriteLine("false")) unreachable. By removing the unnecessary variable and conditional, the unreachable code path is eliminated, fixing the bug where the condition always evaluated to true.python:PrintStatementUsage - Replace print statement by built-in function. • MAJOR • View issue
Location:
sonar-scanner/src/python/fortune.py:92Why is this an issue?
The
printstatement was removed in Python 3.0. The built-in function should be used instead.What changed
Replaces the Python 2-style
printstatement (print get(sys.argv[1])) with the Python 3-compatible built-inprint()function call (print(get(sys.argv[1]))), resolving the code smell about using the deprecated print statement syntax.python:S125 - Remove this commented out code. • MAJOR • View issue 1
python:S125 - Remove this commented out code. • MAJOR • View issue 2
Location:
sonar-scanner/src/python/letters.py:73Why is this an issue?
Commented-out code distracts the focus from the actual executed code. It creates a noise that increases maintenance code. And because it is never executed, it quickly becomes out of date and invalid.
What changed
This hunk removes the commented-out code
#print possibilitiesat line 86 of letters.py. The static analysis rule flags commented-out code as a code smell because it adds maintenance burden and distracts from the actual logic. Deleting it resolves the warning about commented-out code at that location. This also addresses any additional commented-out code warnings in the same file, as the removal eliminates the debugging comment that was flagged by the scanner.SonarQube Remediation Agent uses AI. Check for mistakes.