From c7131f244832a0ed4be27f5d3883c4303be8f6c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gae=CC=88l=20Foppolo?= Date: Fri, 26 Apr 2024 15:19:29 +0200 Subject: [PATCH] Fix SonarLint issues --- .../apple/commons/SourceLinesProvider.java | 10 +++++++++- .../commons/issues/ReportIssueSplitter.java | 3 +-- .../insideapp/sonarqube/objc/ObjectiveC.java | 3 +-- .../apple/mobsfscan/MobSFScanSensor.java | 3 +-- .../parser/MobSFScanReportParser.java | 3 +-- .../apple/xcode/tests/XcodeTestsSensor.java | 1 - .../xcode/tests/mapper/XcodeTestsMapper.java | 2 +- .../xcode/tests/models/XcodeTestGroup.java | 4 +--- .../xcode/tests/parser/XcodeTestsParser.java | 3 +-- .../warnings/models/XcodeWarningType.java | 18 +++++++++--------- .../fr/insideapp/sonarqube/swift/Swift.java | 3 +-- .../issues/periphery/PeripherySensor.java | 3 +-- .../issues/swiftlint/SwiftLintSensor.java | 5 ++--- 13 files changed, 29 insertions(+), 32 deletions(-) diff --git a/commons/src/main/java/fr/insideapp/sonarqube/apple/commons/SourceLinesProvider.java b/commons/src/main/java/fr/insideapp/sonarqube/apple/commons/SourceLinesProvider.java index 48e9f63c..b3e7877f 100644 --- a/commons/src/main/java/fr/insideapp/sonarqube/apple/commons/SourceLinesProvider.java +++ b/commons/src/main/java/fr/insideapp/sonarqube/apple/commons/SourceLinesProvider.java @@ -22,6 +22,7 @@ import org.sonar.api.utils.log.Loggers; import java.io.BufferedReader; +import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.Charset; @@ -38,7 +39,7 @@ public SourceLine[] getLines(final InputStream inputStream, final Charset charse final List sourceLines = new ArrayList<>(); try (final BufferedReader bufferedReader = new BufferedReader( - new InputStreamReader(new BOMInputStream(inputStream, false), charset))) { + new InputStreamReader(bomInputStream(inputStream), charset))) { int totalLines = 1; int global = 0; int count = 0; @@ -62,4 +63,11 @@ public SourceLine[] getLines(final InputStream inputStream, final Charset charse return sourceLines.toArray(new SourceLine[0]); } + public BOMInputStream bomInputStream(final InputStream inputStream) throws IOException { + return BOMInputStream.builder() + .setInputStream(inputStream) + .setInclude(false) + .get(); + } + } diff --git a/commons/src/main/java/fr/insideapp/sonarqube/apple/commons/issues/ReportIssueSplitter.java b/commons/src/main/java/fr/insideapp/sonarqube/apple/commons/issues/ReportIssueSplitter.java index bfb7c23a..1b4f3b51 100644 --- a/commons/src/main/java/fr/insideapp/sonarqube/apple/commons/issues/ReportIssueSplitter.java +++ b/commons/src/main/java/fr/insideapp/sonarqube/apple/commons/issues/ReportIssueSplitter.java @@ -27,7 +27,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; public abstract class ReportIssueSplitter implements ReportIssueSplittable { @@ -48,7 +47,7 @@ public Map> split(List issues, ActiveRules rul List rulesForRepo = rules.findByRepository(def.getRepositoryKey()).stream() .map(ActiveRule::ruleKey) .map(RuleKey::rule) - .collect(Collectors.toList()); + .toList(); activeRules.put(def, rulesForRepo); }); for (ReportIssue issue : issues) { diff --git a/objc-lang/src/main/java/fr/insideapp/sonarqube/objc/ObjectiveC.java b/objc-lang/src/main/java/fr/insideapp/sonarqube/objc/ObjectiveC.java index 741e8f1b..38fa62ca 100644 --- a/objc-lang/src/main/java/fr/insideapp/sonarqube/objc/ObjectiveC.java +++ b/objc-lang/src/main/java/fr/insideapp/sonarqube/objc/ObjectiveC.java @@ -24,7 +24,6 @@ import java.util.Arrays; import java.util.List; -import java.util.stream.Collectors; public final class ObjectiveC extends AbstractLanguage implements LanguageTestFile { @@ -43,7 +42,7 @@ public String[] getFileSuffixes() { .stream() .map(String::trim) .filter(StringUtils::isNotBlank) - .collect(Collectors.toList()); + .toList(); final List filesSuffixes = providedFilesSuffixes.isEmpty() ? FILE_SUFFIXES : providedFilesSuffixes; return filesSuffixes.stream().toArray(String[]::new); } diff --git a/sonar-apple-plugin/src/main/java/fr/insideapp/sonarqube/apple/mobsfscan/MobSFScanSensor.java b/sonar-apple-plugin/src/main/java/fr/insideapp/sonarqube/apple/mobsfscan/MobSFScanSensor.java index 46fc429e..cf81841a 100644 --- a/sonar-apple-plugin/src/main/java/fr/insideapp/sonarqube/apple/mobsfscan/MobSFScanSensor.java +++ b/sonar-apple-plugin/src/main/java/fr/insideapp/sonarqube/apple/mobsfscan/MobSFScanSensor.java @@ -34,7 +34,6 @@ import java.util.List; import java.util.Map; -import java.util.stream.Collectors; public class MobSFScanSensor implements Sensor { @@ -74,7 +73,7 @@ public void describe(SensorDescriptor sensorDescriptor) { public void execute(SensorContext sensorContext) { String output = runner.run(); List issues = parser.parse(output); - List reportIssues = mapper.map(issues).stream().collect(Collectors.toList()); + List reportIssues = mapper.map(issues).stream().toList(); Map> splitReportIssues = splitter.split(reportIssues, sensorContext.activeRules()); ReportIssueRecorder issueRecorder = new ReportIssueRecorder(); splitReportIssues.forEach((rulesDefinition, splitIssues) -> issueRecorder.recordIssues(splitIssues, rulesDefinition.getRepositoryKey(), sensorContext)); diff --git a/sonar-apple-plugin/src/main/java/fr/insideapp/sonarqube/apple/mobsfscan/parser/MobSFScanReportParser.java b/sonar-apple-plugin/src/main/java/fr/insideapp/sonarqube/apple/mobsfscan/parser/MobSFScanReportParser.java index 12913545..7c9a82e6 100644 --- a/sonar-apple-plugin/src/main/java/fr/insideapp/sonarqube/apple/mobsfscan/parser/MobSFScanReportParser.java +++ b/sonar-apple-plugin/src/main/java/fr/insideapp/sonarqube/apple/mobsfscan/parser/MobSFScanReportParser.java @@ -25,7 +25,6 @@ import org.sonar.api.scanner.ScannerSide; import java.util.List; -import java.util.stream.Collectors; import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES; @@ -51,7 +50,7 @@ protected List perform(String input) throws Exception { .entrySet() .stream() .map(MobSFScanIssue::new) - .collect(Collectors.toList()); + .toList(); } } \ No newline at end of file diff --git a/sonar-apple-plugin/src/main/java/fr/insideapp/sonarqube/apple/xcode/tests/XcodeTestsSensor.java b/sonar-apple-plugin/src/main/java/fr/insideapp/sonarqube/apple/xcode/tests/XcodeTestsSensor.java index a625c99e..3283f546 100644 --- a/sonar-apple-plugin/src/main/java/fr/insideapp/sonarqube/apple/xcode/tests/XcodeTestsSensor.java +++ b/sonar-apple-plugin/src/main/java/fr/insideapp/sonarqube/apple/xcode/tests/XcodeTestsSensor.java @@ -38,7 +38,6 @@ import java.util.Collection; import java.util.List; import java.util.Objects; -import java.util.stream.Collectors; public class XcodeTestsSensor implements Sensor { diff --git a/sonar-apple-plugin/src/main/java/fr/insideapp/sonarqube/apple/xcode/tests/mapper/XcodeTestsMapper.java b/sonar-apple-plugin/src/main/java/fr/insideapp/sonarqube/apple/xcode/tests/mapper/XcodeTestsMapper.java index 5383d356..4d5cdd8a 100644 --- a/sonar-apple-plugin/src/main/java/fr/insideapp/sonarqube/apple/xcode/tests/mapper/XcodeTestsMapper.java +++ b/sonar-apple-plugin/src/main/java/fr/insideapp/sonarqube/apple/xcode/tests/mapper/XcodeTestsMapper.java @@ -58,7 +58,7 @@ private static List mapping(ActionTestableSummary summary) { List summaryGroups = pair.getValue().groups .stream() .filter(summaryGroup -> Objects.nonNull(summaryGroup.tests)) // remove null values - .collect(Collectors.toList()); + .toList(); // we'll loop over each groups of the current group // to determine if this is the last "group" level // kind of flattening operation, since we can have an infinite level of nesting diff --git a/sonar-apple-plugin/src/main/java/fr/insideapp/sonarqube/apple/xcode/tests/models/XcodeTestGroup.java b/sonar-apple-plugin/src/main/java/fr/insideapp/sonarqube/apple/xcode/tests/models/XcodeTestGroup.java index 62f008ca..ce3ce193 100644 --- a/sonar-apple-plugin/src/main/java/fr/insideapp/sonarqube/apple/xcode/tests/models/XcodeTestGroup.java +++ b/sonar-apple-plugin/src/main/java/fr/insideapp/sonarqube/apple/xcode/tests/models/XcodeTestGroup.java @@ -22,8 +22,6 @@ import fr.insideapp.sonarqube.apple.xcode.tests.parser.models.ActionTestSummaryGroup; import java.util.List; -import java.util.stream.Collectors; - public final class XcodeTestGroup { @@ -41,7 +39,7 @@ public XcodeTestGroup(final ActionTestSummary parent, final ActionTestSummaryGro this.testCases = metadata .stream() .map(XcodeTestCase::new) - .collect(Collectors.toList()); + .toList(); } } diff --git a/sonar-apple-plugin/src/main/java/fr/insideapp/sonarqube/apple/xcode/tests/parser/XcodeTestsParser.java b/sonar-apple-plugin/src/main/java/fr/insideapp/sonarqube/apple/xcode/tests/parser/XcodeTestsParser.java index dc425f82..e72927ba 100644 --- a/sonar-apple-plugin/src/main/java/fr/insideapp/sonarqube/apple/xcode/tests/parser/XcodeTestsParser.java +++ b/sonar-apple-plugin/src/main/java/fr/insideapp/sonarqube/apple/xcode/tests/parser/XcodeTestsParser.java @@ -25,7 +25,6 @@ import org.sonar.api.scanner.ScannerSide; import java.util.List; -import java.util.stream.Collectors; import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES; @@ -50,7 +49,7 @@ protected List perform(String input) throws Exception { return objectMapper.readValue(input, ActionTestPlanRunSummaries.class) .summaries.stream() .flatMap(testPlanRunSummary -> testPlanRunSummary.testableSummaries.stream()) - .collect(Collectors.toList()); + .toList(); } } \ No newline at end of file diff --git a/sonar-apple-plugin/src/main/java/fr/insideapp/sonarqube/apple/xcode/warnings/models/XcodeWarningType.java b/sonar-apple-plugin/src/main/java/fr/insideapp/sonarqube/apple/xcode/warnings/models/XcodeWarningType.java index e139cb2c..ffaefe54 100644 --- a/sonar-apple-plugin/src/main/java/fr/insideapp/sonarqube/apple/xcode/warnings/models/XcodeWarningType.java +++ b/sonar-apple-plugin/src/main/java/fr/insideapp/sonarqube/apple/xcode/warnings/models/XcodeWarningType.java @@ -36,19 +36,19 @@ public static XcodeWarningType builder(String type) { switch (type) { case "Swift Compiler Warning": return SWIFT_COMPILER; - case "Format String Issue": - case "Semantic Issue": - case "Value Conversion Issue": - case "Lexical or Preprocessor Issue": - case "Nullability Issue": + case "Format String Issue", + "Semantic Issue", + "Value Conversion Issue", + "Lexical or Preprocessor Issue", + "Nullability Issue": return CLANG_COMPILER; - case "Deprecations": - case "Deprecation": + case "Deprecations", + "Deprecation": return DEPRECATION; case "No-usage": return UNUSED; - case "Warning": - case "Target Integrity": + case "Warning", + "Target Integrity": return PROJECT; default: return NOTE; diff --git a/swift-lang/src/main/java/fr/insideapp/sonarqube/swift/Swift.java b/swift-lang/src/main/java/fr/insideapp/sonarqube/swift/Swift.java index 64b8405d..12fbd43d 100644 --- a/swift-lang/src/main/java/fr/insideapp/sonarqube/swift/Swift.java +++ b/swift-lang/src/main/java/fr/insideapp/sonarqube/swift/Swift.java @@ -24,7 +24,6 @@ import java.util.Arrays; import java.util.List; -import java.util.stream.Collectors; public final class Swift extends AbstractLanguage implements LanguageTestFile { @@ -43,7 +42,7 @@ public String[] getFileSuffixes() { .stream() .map(String::trim) .filter(StringUtils::isNotBlank) - .collect(Collectors.toList()); + .toList(); final List filesSuffixes = providedFilesSuffixes.isEmpty() ? FILE_SUFFIXES : providedFilesSuffixes; return filesSuffixes.stream().toArray(String[]::new); } diff --git a/swift-lang/src/main/java/fr/insideapp/sonarqube/swift/issues/periphery/PeripherySensor.java b/swift-lang/src/main/java/fr/insideapp/sonarqube/swift/issues/periphery/PeripherySensor.java index e7854dda..03e470ab 100644 --- a/swift-lang/src/main/java/fr/insideapp/sonarqube/swift/issues/periphery/PeripherySensor.java +++ b/swift-lang/src/main/java/fr/insideapp/sonarqube/swift/issues/periphery/PeripherySensor.java @@ -33,7 +33,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; -import java.util.stream.Collectors; public class PeripherySensor implements Sensor { @@ -73,7 +72,7 @@ public void execute(SensorContext sensorContext) { .parse(output) .stream() .filter(issue -> Objects.nonNull(issue.location)) // remove null values - .collect(Collectors.toList()); + .toList(); List reportIssues = new ArrayList<>(mapper.map(issues)); ReportIssueRecorder issueRecorder = new ReportIssueRecorder(); issueRecorder.recordIssues(reportIssues, rulesDefinition.getRepositoryKey(), sensorContext); diff --git a/swift-lang/src/main/java/fr/insideapp/sonarqube/swift/issues/swiftlint/SwiftLintSensor.java b/swift-lang/src/main/java/fr/insideapp/sonarqube/swift/issues/swiftlint/SwiftLintSensor.java index d6ada3fc..ad5625e4 100644 --- a/swift-lang/src/main/java/fr/insideapp/sonarqube/swift/issues/swiftlint/SwiftLintSensor.java +++ b/swift-lang/src/main/java/fr/insideapp/sonarqube/swift/issues/swiftlint/SwiftLintSensor.java @@ -31,7 +31,6 @@ import org.sonar.api.batch.sensor.SensorDescriptor; import java.util.List; -import java.util.stream.Collectors; public class SwiftLintSensor implements Sensor { @@ -70,8 +69,8 @@ public void execute(SensorContext sensorContext) { List issues = outputs.stream() .map(parser::parse) .flatMap(List::stream) - .collect(Collectors.toList()); - List reportIssues = mapper.map(issues).stream().collect(Collectors.toList()); + .toList(); + List reportIssues = mapper.map(issues).stream().toList(); ReportIssueRecorder issueRecorder = new ReportIssueRecorder(); issueRecorder.recordIssues(reportIssues, rulesDefinition.getRepositoryKey(), sensorContext); }