Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SonarLint issues #89

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,7 +39,7 @@ public SourceLine[] getLines(final InputStream inputStream, final Charset charse
final List<SourceLine> 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;
Expand All @@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends JSONRulesDefinition> implements ReportIssueSplittable<T> {

Expand All @@ -48,7 +47,7 @@ public Map<T, List<ReportIssue>> split(List<ReportIssue> issues, ActiveRules rul
List<String> rulesForRepo = rules.findByRepository(def.getRepositoryKey()).stream()
.map(ActiveRule::ruleKey)
.map(RuleKey::rule)
.collect(Collectors.toList());
.toList();
activeRules.put(def, rulesForRepo);
});
for (ReportIssue issue : issues) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -43,7 +42,7 @@ public String[] getFileSuffixes() {
.stream()
.map(String::trim)
.filter(StringUtils::isNotBlank)
.collect(Collectors.toList());
.toList();
final List<String> filesSuffixes = providedFilesSuffixes.isEmpty() ? FILE_SUFFIXES : providedFilesSuffixes;
return filesSuffixes.stream().toArray(String[]::new);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class MobSFScanSensor implements Sensor {

Expand Down Expand Up @@ -74,7 +73,7 @@ public void describe(SensorDescriptor sensorDescriptor) {
public void execute(SensorContext sensorContext) {
String output = runner.run();
List<MobSFScanIssue> issues = parser.parse(output);
List<ReportIssue> reportIssues = mapper.map(issues).stream().collect(Collectors.toList());
List<ReportIssue> reportIssues = mapper.map(issues).stream().toList();
Map<MobSFScanRulesDefinition, List<ReportIssue>> splitReportIssues = splitter.split(reportIssues, sensorContext.activeRules());
ReportIssueRecorder issueRecorder = new ReportIssueRecorder();
splitReportIssues.forEach((rulesDefinition, splitIssues) -> issueRecorder.recordIssues(splitIssues, rulesDefinition.getRepositoryKey(), sensorContext));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -51,7 +50,7 @@ protected List<MobSFScanIssue> perform(String input) throws Exception {
.entrySet()
.stream()
.map(MobSFScanIssue::new)
.collect(Collectors.toList());
.toList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private static List<XcodeTestGroup> mapping(ActionTestableSummary summary) {
List<ActionTestSummaryGroup> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -41,7 +39,7 @@ public XcodeTestGroup(final ActionTestSummary parent, final ActionTestSummaryGro
this.testCases = metadata
.stream()
.map(XcodeTestCase::new)
.collect(Collectors.toList());
.toList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -50,7 +49,7 @@ protected List<ActionTestableSummary> perform(String input) throws Exception {
return objectMapper.readValue(input, ActionTestPlanRunSummaries.class)
.summaries.stream()
.flatMap(testPlanRunSummary -> testPlanRunSummary.testableSummaries.stream())
.collect(Collectors.toList());
.toList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -43,7 +42,7 @@ public String[] getFileSuffixes() {
.stream()
.map(String::trim)
.filter(StringUtils::isNotBlank)
.collect(Collectors.toList());
.toList();
final List<String> filesSuffixes = providedFilesSuffixes.isEmpty() ? FILE_SUFFIXES : providedFilesSuffixes;
return filesSuffixes.stream().toArray(String[]::new);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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<ReportIssue> reportIssues = new ArrayList<>(mapper.map(issues));
ReportIssueRecorder issueRecorder = new ReportIssueRecorder();
issueRecorder.recordIssues(reportIssues, rulesDefinition.getRepositoryKey(), sensorContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -70,8 +69,8 @@ public void execute(SensorContext sensorContext) {
List<SwiftLintIssue> issues = outputs.stream()
.map(parser::parse)
.flatMap(List::stream)
.collect(Collectors.toList());
List<ReportIssue> reportIssues = mapper.map(issues).stream().collect(Collectors.toList());
.toList();
List<ReportIssue> reportIssues = mapper.map(issues).stream().toList();
ReportIssueRecorder issueRecorder = new ReportIssueRecorder();
issueRecorder.recordIssues(reportIssues, rulesDefinition.getRepositoryKey(), sensorContext);
}
Expand Down