From 4610a5af045a112a323dbbd3535b04d115eae928 Mon Sep 17 00:00:00 2001 From: "sonarqube-agent[bot]" <210722872+sonarqube-agent[bot]@users.noreply.github.com> Date: Sun, 17 May 2026 05:04:56 +0000 Subject: [PATCH] fix: Address 5 SonarQube issues 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) --- .../sonarsource/ruby/converter/AstNode.java | 2 +- .../visitor/AssignmentVisitorTest.java | 4 +- .../rubocop/RuboCopSensorTest.java | 75 +++++++++++-------- .../ruby/plugin/RubySensorTest.java | 2 +- .../ruby/plugin/SimpleCovSensorTest.java | 4 +- 5 files changed, 51 insertions(+), 36 deletions(-) diff --git a/sonar-ruby-plugin/src/main/java/org/sonarsource/ruby/converter/AstNode.java b/sonar-ruby-plugin/src/main/java/org/sonarsource/ruby/converter/AstNode.java index 737e267..9a07780 100644 --- a/sonar-ruby-plugin/src/main/java/org/sonarsource/ruby/converter/AstNode.java +++ b/sonar-ruby-plugin/src/main/java/org/sonarsource/ruby/converter/AstNode.java @@ -36,5 +36,5 @@ public interface AstNode { IRubyObject node(); - List availableAttributes(); + List availableAttributes(); } diff --git a/sonar-ruby-plugin/src/test/java/org/sonarsource/ruby/converter/visitor/AssignmentVisitorTest.java b/sonar-ruby-plugin/src/test/java/org/sonarsource/ruby/converter/visitor/AssignmentVisitorTest.java index 5cb9f8d..2a12f6f 100644 --- a/sonar-ruby-plugin/src/test/java/org/sonarsource/ruby/converter/visitor/AssignmentVisitorTest.java +++ b/sonar-ruby-plugin/src/test/java/org/sonarsource/ruby/converter/visitor/AssignmentVisitorTest.java @@ -53,8 +53,8 @@ void test() throws Exception { @Test void self_assignment() throws Exception { - VariableDeclarationTree var = (VariableDeclarationTree) rubyStatement("a = a"); - assertTree(var.identifier()).isEquivalentTo(var.initializer()); + VariableDeclarationTree varDecl = (VariableDeclarationTree) rubyStatement("a = a"); + assertTree(varDecl.identifier()).isEquivalentTo(varDecl.initializer()); AssignmentExpressionTree tree = (AssignmentExpressionTree) rubyStatement("A = 1\nA = A").children().get(1); assertTree(tree.leftHandSide()).isEquivalentTo(tree.statementOrExpression()); diff --git a/sonar-ruby-plugin/src/test/java/org/sonarsource/ruby/externalreport/rubocop/RuboCopSensorTest.java b/sonar-ruby-plugin/src/test/java/org/sonarsource/ruby/externalreport/rubocop/RuboCopSensorTest.java index a3550dc..439a515 100644 --- a/sonar-ruby-plugin/src/test/java/org/sonarsource/ruby/externalreport/rubocop/RuboCopSensorTest.java +++ b/sonar-ruby-plugin/src/test/java/org/sonarsource/ruby/externalreport/rubocop/RuboCopSensorTest.java @@ -71,37 +71,37 @@ void issues_with_sonarqube() throws IOException { List externalIssues = executeSensorImporting("rubocop-report.json"); assertThat(externalIssues).hasSize(4); - ExternalIssue first = externalIssues.get(0); - assertThat(first.primaryLocation().inputComponent().key()).isEqualTo("rubocop-project:useless-assignment.rb"); - assertThat(first.ruleKey()).hasToString("external_rubocop:Lint/UselessAssignment"); - assertThat(first.type()).isEqualTo(RuleType.CODE_SMELL); - assertThat(first.severity()).isEqualTo(Severity.MAJOR); - assertThat(first.primaryLocation().message()).isEqualTo("Lint/UselessAssignment: Useless assignment to variable - `param`."); - assertThat(location(first)).isEqualTo("from line 3 offset 2 to line 3 offset 7"); + assertExternalIssue(externalIssues.get(0), + "rubocop-project:useless-assignment.rb", + "external_rubocop:Lint/UselessAssignment", + RuleType.CODE_SMELL, + Severity.MAJOR, + "Lint/UselessAssignment: Useless assignment to variable - `param`.", + "from line 3 offset 2 to line 3 offset 7"); - ExternalIssue second = externalIssues.get(1); - assertThat(second.primaryLocation().inputComponent().key()).isEqualTo("rubocop-project:useless-assignment.rb"); - assertThat(first.ruleKey()).hasToString("external_rubocop:Lint/UselessAssignment"); - assertThat(first.type()).isEqualTo(RuleType.CODE_SMELL); - assertThat(first.severity()).isEqualTo(Severity.MAJOR); - assertThat(first.primaryLocation().message()).isEqualTo("Lint/UselessAssignment: Useless assignment to variable - `param`."); - assertThat(location(second)).isEqualTo("from line 130 offset 2 to line 130 offset 7"); - - ExternalIssue third = externalIssues.get(2); - assertThat(third.primaryLocation().inputComponent().key()).isEqualTo("rubocop-project:yaml-issue.rb"); - assertThat(third.ruleKey()).hasToString("external_rubocop:Security/YAMLLoad"); - assertThat(third.type()).isEqualTo(RuleType.VULNERABILITY); - assertThat(third.severity()).isEqualTo(Severity.MAJOR); - assertThat(third.primaryLocation().message()).isEqualTo("Security/YAMLLoad: Prefer using `YAML.safe_load` over `YAML.load`."); - assertThat(location(third)).isEqualTo("from line 2 offset 7 to line 2 offset 11"); - - ExternalIssue fourth = externalIssues.get(3); - assertThat(fourth.primaryLocation().inputComponent().key()).isEqualTo("rubocop-project:yaml-issue.rb"); - assertThat(fourth.ruleKey()).hasToString("external_rubocop:Style/StringLiterals"); - assertThat(fourth.type()).isEqualTo(RuleType.CODE_SMELL); - assertThat(fourth.severity()).isEqualTo(Severity.MINOR); - assertThat(fourth.primaryLocation().message()).isEqualTo("Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols."); - assertThat(location(fourth)).isEqualTo("from line 2 offset 12 to line 2 offset 21"); + assertExternalIssue(externalIssues.get(1), + "rubocop-project:useless-assignment.rb", + "external_rubocop:Lint/UselessAssignment", + RuleType.CODE_SMELL, + Severity.MAJOR, + "Lint/UselessAssignment: Useless assignment to variable - `param`.", + "from line 130 offset 2 to line 130 offset 7"); + + assertExternalIssue(externalIssues.get(2), + "rubocop-project:yaml-issue.rb", + "external_rubocop:Security/YAMLLoad", + RuleType.VULNERABILITY, + Severity.MAJOR, + "Security/YAMLLoad: Prefer using `YAML.safe_load` over `YAML.load`.", + "from line 2 offset 7 to line 2 offset 11"); + + assertExternalIssue(externalIssues.get(3), + "rubocop-project:yaml-issue.rb", + "external_rubocop:Style/StringLiterals", + RuleType.CODE_SMELL, + Severity.MINOR, + "Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.", + "from line 2 offset 12 to line 2 offset 21"); assertNoErrorWarnDebugLogs(logTester); } @@ -231,6 +231,21 @@ private static String language(Path file) { return path.substring(path.lastIndexOf('.') + 1); } + private static void assertExternalIssue(ExternalIssue issue, + String expectedComponentKey, + String expectedRuleKey, + RuleType expectedType, + Severity expectedSeverity, + String expectedMessage, + String expectedLocation) { + assertThat(issue.primaryLocation().inputComponent().key()).isEqualTo(expectedComponentKey); + assertThat(issue.ruleKey()).hasToString(expectedRuleKey); + assertThat(issue.type()).isEqualTo(expectedType); + assertThat(issue.severity()).isEqualTo(expectedSeverity); + assertThat(issue.primaryLocation().message()).isEqualTo(expectedMessage); + assertThat(location(issue)).isEqualTo(expectedLocation); + } + private static String location(ExternalIssue issue) { TextRange range = issue.primaryLocation().textRange(); if (range == null) { diff --git a/sonar-ruby-plugin/src/test/java/org/sonarsource/ruby/plugin/RubySensorTest.java b/sonar-ruby-plugin/src/test/java/org/sonarsource/ruby/plugin/RubySensorTest.java index add6bcb..c7173fd 100644 --- a/sonar-ruby-plugin/src/test/java/org/sonarsource/ruby/plugin/RubySensorTest.java +++ b/sonar-ruby-plugin/src/test/java/org/sonarsource/ruby/plugin/RubySensorTest.java @@ -45,7 +45,7 @@ class C assertThat(context.highlightingTypeAt(inputFile.key(), 1, 5)).isEmpty(); // FIXME - //assertThat(logTester.logs()).contains("1 source files to be analyzed"); + // } @Test diff --git a/sonar-ruby-plugin/src/test/java/org/sonarsource/ruby/plugin/SimpleCovSensorTest.java b/sonar-ruby-plugin/src/test/java/org/sonarsource/ruby/plugin/SimpleCovSensorTest.java index 1f7d855..0501e14 100644 --- a/sonar-ruby-plugin/src/test/java/org/sonarsource/ruby/plugin/SimpleCovSensorTest.java +++ b/sonar-ruby-plugin/src/test/java/org/sonarsource/ruby/plugin/SimpleCovSensorTest.java @@ -200,8 +200,8 @@ void log_when_invalid_format() throws IOException { SensorContextTester context = getSensorContext("invalid_resultset.json", "file1.rb"); sensor.execute(context); - String expectedMessage = String.format( - "Cannot read coverage report file, expecting standard SimpleCov JSON formatter output: 'invalid_resultset.json'"); + String expectedMessage = + "Cannot read coverage report file, expecting standard SimpleCov JSON formatter output: 'invalid_resultset.json'"; assertThat(logTester.logs()).contains(expectedMessage); }