SONARRUBY-164 fix: resolve 5 SonarQube issues across Ruby plugin#148
SONARRUBY-164 fix: resolve 5 SonarQube issues across Ruby plugin#148sonarqube-agent[bot] wants to merge 1 commit into
Conversation
Fixed issues: - AZl5MuDuGyUqE6OUiTjy for java:S6213 rule - AZl5MuCmGyUqE6OUiTjm for java:S3740 rule - AZl5MuEgGyUqE6OUiTj- for java:S125 rule - AZl5MuEUGyUqE6OUiTj9 for java:S3457 rule - AZl5MuE3GyUqE6OUiTkE for java:S5961 rule Generated by SonarQube Agent (task: d9439ec0-c595-4e4a-beea-856602523eac)
Summary
Five SonarQube code quality fixes across the Ruby plugin:
All changes are in test code and interfaces—no production logic is modified. What reviewers should knowKey reviewer observations:
|
There was a problem hiding this comment.
LGTM! ✅
Clean PR. The RuboCopSensorTest refactoring is the most notable change: the assertExternalIssue() helper is well-structured and, as a side effect, fixes a latent copy-paste bug in the second-issue block where first.ruleKey(), first.type(), first.severity(), and first.primaryLocation().message() were all asserting against the wrong object. The bug was masked because both issues share the same rule and severity values. All other changes are straightforward and correct.
|
|
This PR is stale because it has been open 7 days with no activity. If there is no activity in the next 7 days it will be closed automatically |





This PR fixes 5 MAJOR SonarQube issues including adding generic type parameters, renaming a restricted identifier, reducing excessive assertions in tests, removing commented-out code, and eliminating unnecessary String.format calls. These changes improve code quality, maintainability, and runtime safety by following Java best practices and reducing technical debt.
View Project in SonarCloud
Fixed Issues
java:S3740 - Provide the parametrized type for this generic. • MAJOR • View issue
Location:
sonar-ruby-plugin/src/main/java/org/sonarsource/ruby/converter/AstNode.java:39Why is this an issue?
A generic type is a generic class or interface that is parameterized over types. For example,
java.util.Listhas one type parameter: the type of its elements.What changed
This hunk adds the type parameter
<Object>to the rawListtype on line 39 of AstNode.java. The static analysis warning flagged the use of a raw generic type (Listwithout type arguments), which prevents compile-time type checking and could lead to ClassCastException at runtime. By parameterizing it asList<Object>, the generic type is no longer used raw, resolving the code smell.java:S6213 - Rename this variable to not match a restricted identifier. • MAJOR • View issue
Location:
sonar-ruby-plugin/src/test/java/org/sonarsource/ruby/converter/visitor/AssignmentVisitorTest.java:56Why is this an issue?
Even if it is technically possible, Restricted Identifiers should not be used as identifiers. This is only possible for compatibility reasons, using it in Java code is confusing and should be avoided.
What changed
This hunk renames the variable
vartovarDeclin the test file. The variable namevaris a restricted identifier in Java (used for local variable type inference since Java 10), and using it as a variable name is confusing and flagged as a code smell. By renaming it tovarDecl, the code avoids using a restricted identifier as a variable name, resolving the static analysis warning.java:S5961 - Refactor this method to reduce the number of assertions from 26 to less than 25. • MAJOR • View issue
Location:
sonar-ruby-plugin/src/test/java/org/sonarsource/ruby/externalreport/rubocop/RuboCopSensorTest.java:70Why is this an issue?
A common good practice is to write test methods targeting only one logical concept, that can only fail for one reason.
What changed
Replaces 6 inline assertions for the first external issue with a single call to the extracted helper method
assertExternalIssue. This reduces the assertion count in theissues_with_sonarqubetest method, helping bring the total number of assertions from 26 down below the threshold of 25.java:S125 - This block of commented-out lines of code should be removed. • MAJOR • View issue
Location:
sonar-ruby-plugin/src/test/java/org/sonarsource/ruby/plugin/RubySensorTest.java:48Why 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 line of code
assertThat(logTester.logs()).contains("1 source files to be analyzed");and replaces it with just an empty comment. This addresses the code smell about commented-out code that should be removed, as the static analysis rule (java:S125) flags blocks of commented-out lines of code that distract from actual executed code and create maintenance noise. By removing the commented-out assertion, the line no longer contains commented-out code that could become stale or misleading.java:S3457 - String contains no format specifiers. • MAJOR • View issue
Location:
sonar-ruby-plugin/src/test/java/org/sonarsource/ruby/plugin/SimpleCovSensorTest.java:203Why is this an issue?
A
printf--style format string is a string that contains placeholders, usually represented by special characters such as "%s" or "{}", depending on the technology in use. These placeholders are replaced by values when the string is printed or logged.What changed
This hunk removes the unnecessary
String.format()call that wrapped a string literal containing no format specifiers. The original code usedString.format("Cannot read coverage report file...")but the string had no placeholders like%sor%d, making theString.format()call pointless. The fix replaces it with a simple string assignment, eliminating the code smell flagged by the static analysis rule about format strings containing no format specifiers.SonarQube Remediation Agent uses AI. Check for mistakes.