diff --git a/build-logic b/build-logic index 586c6435..a2bbe6c8 160000 --- a/build-logic +++ b/build-logic @@ -1 +1 @@ -Subproject commit 586c643589c7c79b4a394d04095106ddf44d64c1 +Subproject commit a2bbe6c8d29755b7d6d147dc4fff391a76177ad6 diff --git a/build.gradle b/build.gradle index eff6c1c2..031e14c9 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,6 @@ plugins { id 'com.jfrog.artifactory' version '4.28.2' id 'org.sonarqube' version '6.0.1.5171' id 'de.thetaphi.forbiddenapis' version '3.0' apply false - id 'com.diffplug.spotless' version '6.15.0' } allprojects { @@ -51,8 +50,6 @@ subprojects { // do not publish to Artifactory by default artifactoryPublish.skip = true - apply plugin: 'com.diffplug.spotless' - configurations { // include compileOnly dependencies during test testCompile.extendsFrom compileOnly @@ -68,18 +65,6 @@ subprojects { } } - // license updater - spotless { - java { - targetExclude "**/src/test/resources/**", "**/build/**", "its/sources/**", "its/plugin/projects/**" - licenseHeaderFile(rootProject.file("LICENSE_HEADER")).updateYearWithLatest(true) - } - format("javaMisc") { - target("src/**/package-info.java") - licenseHeaderFile(rootProject.file("LICENSE_HEADER"), "(@javax.annotation|@ParametersAreNonnullByDefault)").updateYearWithLatest(true) - } - } - publishing { publications { mavenJava(MavenPublication) { diff --git a/its/plugin/build.gradle.kts b/its/plugin/build.gradle.kts index e9fe1ed1..d9bf1938 100644 --- a/its/plugin/build.gradle.kts +++ b/its/plugin/build.gradle.kts @@ -1,5 +1,6 @@ plugins { id("org.sonarsource.cloud-native.java-conventions") + id("org.sonarsource.cloud-native.code-style-conventions") id("org.sonarsource.cloud-native.integration-test") } diff --git a/its/plugin/src/integrationTest/java/org/sonarsource/slang/CoverageTest.java b/its/plugin/src/integrationTest/java/org/sonarsource/slang/CoverageTest.java index 1bcb22ce..36bab640 100644 --- a/its/plugin/src/integrationTest/java/org/sonarsource/slang/CoverageTest.java +++ b/its/plugin/src/integrationTest/java/org/sonarsource/slang/CoverageTest.java @@ -17,14 +17,12 @@ package org.sonarsource.slang; import com.sonar.orchestrator.build.SonarScanner; -import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import static java.nio.charset.StandardCharsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; public class CoverageTest extends TestBase { diff --git a/its/plugin/src/integrationTest/java/org/sonarsource/slang/ExternalReportTest.java b/its/plugin/src/integrationTest/java/org/sonarsource/slang/ExternalReportTest.java index 959e9876..084d49c7 100644 --- a/its/plugin/src/integrationTest/java/org/sonarsource/slang/ExternalReportTest.java +++ b/its/plugin/src/integrationTest/java/org/sonarsource/slang/ExternalReportTest.java @@ -17,12 +17,10 @@ package org.sonarsource.slang; import com.sonar.orchestrator.build.SonarScanner; -import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.Collections; -import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; import org.junit.Rule; @@ -33,6 +31,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; + public class ExternalReportTest extends TestBase { private static final String BASE_DIRECTORY = "projects/externalreport/"; @@ -74,8 +73,7 @@ public void golint() { "pivot.go|external_golint:Names|MAJOR|5min|line:11|don't use underscores in Go names; var ascii_lowercase should be asciiLowercase\n" + "pivot.go|external_golint:Names|MAJOR|5min|line:12|don't use underscores in Go names; var ascii_uppercase_len should be asciiUppercaseLen\n" + "pivot.go|external_golint:Names|MAJOR|5min|line:13|don't use underscores in Go names; var ascii_lowercase_len should be asciiLowercaseLen\n" + - "pivot.go|external_golint:Names|MAJOR|5min|line:14|don't use underscores in Go names; var ascii_allowed should be asciiAllowed" - ); + "pivot.go|external_golint:Names|MAJOR|5min|line:14|don't use underscores in Go names; var ascii_allowed should be asciiAllowed"); } @Test diff --git a/its/plugin/src/integrationTest/java/org/sonarsource/slang/MeasuresTest.java b/its/plugin/src/integrationTest/java/org/sonarsource/slang/MeasuresTest.java index 165d3605..5fc09758 100644 --- a/its/plugin/src/integrationTest/java/org/sonarsource/slang/MeasuresTest.java +++ b/its/plugin/src/integrationTest/java/org/sonarsource/slang/MeasuresTest.java @@ -16,9 +16,7 @@ */ package org.sonarsource.slang; -import java.util.List; import org.junit.Test; -import org.sonarqube.ws.Issues; import static org.assertj.core.api.Assertions.assertThat; diff --git a/its/plugin/src/integrationTest/java/org/sonarsource/slang/SonarLintTest.java b/its/plugin/src/integrationTest/java/org/sonarsource/slang/SonarLintTest.java index 0a1eb700..45487701 100644 --- a/its/plugin/src/integrationTest/java/org/sonarsource/slang/SonarLintTest.java +++ b/its/plugin/src/integrationTest/java/org/sonarsource/slang/SonarLintTest.java @@ -30,7 +30,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; - import org.apache.commons.io.FileUtils; import org.assertj.core.groups.Tuple; import org.jetbrains.annotations.NotNull; @@ -98,9 +97,8 @@ public static void stop() { public void test_go() throws Exception { ClientInputFile inputFile = prepareInputFile( "package main\n" - + "func empty() {\n" // go:S1186 (empty function) - + "}\n" - ); + + "func empty() {\n" // go:S1186 (empty function) + + "}\n"); assertIssues(analyzeWithSonarLint(inputFile), tuple("go:S1186", 2, inputFile.getPath(), IssueSeverity.CRITICAL)); @@ -110,9 +108,8 @@ public void test_go() throws Exception { public void test_go_nosonar() throws Exception { ClientInputFile goInputFile = prepareInputFile( "package main\n" - + "func empty() { // NOSONAR\n" // skipped go:S1186 (empty function) - + "}\n" - ); + + "func empty() { // NOSONAR\n" // skipped go:S1186 (empty function) + + "}\n"); assertThat(analyzeWithSonarLint(goInputFile)).isEmpty(); } @@ -163,7 +160,6 @@ public Charset getCharset() { return StandardCharsets.UTF_8; } - @Override public G getClientObject() { return null; diff --git a/its/plugin/src/integrationTest/java/org/sonarsource/slang/TestBase.java b/its/plugin/src/integrationTest/java/org/sonarsource/slang/TestBase.java index 51546176..66a6a887 100644 --- a/its/plugin/src/integrationTest/java/org/sonarsource/slang/TestBase.java +++ b/its/plugin/src/integrationTest/java/org/sonarsource/slang/TestBase.java @@ -19,12 +19,8 @@ import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.SonarScanner; import java.io.File; -import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.Map; -import java.util.function.Function; -import java.util.stream.Collectors; import javax.annotation.Nullable; import org.junit.ClassRule; import org.sonarqube.ws.Issues; diff --git a/its/plugin/src/integrationTest/java/org/sonarsource/slang/TestReportTest.java b/its/plugin/src/integrationTest/java/org/sonarsource/slang/TestReportTest.java index e845b01e..9bff0403 100644 --- a/its/plugin/src/integrationTest/java/org/sonarsource/slang/TestReportTest.java +++ b/its/plugin/src/integrationTest/java/org/sonarsource/slang/TestReportTest.java @@ -27,7 +27,7 @@ public class TestReportTest extends TestBase { - private static final Path BASE_DIRECTORY = Paths.get("projects","measures"); + private static final Path BASE_DIRECTORY = Paths.get("projects", "measures"); @ClassRule public static Orchestrator orchestrator = Tests.ORCHESTRATOR; diff --git a/its/plugin/src/integrationTest/java/org/sonarsource/slang/Tests.java b/its/plugin/src/integrationTest/java/org/sonarsource/slang/Tests.java index 396689ed..eba37435 100644 --- a/its/plugin/src/integrationTest/java/org/sonarsource/slang/Tests.java +++ b/its/plugin/src/integrationTest/java/org/sonarsource/slang/Tests.java @@ -22,7 +22,6 @@ import com.sonar.orchestrator.locator.Location; import com.sonar.orchestrator.locator.MavenLocation; import java.io.File; - import org.apache.commons.lang.StringUtils; import org.junit.ClassRule; import org.junit.runner.RunWith; diff --git a/its/ruling/build.gradle.kts b/its/ruling/build.gradle.kts index 95713577..5b796fd1 100644 --- a/its/ruling/build.gradle.kts +++ b/its/ruling/build.gradle.kts @@ -1,5 +1,6 @@ plugins { id("org.sonarsource.cloud-native.java-conventions") + id("org.sonarsource.cloud-native.code-style-conventions") id("org.sonarsource.cloud-native.integration-test") } diff --git a/its/ruling/src/integrationTest/java/org/sonarsource/slang/GoRulingTest.java b/its/ruling/src/integrationTest/java/org/sonarsource/slang/GoRulingTest.java index f347578a..8cbdb5ec 100644 --- a/its/ruling/src/integrationTest/java/org/sonarsource/slang/GoRulingTest.java +++ b/its/ruling/src/integrationTest/java/org/sonarsource/slang/GoRulingTest.java @@ -30,7 +30,6 @@ import java.util.HashMap; import java.util.Map; import java.util.Scanner; - import org.apache.commons.lang.StringUtils; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -48,7 +47,6 @@ public class GoRulingTest { private static Orchestrator orchestrator; private static boolean keepSonarqubeRunning = "true".equals(System.getProperty("keepSonarqubeRunning")); - @BeforeClass public static void setUp() { OrchestratorBuilder builder = Orchestrator.builderEnv() diff --git a/settings.gradle.kts b/settings.gradle.kts index 06e67521..423fd47c 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -8,6 +8,7 @@ pluginManagement { plugins { id("com.gradle.develocity") version "3.18.2" + id("com.diffplug.blowdryerSetup") version "1.7.1" } develocity { diff --git a/sonar-go-plugin/build.gradle.kts b/sonar-go-plugin/build.gradle.kts index 25061476..1c692172 100644 --- a/sonar-go-plugin/build.gradle.kts +++ b/sonar-go-plugin/build.gradle.kts @@ -1,10 +1,11 @@ import java.text.SimpleDateFormat -import java.util.HashSet import java.util.Date +import java.util.HashSet import java.util.jar.JarInputStream plugins { id("org.sonarsource.cloud-native.java-conventions") + id("org.sonarsource.cloud-native.code-style-conventions") id("com.github.johnrengelman.shadow") version "7.1.0" } @@ -39,8 +40,12 @@ dependencies { tasks.jar { manifest { val displayVersion = - if (!project.hasProperty("buildNumber")) project.version else project.version.toString() - .substring(0, project.version.toString().lastIndexOf(".")) + " (build ${project.property("buildNumber")})" + if (!project.hasProperty("buildNumber")) { + project.version + } else { + project.version.toString() + .substring(0, project.version.toString().lastIndexOf(".")) + " (build ${project.property("buildNumber")})" + } val buildDate = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(Date()) val commitHash = providers.exec { commandLine("git", "rev-parse", "HEAD") @@ -68,7 +73,7 @@ tasks.jar { "Sonar-Version" to "6.7", "SonarLint-Supported" to "true", "Version" to "${project.version}", - "Jre-Min-Version" to "11", + "Jre-Min-Version" to "11" ) ) } @@ -109,7 +114,11 @@ publishing { } } -fun enforceJarSizeAndCheckContent(file: File, minSize: Long, maxSize: Long) { +fun enforceJarSizeAndCheckContent( + file: File, + minSize: Long, + maxSize: Long, +) { val size = file.length() if (size < minSize) { throw GradleException("${file.path} size ($size) too small. Min is $minSize") diff --git a/sonar-go-plugin/src/main/java/org/sonar/go/checks/CodeAfterJumpGoCheck.java b/sonar-go-plugin/src/main/java/org/sonar/go/checks/CodeAfterJumpGoCheck.java index d4bc7e3f..7f06a145 100644 --- a/sonar-go-plugin/src/main/java/org/sonar/go/checks/CodeAfterJumpGoCheck.java +++ b/sonar-go-plugin/src/main/java/org/sonar/go/checks/CodeAfterJumpGoCheck.java @@ -29,12 +29,12 @@ public class CodeAfterJumpGoCheck extends CodeAfterJumpCheck { @Override protected boolean isValidAfterJump(Tree tree) { return tree instanceof NativeTree && - ((NativeTree) tree).nativeKind().toString().contains(LABEL); + ((NativeTree) tree).nativeKind().toString().contains(LABEL); } @Override protected boolean shouldIgnore(Tree tree) { return tree instanceof NativeTree && - ((NativeTree) tree).nativeKind().toString().equals(SEMICOLON); + ((NativeTree) tree).nativeKind().toString().equals(SEMICOLON); } } diff --git a/sonar-go-plugin/src/main/java/org/sonar/go/checks/DuplicateBranchGoCheck.java b/sonar-go-plugin/src/main/java/org/sonar/go/checks/DuplicateBranchGoCheck.java index 51541729..7518fc9d 100644 --- a/sonar-go-plugin/src/main/java/org/sonar/go/checks/DuplicateBranchGoCheck.java +++ b/sonar-go-plugin/src/main/java/org/sonar/go/checks/DuplicateBranchGoCheck.java @@ -30,8 +30,8 @@ public class DuplicateBranchGoCheck extends DuplicateBranchCheck { @Override protected void checkConditionalStructure(CheckContext ctx, Tree tree, ConditionalStructure conditional) { /* - If we enter a type switch, we may find branches with similar ASTs but different semantics. - In this case, we stop exploring the conditional structure to avoid raising FPs. + * If we enter a type switch, we may find branches with similar ASTs but different semantics. + * In this case, we stop exploring the conditional structure to avoid raising FPs. */ if (tree instanceof MatchTree && isTypeSwitch((MatchTree) tree)) { return; diff --git a/sonar-go-plugin/src/main/java/org/sonar/go/checks/OneStatementPerLineGoCheck.java b/sonar-go-plugin/src/main/java/org/sonar/go/checks/OneStatementPerLineGoCheck.java index e025d621..c38501b2 100644 --- a/sonar-go-plugin/src/main/java/org/sonar/go/checks/OneStatementPerLineGoCheck.java +++ b/sonar-go-plugin/src/main/java/org/sonar/go/checks/OneStatementPerLineGoCheck.java @@ -28,6 +28,6 @@ public class OneStatementPerLineGoCheck extends OneStatementPerLineCheck { @Override protected boolean shouldIgnore(Tree tree) { return tree instanceof NativeTree && - ((NativeTree) tree).nativeKind().toString().equals(SEMICOLON); + ((NativeTree) tree).nativeKind().toString().equals(SEMICOLON); } } diff --git a/sonar-go-plugin/src/main/java/org/sonar/go/checks/package-info.java b/sonar-go-plugin/src/main/java/org/sonar/go/checks/package-info.java index 7c218874..fbadcd39 100644 --- a/sonar-go-plugin/src/main/java/org/sonar/go/checks/package-info.java +++ b/sonar-go-plugin/src/main/java/org/sonar/go/checks/package-info.java @@ -14,7 +14,5 @@ * You should have received a copy of the Sonar Source-Available License * along with this program; if not, see https://sonarsource.com/license/ssal/ */ -@ParametersAreNonnullByDefault +@javax.annotation.ParametersAreNonnullByDefault package org.sonar.go.checks; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-go-plugin/src/main/java/org/sonar/go/converter/ExternalProcessStreamConsumer.java b/sonar-go-plugin/src/main/java/org/sonar/go/converter/ExternalProcessStreamConsumer.java index 475b4685..7be67949 100644 --- a/sonar-go-plugin/src/main/java/org/sonar/go/converter/ExternalProcessStreamConsumer.java +++ b/sonar-go-plugin/src/main/java/org/sonar/go/converter/ExternalProcessStreamConsumer.java @@ -26,7 +26,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; - class ExternalProcessStreamConsumer { private static final Logger LOG = LoggerFactory.getLogger(ExternalProcessStreamConsumer.class); diff --git a/sonar-go-plugin/src/main/java/org/sonar/go/converter/GoConverter.java b/sonar-go-plugin/src/main/java/org/sonar/go/converter/GoConverter.java index aa2c9df1..1eb3c425 100644 --- a/sonar-go-plugin/src/main/java/org/sonar/go/converter/GoConverter.java +++ b/sonar-go-plugin/src/main/java/org/sonar/go/converter/GoConverter.java @@ -146,7 +146,7 @@ static boolean fileMatch(File dest, byte[] expectedContent) throws IOException { static byte[] getBytesFromResource(String executable) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); - try(InputStream in = GoConverter.class.getClassLoader().getResourceAsStream(executable)) { + try (InputStream in = GoConverter.class.getClassLoader().getResourceAsStream(executable)) { if (in == null) { throw new IllegalStateException(executable + " binary not found on class path"); } diff --git a/sonar-go-plugin/src/main/java/org/sonar/go/converter/package-info.java b/sonar-go-plugin/src/main/java/org/sonar/go/converter/package-info.java index cafa6db6..ccea630a 100644 --- a/sonar-go-plugin/src/main/java/org/sonar/go/converter/package-info.java +++ b/sonar-go-plugin/src/main/java/org/sonar/go/converter/package-info.java @@ -14,7 +14,5 @@ * You should have received a copy of the Sonar Source-Available License * along with this program; if not, see https://sonarsource.com/license/ssal/ */ -@ParametersAreNonnullByDefault +@javax.annotation.ParametersAreNonnullByDefault package org.sonar.go.converter; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-go-plugin/src/main/java/org/sonar/go/coverage/GoCoverSensor.java b/sonar-go-plugin/src/main/java/org/sonar/go/coverage/GoCoverSensor.java index ca021250..a65af33b 100644 --- a/sonar-go-plugin/src/main/java/org/sonar/go/coverage/GoCoverSensor.java +++ b/sonar-go-plugin/src/main/java/org/sonar/go/coverage/GoCoverSensor.java @@ -132,10 +132,9 @@ static Stream getReportPaths(SensorContext sensorContext) { Configuration config = sensorContext.config(); Path baseDir = sensorContext.fileSystem().baseDir().toPath(); String[] reportPaths = config.getStringArray(REPORT_PATH_KEY); - return Arrays.stream(reportPaths).flatMap(reportPath -> - isWildcard(reportPath) - ? getPatternPaths(baseDir, reportPath) - : getRegularPath(baseDir, reportPath)); + return Arrays.stream(reportPaths).flatMap(reportPath -> isWildcard(reportPath) + ? getPatternPaths(baseDir, reportPath) + : getRegularPath(baseDir, reportPath)); } private static Stream getRegularPath(Path baseDir, String reportPath) { @@ -245,14 +244,14 @@ private void add(CoverageStat coverage) { for (int line = startLine; line <= endLine; line++) { if (!isEmpty(line - 1)) { lineMap.computeIfAbsent(line, key -> new LineCoverage()) - .add(coverage); + .add(coverage); } } } private boolean isEmpty(int line) { return lines != null && - lines.get(line).trim().isEmpty(); + lines.get(line).trim().isEmpty(); } int findStartIgnoringBrace(CoverageStat coverage) { @@ -307,7 +306,7 @@ void add(CoverageStat coverage) { if (sum > Integer.MAX_VALUE) { hits = Integer.MAX_VALUE; } else { - hits = (int) sum; + hits = (int) sum; } } } diff --git a/sonar-go-plugin/src/main/java/org/sonar/go/coverage/GoPathContext.java b/sonar-go-plugin/src/main/java/org/sonar/go/coverage/GoPathContext.java index 6d76defa..18263d0c 100644 --- a/sonar-go-plugin/src/main/java/org/sonar/go/coverage/GoPathContext.java +++ b/sonar-go-plugin/src/main/java/org/sonar/go/coverage/GoPathContext.java @@ -74,11 +74,10 @@ String concat(String parentPath, String childPath) { * See {@link GoCoverSensor#findInputFile(String, FileSystem)} */ public String resolve(String filePath) { - return resolvedPaths.computeIfAbsent(filePath, path -> - getAbsolutePathForOldGoVersions(path) - .orElseGet(() -> getAbsolutePath(path) + return resolvedPaths.computeIfAbsent(filePath, path -> getAbsolutePathForOldGoVersions(path) + .orElseGet(() -> getAbsolutePath(path) .orElseGet(() -> prefixByFirstValidGoPath(path) - .orElseGet(() -> prefixByFirstGoPath(path))))); + .orElseGet(() -> prefixByFirstGoPath(path))))); } /** @@ -88,7 +87,7 @@ public String resolve(String filePath) { * unix: "_/mnt/c/src..." vs "/mnt/c/src..." * windows: "_\c_\src..." vs "c:\src..." */ - private static Optional getAbsolutePathForOldGoVersions(String path){ + private static Optional getAbsolutePathForOldGoVersions(String path) { if (path.startsWith(LINUX_ABSOLUTE_OLD_PREFIX)) { return Optional.of(path.substring(1)); } else if (path.startsWith(WINDOWS_ABSOLUTE_OLD_PREFIX)) { diff --git a/sonar-go-plugin/src/main/java/org/sonar/go/coverage/package-info.java b/sonar-go-plugin/src/main/java/org/sonar/go/coverage/package-info.java index 98148a06..e5bdd2ee 100644 --- a/sonar-go-plugin/src/main/java/org/sonar/go/coverage/package-info.java +++ b/sonar-go-plugin/src/main/java/org/sonar/go/coverage/package-info.java @@ -14,7 +14,5 @@ * You should have received a copy of the Sonar Source-Available License * along with this program; if not, see https://sonarsource.com/license/ssal/ */ -@ParametersAreNonnullByDefault +@javax.annotation.ParametersAreNonnullByDefault package org.sonar.go.coverage; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-go-plugin/src/main/java/org/sonar/go/externalreport/AbstractReportSensor.java b/sonar-go-plugin/src/main/java/org/sonar/go/externalreport/AbstractReportSensor.java index eb162d3e..245921c9 100644 --- a/sonar-go-plugin/src/main/java/org/sonar/go/externalreport/AbstractReportSensor.java +++ b/sonar-go-plugin/src/main/java/org/sonar/go/externalreport/AbstractReportSensor.java @@ -135,7 +135,7 @@ public static void createExternalRuleRepository(Context context, String linterId try (InputStreamReader inputStreamReader = new InputStreamReader(AbstractReportSensor.class.getClassLoader().getResourceAsStream(pathToRulesMeta), StandardCharsets.UTF_8)) { JsonArray jsonArray = Json.parse(inputStreamReader).asArray(); - for(JsonValue jsonValue : jsonArray) { + for (JsonValue jsonValue : jsonArray) { JsonObject rule = jsonValue.asObject(); NewRule newRule = externalRepo.createRule(rule.getString("key", null)) .setName(rule.getString("name", null)) diff --git a/sonar-go-plugin/src/main/java/org/sonar/go/externalreport/ExternalKeyUtils.java b/sonar-go-plugin/src/main/java/org/sonar/go/externalreport/ExternalKeyUtils.java index 59f71c49..3305f07f 100644 --- a/sonar-go-plugin/src/main/java/org/sonar/go/externalreport/ExternalKeyUtils.java +++ b/sonar-go-plugin/src/main/java/org/sonar/go/externalreport/ExternalKeyUtils.java @@ -45,23 +45,19 @@ private ExternalKeyUtils() { new ExternalKey("shadow", msg -> msg.contains("shadows declaration at")), new ExternalKey("shift", msg -> msg.contains("too small for shift")), new ExternalKey("structtags", msg -> msg.contains("struct field") && msg.contains("tag")), - new ExternalKey("tests", msg -> - msg.contains("has malformed") || - msg.contains("refers to unknown") || - msg.endsWith("should return nothing") || - msg.endsWith("should be niladic")), + new ExternalKey("tests", msg -> msg.contains("has malformed") || + msg.contains("refers to unknown") || + msg.endsWith("should return nothing") || + msg.endsWith("should be niladic")), new ExternalKey("unreachable", msg -> msg.equals("unreachable code")), new ExternalKey("unusedresult", msg -> msg.endsWith("call not used")), - new ExternalKey("unsafeptr", msg -> msg.equals("possible misuse of unsafe.Pointer")) - )); - + new ExternalKey("unsafeptr", msg -> msg.equals("possible misuse of unsafe.Pointer")))); public static final List GO_LINT_KEYS = Collections.unmodifiableList(Arrays.asList( - new ExternalKey("PackageComment", msg -> - msg.startsWith("package comment should be of the form") || - msg.startsWith("package comment should not have leading space") || - msg.equals("package comment is detached; there should be no blank lines between it and the package statement") || - msg.equals("should have a package comment, unless it's in another file for this package")), + new ExternalKey("PackageComment", msg -> msg.startsWith("package comment should be of the form") || + msg.startsWith("package comment should not have leading space") || + msg.equals("package comment is detached; there should be no blank lines between it and the package statement") || + msg.equals("should have a package comment, unless it's in another file for this package")), new ExternalKey("BlankImports", msg -> msg.equals("a blank import should be only in a main or test package, or have a comment justifying it")), new ExternalKey("Imports", msg -> msg.equals("should not use dot imports")), new ExternalKey("Exported", msg -> (msg.startsWith("exported") && msg.endsWith("or be unexported")) || @@ -74,25 +70,21 @@ private ExternalKeyUtils() { new ExternalKey("Errorf", msg -> msg.contains("(fmt.Sprintf(...)) with") && msg.contains(".Errorf(...)")), new ExternalKey("Errors", msg -> msg.startsWith("error var ") && msg.contains("should have name of the form ")), new ExternalKey("ErrorStrings", msg -> msg.equals("error strings should not be capitalized or end with punctuation or a newline")), - new ExternalKey("ReceiverNames", msg -> - msg.contains("should be consistent with previous receiver name") || - msg.startsWith("receiver name should not be an underscore") || - msg.equals("receiver name should be a reflection of its identity; don't use generic names such as \"this\" or \"self\"")), + new ExternalKey("ReceiverNames", msg -> msg.contains("should be consistent with previous receiver name") || + msg.startsWith("receiver name should not be an underscore") || + msg.equals("receiver name should be a reflection of its identity; don't use generic names such as \"this\" or \"self\"")), new ExternalKey("IncDec", msg -> msg.startsWith("should replace") && !msg.contains("(fmt.Sprintf(...)) with")), new ExternalKey("ErrorReturn", msg -> msg.startsWith("error should be the last type when returning multiple items")), new ExternalKey("UnexportedReturn", msg -> msg.contains("returns unexported type") && msg.endsWith("which can be annoying to use")), new ExternalKey("TimeNames", msg -> msg.contains("don't use unit-specific suffix")), new ExternalKey("ContextKeyTypes", msg -> msg.startsWith("should not use basic type") && msg.endsWith("as key in context.WithValue")), new ExternalKey("ContextArgs", msg -> msg.equals("context.Context should be the first parameter of a function")), - new ExternalKey("Names", msg -> - msg.startsWith("don't use an underscore in package name") || - msg.startsWith("don't use ALL_CAPS in Go names; use CamelCase") || - msg.startsWith("don't use leading k in Go names;") || - msg.startsWith("don't use underscores in Go names;") || - msg.matches("(range var|struct field|[\\w]+) [\\w_]+ should be [\\w_]+") || - msg.startsWith("don't use MixedCaps in package name;") - ) - )); + new ExternalKey("Names", msg -> msg.startsWith("don't use an underscore in package name") || + msg.startsWith("don't use ALL_CAPS in Go names; use CamelCase") || + msg.startsWith("don't use leading k in Go names;") || + msg.startsWith("don't use underscores in Go names;") || + msg.matches("(range var|struct field|[\\w]+) [\\w_]+ should be [\\w_]+") || + msg.startsWith("don't use MixedCaps in package name;")))); public static String lookup(String message, String linter) { if (linter.equals(GoVetReportSensor.LINTER_ID) || linter.equals(GoLintReportSensor.LINTER_ID)) { diff --git a/sonar-go-plugin/src/main/java/org/sonar/go/externalreport/package-info.java b/sonar-go-plugin/src/main/java/org/sonar/go/externalreport/package-info.java index 48193a77..8d726819 100644 --- a/sonar-go-plugin/src/main/java/org/sonar/go/externalreport/package-info.java +++ b/sonar-go-plugin/src/main/java/org/sonar/go/externalreport/package-info.java @@ -14,7 +14,5 @@ * You should have received a copy of the Sonar Source-Available License * along with this program; if not, see https://sonarsource.com/license/ssal/ */ -@ParametersAreNonnullByDefault +@javax.annotation.ParametersAreNonnullByDefault package org.sonar.go.externalreport; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-go-plugin/src/main/java/org/sonar/go/plugin/GoCheckList.java b/sonar-go-plugin/src/main/java/org/sonar/go/plugin/GoCheckList.java index 437a3d6c..f76e994b 100644 --- a/sonar-go-plugin/src/main/java/org/sonar/go/plugin/GoCheckList.java +++ b/sonar-go-plugin/src/main/java/org/sonar/go/plugin/GoCheckList.java @@ -20,8 +20,9 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; - +import org.sonar.go.checks.CodeAfterJumpGoCheck; import org.sonar.go.checks.DuplicateBranchGoCheck; +import org.sonar.go.checks.OneStatementPerLineGoCheck; import org.sonarsource.slang.checks.BadClassNameCheck; import org.sonarsource.slang.checks.CheckList; import org.sonarsource.slang.checks.CodeAfterJumpCheck; @@ -33,9 +34,6 @@ import org.sonarsource.slang.checks.UnusedLocalVariableCheck; import org.sonarsource.slang.checks.UnusedPrivateMethodCheck; -import org.sonar.go.checks.CodeAfterJumpGoCheck; -import org.sonar.go.checks.OneStatementPerLineGoCheck; - public class GoCheckList { private GoCheckList() { @@ -60,8 +58,7 @@ private GoCheckList() { private static final Collection> GO_LANGUAGE_SPECIFIC_CHECKS = Arrays.asList( CodeAfterJumpGoCheck.class, DuplicateBranchGoCheck.class, - OneStatementPerLineGoCheck.class - ); + OneStatementPerLineGoCheck.class); public static List> checks() { List> list = new ArrayList<>(CheckList.excludeChecks(GO_CHECK_BLACK_LIST)); diff --git a/sonar-go-plugin/src/main/java/org/sonar/go/plugin/GoPlugin.java b/sonar-go-plugin/src/main/java/org/sonar/go/plugin/GoPlugin.java index eca058a0..2842c90d 100644 --- a/sonar-go-plugin/src/main/java/org/sonar/go/plugin/GoPlugin.java +++ b/sonar-go-plugin/src/main/java/org/sonar/go/plugin/GoPlugin.java @@ -70,8 +70,7 @@ public void define(Context context) { .subCategory(GENERAL_SUBCATEGORY) .onQualifiers(Qualifiers.PROJECT) .multiValues(true) - .build() - ); + .build()); if (context.getRuntime().getProduct() != SonarProduct.SONARLINT) { addReportExtensions(context); @@ -148,7 +147,6 @@ private static void addReportExtensions(Context context) { .onQualifiers(Qualifiers.PROJECT) .defaultValue("") .multiValues(true) - .build() - ); + .build()); } } diff --git a/sonar-go-plugin/src/main/java/org/sonar/go/plugin/GoRulesDefinition.java b/sonar-go-plugin/src/main/java/org/sonar/go/plugin/GoRulesDefinition.java index 8580e330..47e5dcb6 100644 --- a/sonar-go-plugin/src/main/java/org/sonar/go/plugin/GoRulesDefinition.java +++ b/sonar-go-plugin/src/main/java/org/sonar/go/plugin/GoRulesDefinition.java @@ -17,7 +17,6 @@ package org.sonar.go.plugin; import java.util.List; - import org.sonar.api.SonarRuntime; import org.sonar.api.server.rule.RulesDefinition; import org.sonar.go.externalreport.AbstractReportSensor; diff --git a/sonar-go-plugin/src/main/java/org/sonar/go/plugin/GoSensor.java b/sonar-go-plugin/src/main/java/org/sonar/go/plugin/GoSensor.java index f297d028..326b8b79 100644 --- a/sonar-go-plugin/src/main/java/org/sonar/go/plugin/GoSensor.java +++ b/sonar-go-plugin/src/main/java/org/sonar/go/plugin/GoSensor.java @@ -69,10 +69,8 @@ protected String repositoryKey() { @Override protected Predicate executableLineOfCodePredicate() { - return super.executableLineOfCodePredicate().and(t -> - !(t instanceof VariableDeclarationTree) - && !isGenericDeclaration(t) - ); + return super.executableLineOfCodePredicate().and(t -> !(t instanceof VariableDeclarationTree) + && !isGenericDeclaration(t)); } private static boolean isGenericDeclaration(Tree tree) { diff --git a/sonar-go-plugin/src/main/java/org/sonar/go/plugin/package-info.java b/sonar-go-plugin/src/main/java/org/sonar/go/plugin/package-info.java index 4ebb4920..d1f12703 100644 --- a/sonar-go-plugin/src/main/java/org/sonar/go/plugin/package-info.java +++ b/sonar-go-plugin/src/main/java/org/sonar/go/plugin/package-info.java @@ -14,7 +14,5 @@ * You should have received a copy of the Sonar Source-Available License * along with this program; if not, see https://sonarsource.com/license/ssal/ */ -@ParametersAreNonnullByDefault +@javax.annotation.ParametersAreNonnullByDefault package org.sonar.go.plugin; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-go-plugin/src/main/java/org/sonar/go/testreport/GoTestSensor.java b/sonar-go-plugin/src/main/java/org/sonar/go/testreport/GoTestSensor.java index 8e45494b..82010248 100644 --- a/sonar-go-plugin/src/main/java/org/sonar/go/testreport/GoTestSensor.java +++ b/sonar-go-plugin/src/main/java/org/sonar/go/testreport/GoTestSensor.java @@ -196,7 +196,6 @@ private static String findPackageDirectory(String packagePath, FileSystem fileSy } } - private static void saveTestMetrics(SensorContext context, InputFile testFile, List tests) { int skip = 0; long timeMs = 0; diff --git a/sonar-go-plugin/src/main/java/org/sonar/go/testreport/package-info.java b/sonar-go-plugin/src/main/java/org/sonar/go/testreport/package-info.java index ff97be03..c5f5fc47 100644 --- a/sonar-go-plugin/src/main/java/org/sonar/go/testreport/package-info.java +++ b/sonar-go-plugin/src/main/java/org/sonar/go/testreport/package-info.java @@ -14,7 +14,5 @@ * You should have received a copy of the Sonar Source-Available License * along with this program; if not, see https://sonarsource.com/license/ssal/ */ -@ParametersAreNonnullByDefault +@javax.annotation.ParametersAreNonnullByDefault package org.sonar.go.testreport; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-go-plugin/src/test/java/org/sonar/go/checks/CodeAfterJumpGoCheckTest.java b/sonar-go-plugin/src/test/java/org/sonar/go/checks/CodeAfterJumpGoCheckTest.java index 97d71a66..c98f3548 100644 --- a/sonar-go-plugin/src/test/java/org/sonar/go/checks/CodeAfterJumpGoCheckTest.java +++ b/sonar-go-plugin/src/test/java/org/sonar/go/checks/CodeAfterJumpGoCheckTest.java @@ -19,8 +19,8 @@ import org.junit.jupiter.api.Test; class CodeAfterJumpGoCheckTest { - @Test - void test() { - GoVerifier.verify("CodeAfterJumpGoCheck.go", new CodeAfterJumpGoCheck()); - } + @Test + void test() { + GoVerifier.verify("CodeAfterJumpGoCheck.go", new CodeAfterJumpGoCheck()); + } } diff --git a/sonar-go-plugin/src/test/java/org/sonar/go/checks/DuplicateBranchGoCheckTest.java b/sonar-go-plugin/src/test/java/org/sonar/go/checks/DuplicateBranchGoCheckTest.java index 8ed4e37b..13c8df83 100644 --- a/sonar-go-plugin/src/test/java/org/sonar/go/checks/DuplicateBranchGoCheckTest.java +++ b/sonar-go-plugin/src/test/java/org/sonar/go/checks/DuplicateBranchGoCheckTest.java @@ -23,4 +23,4 @@ class DuplicateBranchGoCheckTest { void test() { GoVerifier.verify("DuplicateBranchGoCheck.go", new DuplicateBranchGoCheck()); } -} \ No newline at end of file +} diff --git a/sonar-go-plugin/src/test/java/org/sonar/go/checks/GoVerifier.java b/sonar-go-plugin/src/test/java/org/sonar/go/checks/GoVerifier.java index 2b35e8b3..f16b12e7 100644 --- a/sonar-go-plugin/src/test/java/org/sonar/go/checks/GoVerifier.java +++ b/sonar-go-plugin/src/test/java/org/sonar/go/checks/GoVerifier.java @@ -16,18 +16,17 @@ */ package org.sonar.go.checks; +import java.nio.file.Path; +import java.nio.file.Paths; import org.sonar.go.converter.GoConverter; import org.sonarsource.slang.api.ASTConverter; import org.sonarsource.slang.checks.api.SlangCheck; -import java.nio.file.Path; -import java.nio.file.Paths; - public class GoVerifier { - private static final Path BASE_DIR = Paths.get("src", "test", "resources", "checks"); - private static final ASTConverter CONVERTER = new GoConverter(Paths.get("build", "tmp").toFile()); + private static final Path BASE_DIR = Paths.get("src", "test", "resources", "checks"); + private static final ASTConverter CONVERTER = new GoConverter(Paths.get("build", "tmp").toFile()); - public static void verify(String fileName, SlangCheck check) { - org.sonarsource.slang.testing.Verifier.verify(CONVERTER, BASE_DIR.resolve(fileName), check); - } + public static void verify(String fileName, SlangCheck check) { + org.sonarsource.slang.testing.Verifier.verify(CONVERTER, BASE_DIR.resolve(fileName), check); + } } diff --git a/sonar-go-plugin/src/test/java/org/sonar/go/checks/OneStatementPerLineGoCheckTest.java b/sonar-go-plugin/src/test/java/org/sonar/go/checks/OneStatementPerLineGoCheckTest.java index c909f2d7..3cadf95d 100644 --- a/sonar-go-plugin/src/test/java/org/sonar/go/checks/OneStatementPerLineGoCheckTest.java +++ b/sonar-go-plugin/src/test/java/org/sonar/go/checks/OneStatementPerLineGoCheckTest.java @@ -19,8 +19,8 @@ import org.junit.jupiter.api.Test; class OneStatementPerLineGoCheckTest { - @Test - void test() { - GoVerifier.verify("OneStatementPerLineGoCheck.go", new OneStatementPerLineGoCheck()); - } + @Test + void test() { + GoVerifier.verify("OneStatementPerLineGoCheck.go", new OneStatementPerLineGoCheck()); + } } diff --git a/sonar-go-plugin/src/test/java/org/sonar/go/converter/GoConverterTest.java b/sonar-go-plugin/src/test/java/org/sonar/go/converter/GoConverterTest.java index 2cd7a1de..6172e392 100644 --- a/sonar-go-plugin/src/test/java/org/sonar/go/converter/GoConverterTest.java +++ b/sonar-go-plugin/src/test/java/org/sonar/go/converter/GoConverterTest.java @@ -51,7 +51,7 @@ void test_parse_return() { checkIntegerValue(returnList.get(0), "42"); } - + @Test void test_parse_binary_notation() { GoConverter converter = new GoConverter(Paths.get("build", "tmp").toFile()); @@ -79,7 +79,7 @@ void test_parse_embed_overlapping_interfaces() { .collect(Collectors.toList()); assertThat(classList).hasSize(3); } - + @Test void test_parse_infinite_for() { GoConverter converter = new GoConverter(Paths.get("build", "tmp").toFile()); diff --git a/sonar-go-plugin/src/test/java/org/sonar/go/coverage/GoCoverSensorTest.java b/sonar-go-plugin/src/test/java/org/sonar/go/coverage/GoCoverSensorTest.java index d787cca5..e3ad06e2 100644 --- a/sonar-go-plugin/src/test/java/org/sonar/go/coverage/GoCoverSensorTest.java +++ b/sonar-go-plugin/src/test/java/org/sonar/go/coverage/GoCoverSensorTest.java @@ -34,11 +34,11 @@ import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor; import org.sonar.api.batch.sensor.internal.SensorContextTester; import org.sonar.api.config.internal.MapSettings; -import org.sonarsource.slang.testing.ThreadLocalLogTester; import org.sonar.go.coverage.GoCoverSensor.Coverage; import org.sonar.go.coverage.GoCoverSensor.CoverageStat; import org.sonar.go.coverage.GoCoverSensor.FileCoverage; import org.sonar.go.coverage.GoCoverSensor.LineCoverage; +import org.sonarsource.slang.testing.ThreadLocalLogTester; import static java.nio.charset.StandardCharsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; @@ -51,7 +51,6 @@ class GoCoverSensorTest { @RegisterExtension public ThreadLocalLogTester logTester = new ThreadLocalLogTester(); - @Test void test_descriptor() { DefaultSensorDescriptor sensorDescriptor = new DefaultSensorDescriptor(); @@ -100,7 +99,7 @@ void coverage_stat() { // numStmt is not parsed because not required. assertThat(coverage.count).isEqualTo(234); - assertThatThrownBy(() -> new CoverageStat(42, "invalid") ) + assertThatThrownBy(() -> new CoverageStat(42, "invalid")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("Invalid go coverage at line 42"); } @@ -127,7 +126,7 @@ void line_coverage() { void line_coverage_over_flow() { LineCoverage line = new LineCoverage(); // hits is greater than Integer.MAX_VALUE - line.add(new CoverageStat(2, "main.go:2.2,2.5 1 " + + (((long)Integer.MAX_VALUE) + 1))); + line.add(new CoverageStat(2, "main.go:2.2,2.5 1 " + +(((long) Integer.MAX_VALUE) + 1))); assertThat(line.hits).isEqualTo(Integer.MAX_VALUE); LineCoverage lineWithTwoStats = new LineCoverage(); @@ -243,7 +242,7 @@ void get_report_paths_with_wildcards() { SensorContextTester context = SensorContextTester.create(COVERAGE_DIR); context.setSettings(new MapSettings()); context.settings().setProperty("sonar.go.coverage.reportPaths", - "*.absolute.out,glob" + File.separator +"*.out, test*" + File.separator +"*.out, coverage?.out"); + "*.absolute.out,glob" + File.separator + "*.out, test*" + File.separator + "*.out, coverage?.out"); Stream reportPaths = GoCoverSensor.getReportPaths(context); assertThat(reportPaths).containsExactlyInAnyOrder( Paths.get("src", "test", "resources", "coverage", "coverage.linux.absolute.out"), @@ -253,7 +252,7 @@ void get_report_paths_with_wildcards() { Paths.get("src", "test", "resources", "coverage", "coverage1.out")); context.settings().setProperty("sonar.go.coverage.reportPaths", - "**" + File.separator +"coverage.glob.out"); + "**" + File.separator + "coverage.glob.out"); Stream reportPaths2 = GoCoverSensor.getReportPaths(context); assertThat(reportPaths2).containsExactlyInAnyOrder( Paths.get("src", "test", "resources", "coverage", "glob", "coverage.glob.out")); diff --git a/sonar-go-plugin/src/test/java/org/sonar/go/coverage/GoPathContextTest.java b/sonar-go-plugin/src/test/java/org/sonar/go/coverage/GoPathContextTest.java index bf08825b..c4d39446 100644 --- a/sonar-go-plugin/src/test/java/org/sonar/go/coverage/GoPathContextTest.java +++ b/sonar-go-plugin/src/test/java/org/sonar/go/coverage/GoPathContextTest.java @@ -21,8 +21,8 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import org.junit.jupiter.api.Test; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-go-plugin/src/test/java/org/sonar/go/externalreport/ExternalLinterSensorHelper.java b/sonar-go-plugin/src/test/java/org/sonar/go/externalreport/ExternalLinterSensorHelper.java index 9906c728..07b90082 100644 --- a/sonar-go-plugin/src/test/java/org/sonar/go/externalreport/ExternalLinterSensorHelper.java +++ b/sonar-go-plugin/src/test/java/org/sonar/go/externalreport/ExternalLinterSensorHelper.java @@ -23,7 +23,6 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; - import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.batch.sensor.Sensor; diff --git a/sonar-go-plugin/src/test/java/org/sonar/go/externalreport/GolangCILintReportSensorTest.java b/sonar-go-plugin/src/test/java/org/sonar/go/externalreport/GolangCILintReportSensorTest.java index 164f80e3..96cde503 100644 --- a/sonar-go-plugin/src/test/java/org/sonar/go/externalreport/GolangCILintReportSensorTest.java +++ b/sonar-go-plugin/src/test/java/org/sonar/go/externalreport/GolangCILintReportSensorTest.java @@ -84,7 +84,6 @@ void issues_with_sonarqube() throws IOException { assertThat(logTester.logs(Level.ERROR)).isEmpty(); } - @Test void import_check_style_report_same_source_different_key() throws IOException { // Check that rules have different key based on the severity diff --git a/sonar-go-plugin/src/test/java/org/sonar/go/plugin/GoExclusionsFileFilterTest.java b/sonar-go-plugin/src/test/java/org/sonar/go/plugin/GoExclusionsFileFilterTest.java index 2aeb5f83..1bf55f54 100644 --- a/sonar-go-plugin/src/test/java/org/sonar/go/plugin/GoExclusionsFileFilterTest.java +++ b/sonar-go-plugin/src/test/java/org/sonar/go/plugin/GoExclusionsFileFilterTest.java @@ -83,7 +83,7 @@ void should_ignore_empty_path_regex() throws Exception { } private DefaultInputFile inputFile(String file) { - return new TestInputFileBuilder("test","test_vendor/" + file).setLanguage(file.split("\\.")[1]).build(); + return new TestInputFileBuilder("test", "test_vendor/" + file).setLanguage(file.split("\\.")[1]).build(); } } diff --git a/sonar-go-plugin/src/test/java/org/sonar/go/plugin/GoLanguageTest.java b/sonar-go-plugin/src/test/java/org/sonar/go/plugin/GoLanguageTest.java index b8515986..a98a2bdd 100644 --- a/sonar-go-plugin/src/test/java/org/sonar/go/plugin/GoLanguageTest.java +++ b/sonar-go-plugin/src/test/java/org/sonar/go/plugin/GoLanguageTest.java @@ -35,6 +35,6 @@ void can_override_file_extensions() { MapSettings mapSettings = new MapSettings(); mapSettings.setProperty("sonar.go.file.suffixes", ".go1,.go2"); GoLanguage typeScriptLanguage = new GoLanguage(mapSettings.asConfig()); - assertThat(typeScriptLanguage.getFileSuffixes()).containsExactly(".go1",".go2"); + assertThat(typeScriptLanguage.getFileSuffixes()).containsExactly(".go1", ".go2"); } } diff --git a/sonar-go-plugin/src/test/java/org/sonar/go/plugin/GoSensorTest.java b/sonar-go-plugin/src/test/java/org/sonar/go/plugin/GoSensorTest.java index aa20e486..85a33e2b 100644 --- a/sonar-go-plugin/src/test/java/org/sonar/go/plugin/GoSensorTest.java +++ b/sonar-go-plugin/src/test/java/org/sonar/go/plugin/GoSensorTest.java @@ -47,10 +47,10 @@ import org.sonar.api.measures.FileLinesContext; import org.sonar.api.measures.FileLinesContextFactory; import org.sonar.api.rule.RuleKey; -import org.sonarsource.slang.testing.ThreadLocalLogTester; import org.sonar.go.converter.GoConverter; import org.sonarsource.slang.checks.api.SlangCheck; import org.sonarsource.slang.testing.AbstractSensorTest; +import org.sonarsource.slang.testing.ThreadLocalLogTester; import static java.nio.charset.StandardCharsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; @@ -194,7 +194,6 @@ void metrics() { assertThat(fileLinesContext.metrics.keySet()).containsExactlyInAnyOrder(CoreMetrics.NCLOC_DATA_KEY, CoreMetrics.EXECUTABLE_LINES_DATA_KEY); - assertThat(fileLinesContext.metrics.get(CoreMetrics.NCLOC_DATA_KEY)).containsExactlyInAnyOrder( "2:1", "3:1", "4:1", "5:1", "6:1", "7:1", "8:1", "9:1", "10:1", "11:1", "12:1", "13:1", "14:1", "15:1", "16:1", "17:1", "18:1", "19:1", "20:1"); @@ -219,8 +218,7 @@ void test_not_executable_lines() { "}\n" + "type (\n" + "\tRrsType string\n" + - ")\n" - ); + ")\n"); sensorContext.fileSystem().add(inputFile); GoSensor goSensor = getSensor(); goSensor.execute(sensorContext); @@ -256,7 +254,7 @@ void metrics_for_test_file() { @Test void cognitive_complexity_metric() { InputFile inputFile = createInputFile("lets.go", InputFile.Type.MAIN, - "package main\n" + + "package main\n" + "import \"fmt\"\n" + "func fun1(i int) int {\n" + " if i < 0 { // +1\n" + diff --git a/sonar-go-plugin/src/test/java/org/sonar/go/testreport/GoTestSensorTest.java b/sonar-go-plugin/src/test/java/org/sonar/go/testreport/GoTestSensorTest.java index dd17fa56..29c26301 100644 --- a/sonar-go-plugin/src/test/java/org/sonar/go/testreport/GoTestSensorTest.java +++ b/sonar-go-plugin/src/test/java/org/sonar/go/testreport/GoTestSensorTest.java @@ -33,9 +33,9 @@ import org.sonar.api.batch.sensor.internal.SensorContextTester; import org.sonar.api.config.internal.MapSettings; import org.sonar.api.measures.CoreMetrics; -import org.sonarsource.slang.testing.ThreadLocalLogTester; import org.sonar.go.coverage.GoPathContext; import org.sonar.go.testreport.GoTestSensor.TestInfo; +import org.sonarsource.slang.testing.ThreadLocalLogTester; import static org.assertj.core.api.Assertions.assertThat; @@ -168,7 +168,6 @@ private DefaultInputFile getTestInputFile(DefaultFileSystem fs, String content, return nestedTestFile; } - @Test void subtests() throws Exception { GoTestSensor goTestSensor = new GoTestSensor(); diff --git a/sonar-go-to-slang/build.gradle.kts b/sonar-go-to-slang/build.gradle.kts index 632bf8c7..f02c4a45 100644 --- a/sonar-go-to-slang/build.gradle.kts +++ b/sonar-go-to-slang/build.gradle.kts @@ -1,3 +1,7 @@ +plugins { + id("org.sonarsource.cloud-native.code-style-conventions") +} + sonarqube { properties { property("sonar.sources", ".") @@ -7,7 +11,10 @@ sonarqube { property("sonar.test.inclusions", "**/*_test.go") property("sonar.test.exclusions", "**/build/**,**/vendor/**,**/.gogradle/**") property("sonar.go.tests.reportPaths", "${project.projectDir}/.gogradle/reports/test-report.out") - property("sonar.go.coverage.reportPaths", "${project.projectDir}/.gogradle/reports/coverage/profiles/github.com%2FSonarSource%2Fslang%2Fsonar-go-to-slang.out") + property( + "sonar.go.coverage.reportPaths", + "${project.projectDir}/.gogradle/reports/coverage/profiles/github.com%2FSonarSource%2Fslang%2Fsonar-go-to-slang.out" + ) } } @@ -44,3 +51,22 @@ generateTestReport { tasks.build { dependsOn(generateTestReport) } + +if (System.getenv("CI") == "true") { + // spotless is enabled only for CI, because spotless relies on Go installation being available on the machine + spotless { + go { + val goVersion = providers.environmentVariable("GO_VERSION").getOrElse("1.23.4") + gofmt("go$goVersion").withGoExecutable(System.getenv("HOME") + "/go/bin/go") + target("*.go", "**/*.go") + targetExclude("*_generated.go") + } + } + // For now, these tasks rely on installation of Go performed by the call to make.sh + tasks.spotlessCheck { + dependsOn(generateParserAndBuild) + } + tasks.spotlessApply { + dependsOn(generateParserAndBuild) + } +} diff --git a/sonar-go-to-slang/generate_source.go b/sonar-go-to-slang/generate_source.go index 5b373005..bea5515b 100644 --- a/sonar-go-to-slang/generate_source.go +++ b/sonar-go-to-slang/generate_source.go @@ -95,10 +95,10 @@ import ( "BadExpr": true, }, FieldToIgnore: map[string]bool{ - "File#FileStart": true, - "File#FileEnd" : true, - "File#GoVersion" : true, - "RangeStmt#Range" : true, + "File#FileStart": true, + "File#FileEnd": true, + "File#GoVersion": true, + "RangeStmt#Range": true, }, TypeToIgnore: map[string]bool{ // All fields of ast.* structs with the following types are ignored