Skip to content

Commit

Permalink
style(detekt): Enable the "Indentation" rule
Browse files Browse the repository at this point in the history
Enable the "Indentation" rule [1] [2] to ensure consistent indentation
across the codebase. Change the continuation indent from 8 to 4 because
the ktlint rule does not support continuation indents [3] [4].

[1]: https://detekt.dev/docs/rules/formatting#indentation
[2]: https://pinterest.github.io/ktlint/0.50.0/rules/standard/#indentation
[3]: pinterest/ktlint#816
[4]: https://kotlinlang.org/docs/code-style-migration-guide.html#differences-between-kotlin-coding-conventions-and-intellij-idea-default-code-style

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.io>
  • Loading branch information
mnonnenmacher committed Aug 30, 2023
1 parent f3123a7 commit 8ebf654
Show file tree
Hide file tree
Showing 235 changed files with 1,286 additions and 1,288 deletions.
2 changes: 0 additions & 2 deletions .detekt.yml
Expand Up @@ -38,8 +38,6 @@ formatting:
functionBodyExpressionWrapping: multiline
ImportOrdering:
active: false
Indentation:
active: false
MaximumLineLength:
active: false
NoUnusedImports:
Expand Down
2 changes: 1 addition & 1 deletion .editorconfig
@@ -1,5 +1,5 @@
[*.{kt,kts}]
indent_size=4
continuation_indent_size=8
continuation_indent_size=4
insert_final_newline=true
max_line_length=120
4 changes: 2 additions & 2 deletions advisor/src/main/kotlin/Advisor.kt
Expand Up @@ -60,7 +60,7 @@ class Advisor(
if (ortResult.analyzer == null) {
logger.warn {
"Cannot run the advisor as the provided ORT result does not contain an analyzer result. " +
"No result will be added."
"No result will be added."
}

return ortResult
Expand Down Expand Up @@ -91,7 +91,7 @@ class Advisor(

logger.info {
"Found ${providerResults.values.flatMap { it.vulnerabilities }.distinct().size} distinct " +
"vulnerabilities via ${provider.providerName}. "
"vulnerabilities via ${provider.providerName}. "
}

providerResults.keys.takeIf { it.isNotEmpty() }?.let { pkgs ->
Expand Down
8 changes: 4 additions & 4 deletions advisor/src/main/kotlin/advisors/GitHubDefects.kt
Expand Up @@ -167,7 +167,7 @@ class GitHubDefects(name: String, config: GitHubDefectsConfiguration) : AdvicePr
ortIssues += createAndLogIssue(
providerName,
"Failed to load information about $itemType for package '${pkg.original.id.toCoordinates()}': " +
exception.collectMessages(),
exception.collectMessages(),
Severity.ERROR
)
}.getOrNull().orEmpty()
Expand Down Expand Up @@ -231,9 +231,9 @@ class GitHubDefects(name: String, config: GitHubDefectsConfiguration) : AdvicePr
*/
private fun List<GitHubIssue>.applyLabelFilters(): List<GitHubIssue> =

Check warning on line 232 in advisor/src/main/kotlin/advisors/GitHubDefects.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "applyLabelFilters" is never used
filter { issue ->
val labels = issue.labels()
labelFilters.find { it.matches(labels) }?.including ?: false
}
val labels = issue.labels()
labelFilters.find { it.matches(labels) }?.including ?: false
}
}

/**
Expand Down
24 changes: 12 additions & 12 deletions advisor/src/main/kotlin/advisors/VulnerableCode.kt
Expand Up @@ -127,18 +127,18 @@ class VulnerableCode(name: String, config: VulnerableCodeConfiguration) : Advice
issues: MutableList<Issue>
): List<VulnerabilityReference> =
runCatching {
val sourceUri = URI(url)
if (scores.isEmpty()) return listOf(VulnerabilityReference(sourceUri, null, null))
return scores.map {
// VulnerableCode returns MODERATE instead of MEDIUM in case of cvssv3.1_qr, see:
// https://github.com/nexB/vulnerablecode/issues/1186
val severity = if (it.scoringSystem == "cvssv3.1_qr" && it.value == "MODERATE") "MEDIUM" else it.value

VulnerabilityReference(sourceUri, it.scoringSystem, severity)
}
}.onFailure {
issues += createAndLogIssue(providerName, "Failed to map $this to ORT model due to $it.", Severity.HINT)
}.getOrElse { emptyList() }
val sourceUri = URI(url)
if (scores.isEmpty()) return listOf(VulnerabilityReference(sourceUri, null, null))
return scores.map {
// VulnerableCode returns MODERATE instead of MEDIUM in case of cvssv3.1_qr, see:
// https://github.com/nexB/vulnerablecode/issues/1186
val severity = if (it.scoringSystem == "cvssv3.1_qr" && it.value == "MODERATE") "MEDIUM" else it.value

VulnerabilityReference(sourceUri, it.scoringSystem, severity)
}
}.onFailure {
issues += createAndLogIssue(providerName, "Failed to map $this to ORT model due to $it.", Severity.HINT)
}.getOrElse { emptyList() }

/**
* Return a meaningful identifier for this vulnerability that can be used in reports. Obtain this identifier from
Expand Down
2 changes: 1 addition & 1 deletion analyzer/src/funTest/kotlin/PackageManagerFunTest.kt
Expand Up @@ -174,7 +174,7 @@ class PackageManagerFunTest : WordSpec({
"take path excludes into account" {
val tempDir = "test/"
val definitionFilesWithExcludes = definitionFiles +
listOf("pom.xml", "build.gradle", "build.sbt").map { "$tempDir$it" }
listOf("pom.xml", "build.gradle", "build.sbt").map { "$tempDir$it" }
val rootDir = tempdir()
definitionFilesWithExcludes.writeFiles(rootDir)

Expand Down
6 changes: 3 additions & 3 deletions analyzer/src/funTest/kotlin/managers/GoDepFunTest.kt
Expand Up @@ -53,9 +53,9 @@ class GoDepFunTest : WordSpec({

with(result) {
project.id shouldBe
Identifier("GoDep::src/funTest/assets/projects/synthetic/godep/no-lockfile/Gopkg.toml:")
Identifier("GoDep::src/funTest/assets/projects/synthetic/godep/no-lockfile/Gopkg.toml:")
project.definitionFilePath shouldBe
"analyzer/src/funTest/assets/projects/synthetic/godep/no-lockfile/Gopkg.toml"
"analyzer/src/funTest/assets/projects/synthetic/godep/no-lockfile/Gopkg.toml"
packages should beEmpty()
issues.size shouldBe 1
issues.first().message should haveSubstring("IllegalArgumentException: No lockfile found in")
Expand Down Expand Up @@ -102,7 +102,7 @@ class GoDepFunTest : WordSpec({
val vcsInfo = VcsInfo.EMPTY.copy(url = "https://github.com/oss-review-toolkit/ort.git")

deduceImportPath(projectDir, vcsInfo, gopath) shouldBe
gopath.resolve("src/github.com/oss-review-toolkit/ort.git")
gopath.resolve("src/github.com/oss-review-toolkit/ort.git")
}

"deduce an import path without VCS info" {
Expand Down
6 changes: 3 additions & 3 deletions analyzer/src/main/kotlin/Analyzer.kt
Expand Up @@ -207,7 +207,7 @@ class Analyzer(private val config: AnalyzerConfiguration, private val labels: Ma
if (managerForName == null) {
logger.debug {
"Ignoring that ${packageManager.managerName} must run after $name, because there are no " +
"definition files for $name."
"definition files for $name."
}
} else {
result.getOrPut(packageManager) { mutableSetOf() } += name
Expand All @@ -223,7 +223,7 @@ class Analyzer(private val config: AnalyzerConfiguration, private val labels: Ma
if (managerForName == null) {
logger.debug {
"Ignoring that ${packageManager.managerName} must run before $name, because there are no " +
"definition files for $name."
"definition files for $name."
}
} else {
result.getOrPut(managerForName) { mutableSetOf() } += packageManager.managerName
Expand Down Expand Up @@ -305,7 +305,7 @@ private class PackageManagerRunner(
if (remaining.isNotEmpty()) {
Analyzer.logger.info {
"${manager.managerName} is waiting for the following package managers to complete: " +
remaining.joinToString(postfix = ".")
remaining.joinToString(postfix = ".")
}
}

Expand Down
50 changes: 25 additions & 25 deletions analyzer/src/main/kotlin/AnalyzerResultBuilder.kt
Expand Up @@ -48,7 +48,7 @@ class AnalyzerResultBuilder {
val duplicates = (projects.map { it.toPackage() } + packages).getDuplicates { it.id }
require(duplicates.isEmpty()) {
"Unable to create the AnalyzerResult as it contains packages and projects with the same ids: " +
duplicates.values
duplicates.values
}

return AnalyzerResult(projects, packages, issues, dependencyGraphs)
Expand All @@ -58,37 +58,37 @@ class AnalyzerResultBuilder {

fun addResult(projectAnalyzerResult: ProjectAnalyzerResult) =
apply {
// TODO: It might be, e.g. in the case of PIP "requirements.txt" projects, that different projects with
// the same ID exist. We need to decide how to handle that case.
val existingProject = projects.find { it.id == projectAnalyzerResult.project.id }
// TODO: It might be, e.g. in the case of PIP "requirements.txt" projects, that different projects with
// the same ID exist. We need to decide how to handle that case.
val existingProject = projects.find { it.id == projectAnalyzerResult.project.id }

if (existingProject != null) {
val existingDefinitionFileUrl = existingProject.let {
"${it.vcsProcessed.url}/${it.definitionFilePath}"
}
val incomingDefinitionFileUrl = projectAnalyzerResult.project.let {
"${it.vcsProcessed.url}/${it.definitionFilePath}"
}
if (existingProject != null) {
val existingDefinitionFileUrl = existingProject.let {
"${it.vcsProcessed.url}/${it.definitionFilePath}"
}
val incomingDefinitionFileUrl = projectAnalyzerResult.project.let {
"${it.vcsProcessed.url}/${it.definitionFilePath}"
}

val issue = createAndLogIssue(
source = "analyzer",
message = "Multiple projects with the same id '${existingProject.id.toCoordinates()}' " +
val issue = createAndLogIssue(
source = "analyzer",
message = "Multiple projects with the same id '${existingProject.id.toCoordinates()}' " +
"found. Not adding the project defined in '$incomingDefinitionFileUrl' to the " +
"analyzer results as it duplicates the project defined in " +
"'$existingDefinitionFileUrl'."
)
)

val projectIssues = issues.getOrDefault(existingProject.id, emptyList())
issues[existingProject.id] = projectIssues + issue
} else {
projects += projectAnalyzerResult.project
addPackages(projectAnalyzerResult.packages)
val projectIssues = issues.getOrDefault(existingProject.id, emptyList())
issues[existingProject.id] = projectIssues + issue
} else {
projects += projectAnalyzerResult.project
addPackages(projectAnalyzerResult.packages)

if (projectAnalyzerResult.issues.isNotEmpty()) {
issues[projectAnalyzerResult.project.id] = projectAnalyzerResult.issues
if (projectAnalyzerResult.issues.isNotEmpty()) {
issues[projectAnalyzerResult.project.id] = projectAnalyzerResult.issues
}
}
}
}

/**
* Add the given [packageSet] to this builder. This function can be used for packages that have been obtained
Expand All @@ -102,8 +102,8 @@ class AnalyzerResultBuilder {
*/
fun addDependencyGraph(packageManagerName: String, graph: DependencyGraph) =
apply {
dependencyGraphs[packageManagerName] = graph
}
dependencyGraphs[packageManagerName] = graph
}
}

private fun AnalyzerResult.resolvePackageManagerDependencies(): AnalyzerResult {
Expand Down
4 changes: 2 additions & 2 deletions analyzer/src/main/kotlin/PackageManager.kt
Expand Up @@ -339,7 +339,7 @@ abstract class PackageManager(
createAndLogIssue(
source = managerName,
message = "$managerName failed to resolve dependencies for path '$relativePath': " +
it.collectMessages()
it.collectMessages()
)
)

Expand Down Expand Up @@ -369,7 +369,7 @@ abstract class PackageManager(
.takeUnless { it.isEmpty() } ?: "."

"No lockfile found in '$relativePathString'. This potentially results in unstable versions of " +
"dependencies. To support this, enable the 'allowDynamicVersions' option in '$ORT_CONFIG_FILENAME'."
"dependencies. To support this, enable the 'allowDynamicVersions' option in '$ORT_CONFIG_FILENAME'."
}
}

Expand Down
4 changes: 2 additions & 2 deletions analyzer/src/main/kotlin/managers/Sbt.kt
Expand Up @@ -173,7 +173,7 @@ class Sbt(

logger.info {
"No POM locations found in the output of SBT's 'makePom' command. Falling back to look for POMs in " +
"the '$targetDir' directory."
"the '$targetDir' directory."
}

targetDir.walk().maxDepth(1).filterTo(pomFiles) { it.extension == "pom" }
Expand Down Expand Up @@ -215,7 +215,7 @@ class Sbt(
if (!Semver(lowestSbtVersion).satisfies(sbtVersionRequirement)) {
throw IOException(
"Unsupported $managerName version $lowestSbtVersion does not fulfill " +
"$sbtVersionRequirement."
"$sbtVersionRequirement."
)
}
}
Expand Down
Expand Up @@ -112,7 +112,7 @@ class MavenDependencyHandler(
issues += createAndLogIssue(
source = managerName,
message = "Could not get package information for dependency '" +
"${dependency.artifact.identifier()}': ${e.collectMessages()}"
"${dependency.artifact.identifier()}': ${e.collectMessages()}"
)
}.getOrNull()
}
Expand Down
20 changes: 10 additions & 10 deletions analyzer/src/main/kotlin/managers/utils/MavenSupport.kt
Expand Up @@ -229,14 +229,14 @@ class MavenSupport(private val workspaceReader: WorkspaceReader) {
// clear cases.
logger.info {
"Maven SCM connection '$connection' of project ${project.artifact} lacks the required " +
"'scm' prefix."
"'scm' prefix."
}

VcsInfo(type = VcsType.GIT, url = connection, revision = tag)
} else {
logger.info {
"Ignoring Maven SCM connection '$connection' of project ${project.artifact} due to an " +
"unexpected format."
"unexpected format."
}

VcsInfo.EMPTY
Expand Down Expand Up @@ -427,7 +427,7 @@ class MavenSupport(private val workspaceReader: WorkspaceReader) {

logger.warn {
"There have been issues building the Maven project models, this could lead to errors during " +
"dependency analysis: ${e.collectMessages()}"
"dependency analysis: ${e.collectMessages()}"
}

e.results
Expand All @@ -439,7 +439,7 @@ class MavenSupport(private val workspaceReader: WorkspaceReader) {
if (projectBuildingResult.project == null) {
logger.warn {
"Project for POM file '${projectBuildingResult.pomFile.absolutePath}' could not be built:\n" +
projectBuildingResult.problems.joinToString("\n")
projectBuildingResult.problems.joinToString("\n")
}
} else {
val project = projectBuildingResult.project
Expand Down Expand Up @@ -470,8 +470,8 @@ class MavenSupport(private val workspaceReader: WorkspaceReader) {
if (resultForPomFile != null) {
logger.warn {
"There was an error building project '${e.projectId}' at '${e.pomFile.safePath}'. " +
"Still continuing with the incompletely built project '${resultForPomFile.projectId}' at " +
"'${resultForPomFile.pomFile.safePath}': ${e.collectMessages()}"
"Still continuing with the incompletely built project '${resultForPomFile.projectId}' at " +
"'${resultForPomFile.pomFile.safePath}': ${e.collectMessages()}"
}

resultForPomFile
Expand Down Expand Up @@ -704,7 +704,7 @@ class MavenSupport(private val workspaceReader: WorkspaceReader) {
if (failedProject != null) {
logger.warn {
"There was an error building '${it.identifier()}', continuing with the incompletely built " +
"project: ${e.collectMessages()}"
"project: ${e.collectMessages()}"
}
failedProject.project
} else {
Expand Down Expand Up @@ -759,9 +759,9 @@ class MavenSupport(private val workspaceReader: WorkspaceReader) {
val isSpringMetadataProject = with(mavenProject) {
listOf("boot", "cloud").any {
groupId == "org.springframework.$it" && (
artifactId.startsWith("spring-$it-starter") ||
artifactId.startsWith("spring-$it-starter") ||
artifactId.startsWith("spring-$it-contract-spec")
)
)
}
}

Expand All @@ -782,7 +782,7 @@ class MavenSupport(private val workspaceReader: WorkspaceReader) {
vcs = vcsFromPackage,
vcsProcessed = vcsProcessed,
isMetadataOnly = (mavenProject.packaging == "pom" && binaryRemoteArtifact.url.endsWith(".pom"))
|| isSpringMetadataProject,
|| isSpringMetadataProject,
isModified = isBinaryArtifactModified || isSourceArtifactModified
)
}
Expand Down
Expand Up @@ -136,18 +136,18 @@ private data class PackageManagerDependency(

require(project.id.type == packageManager) {
"The project '${project.id.toCoordinates()}' from definition file '$definitionFile' uses the wrong " +
"package manager '${project.id.type}', expected is '$packageManager'."
"package manager '${project.id.type}', expected is '$packageManager'."
}

requireNotNull(project.scopeNames) {
"The project '${project.id.toCoordinates()}' from definition file '$definitionFile' does not use a " +
"dependency graph."
"dependency graph."
}

if (scope !in project.scopeNames.orEmpty()) {
logger.warn {
"The project '${project.id.toCoordinates()}' from definition file '$definitionFile' does not contain " +
"the requested scope '$scope'."
"the requested scope '$scope'."
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions analyzer/src/test/kotlin/managers/utils/MavenSupportTest.kt
Expand Up @@ -46,7 +46,7 @@ class MavenSupportTest : WordSpec({
}

MavenSupport.getOriginalScm(mavenProject)?.connection shouldBe
"scm:git:https://github.com/spring-projects/spring-boot.git"
"scm:git:https://github.com/spring-projects/spring-boot.git"
MavenSupport.getOriginalScm(mavenProject)?.url shouldBe "https://github.com/oss-review-toolkit/correctUrl"
}

Expand All @@ -65,7 +65,7 @@ class MavenSupportTest : WordSpec({
}

MavenSupport.getOriginalScm(mavenProject)?.connection shouldBe
"scm:git:https://github.com/oss-review-toolkit/childConnection.git"
"scm:git:https://github.com/oss-review-toolkit/childConnection.git"
MavenSupport.getOriginalScm(mavenProject)?.url shouldBe "https://github.com/spring-projects/spring-boot"
}
}
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main/kotlin/OrtMain.kt
Expand Up @@ -109,7 +109,7 @@ class OrtMain : CliktCommand(
private val configArguments by option(
"-P",
help = "Override a key-value pair in the configuration file. For example: " +
"-P ort.scanner.storages.postgres.connection.schema=testSchema"
"-P ort.scanner.storages.postgres.connection.schema=testSchema"
).associate()

private val helpAll by option(
Expand Down

0 comments on commit 8ebf654

Please sign in to comment.