Skip to content

Commit

Permalink
style(detekt): Enable the "FunctionSignature" rule
Browse files Browse the repository at this point in the history
Enable the "FunctionSignature" rule [1] [2] to ensure consistent
formatting of function signatures. Set the
`functionBodyExpressionWrapping` property to `multiline` to align with
the Kotlin style guide which recommends to put a linebreak after the `=`
sign if an expression body does not fit in a single line [3].

The changes were automatically applied by running `./gradlew detekt
--auto-correct`. This introduced some indentation issues which will be
fixed in the following commit.

[1]: https://detekt.dev/docs/rules/formatting#functionsignature
[2]: https://pinterest.github.io/ktlint/0.50.0/rules/experimental/#function-signature
[3]: https://kotlinlang.org/docs/coding-conventions.html#expression-bodies

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.io>
  • Loading branch information
mnonnenmacher committed Aug 30, 2023
1 parent bef16db commit f3123a7
Show file tree
Hide file tree
Showing 122 changed files with 269 additions and 377 deletions.
3 changes: 3 additions & 0 deletions .detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ formatting:
active: false
FinalNewline:
active: false
FunctionSignature:
active: true
functionBodyExpressionWrapping: multiline
ImportOrdering:
active: false
Indentation:
Expand Down
3 changes: 1 addition & 2 deletions advisor/src/funTest/kotlin/OsvFunTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ class OsvFunTest : StringSpec({
private fun identifierToPackage(id: String): Package =
Identifier(id).let { Package.EMPTY.copy(id = it, purl = it.toPurl()) }

private fun createOsv(): Osv =
Osv("OSV", OsvConfiguration(serverUrl = null))
private fun createOsv(): Osv = Osv("OSV", OsvConfiguration(serverUrl = null))

private fun Map<Identifier, AdvisorResult>.patchTimes(): Map<Identifier, AdvisorResult> =
mapValues { (_, advisorResult) ->
Expand Down
3 changes: 1 addition & 2 deletions advisor/src/main/kotlin/AdviceProviderFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ abstract class AbstractAdviceProviderFactory<out T : AdviceProvider>(
* Return a map with options for the [AdviceProvider] managed by this factory or an empty map if no options are
* available.
*/
protected fun AdvisorConfiguration.providerOptions(): Options =
options.orEmpty()[type].orEmpty()
protected fun AdvisorConfiguration.providerOptions(): Options = options.orEmpty()[type].orEmpty()

/**
* Return the provider's name here to allow Clikt to display something meaningful when listing the advisors which
Expand Down
3 changes: 2 additions & 1 deletion advisor/src/main/kotlin/advisors/GitHubDefects.kt
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ class GitHubDefects(name: String, config: GitHubDefectsConfiguration) : AdvicePr
/**
* Return a filtered list of [Issue]s according to the label filters defined in the configuration.
*/
private fun List<GitHubIssue>.applyLabelFilters(): List<GitHubIssue> = filter { issue ->
private fun List<GitHubIssue>.applyLabelFilters(): List<GitHubIssue> =
filter { issue ->
val labels = issue.labels()
labelFilters.find { it.matches(labels) }?.including ?: false
}
Expand Down
3 changes: 2 additions & 1 deletion advisor/src/main/kotlin/advisors/VulnerableCode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ class VulnerableCode(name: String, config: VulnerableCodeConfiguration) : Advice
*/
private fun VulnerableCodeService.VulnerabilityReference.toModel(
issues: MutableList<Issue>
): List<VulnerabilityReference> = runCatching {
): List<VulnerabilityReference> =
runCatching {
val sourceUri = URI(url)
if (scores.isEmpty()) return listOf(VulnerabilityReference(sourceUri, null, null))
return scores.map {
Expand Down
10 changes: 5 additions & 5 deletions analyzer/src/main/kotlin/AnalyzerResultBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class AnalyzerResultBuilder {
.resolvePackageManagerDependencies()
}

fun addResult(projectAnalyzerResult: ProjectAnalyzerResult) = apply {
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 }
Expand Down Expand Up @@ -93,15 +94,14 @@ class AnalyzerResultBuilder {
* Add the given [packageSet] to this builder. This function can be used for packages that have been obtained
* independently of a [ProjectAnalyzerResult].
*/
fun addPackages(packageSet: Set<Package>) = apply {
packages += packageSet
}
fun addPackages(packageSet: Set<Package>) = apply { packages += packageSet }

/**
* Add a [DependencyGraph][graph] with all dependencies detected by the [PackageManager] with the given
* [name][packageManagerName] to the result produced by this builder.
*/
fun addDependencyGraph(packageManagerName: String, graph: DependencyGraph) = apply {
fun addDependencyGraph(packageManagerName: String, graph: DependencyGraph) =
apply {
dependencyGraphs[packageManagerName] = graph
}
}
Expand Down
3 changes: 1 addition & 2 deletions analyzer/src/main/kotlin/managers/utils/GoSupport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ package org.ossreviewtoolkit.analyzer.managers.utils
* also any suffix starting with '+', because build metadata is not involved in version comparison according to
* https://go.dev/ref/mod#incompatible-versions.
*/
fun normalizeModuleVersion(moduleVersion: String): String =
moduleVersion.removePrefix("v").substringBefore("+")
fun normalizeModuleVersion(moduleVersion: String): String = moduleVersion.removePrefix("v").substringBefore("+")
3 changes: 1 addition & 2 deletions analyzer/src/main/kotlin/managers/utils/MavenSupport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,7 @@ class MavenSupport(private val workspaceReader: WorkspaceReader) {
/**
* Looks up an instance of the class provided from the Maven Plexus container.
*/
inline fun <reified T> containerLookup(hint: String = "default"): T =
container.lookup(T::class.java, hint)
inline fun <reified T> containerLookup(hint: String = "default"): T = container.lookup(T::class.java, hint)

/**
* Build the Maven projects defined in the provided [pomFiles] without resolving dependencies. The result can later
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ interface ClearlyDefinedService {
* Create a ClearlyDefined service instance for communicating with the given [server], optionally using a
* pre-built OkHttp [client].
*/
fun create(server: Server, client: OkHttpClient? = null): ClearlyDefinedService =
create(server.apiUrl, client)
fun create(server: Server, client: OkHttpClient? = null): ClearlyDefinedService = create(server.apiUrl, client)

/**
* Create a ClearlyDefined service instance for communicating with a server running at the given [url],
Expand Down
6 changes: 2 additions & 4 deletions clients/fossid-webapp/src/main/kotlin/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ suspend fun FossIdRestService.createProject(
projectCode: String,
projectName: String,
comment: String = "Created by ORT"
) =
createProject(
) = createProject(
PostRequestBody(
"create",
PROJECT_GROUP,
Expand Down Expand Up @@ -371,8 +370,7 @@ suspend fun FossIdRestService.createIgnoreRule(
type: RuleType,
value: String,
scope: RuleScope
) =
createIgnoreRule(
) = createIgnoreRule(
PostRequestBody(
"ignore_rules_add",
SCAN_GROUP,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ abstract class FossIdServiceWithVersion(val version: String) : FossIdRestService
* Construct a new instance of [FossIdServiceWithVersion] for given [delegate]. The implementation matching
* FossID version will be instantiated and returned.
*/
fun instance(delegate: FossIdRestService): FossIdServiceWithVersion = runBlocking {
fun instance(delegate: FossIdRestService): FossIdServiceWithVersion =
runBlocking {
val version = delegate.getFossIdVersion().orEmpty()

when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ open class VersionedFossIdService(
user: String,
apiKey: String,
scanCode: String
): EntityResponseBody<out UnversionedScanDescription> = delegate.checkScanStatus(
): EntityResponseBody<out UnversionedScanDescription> =
delegate.checkScanStatus(
PostRequestBody("check_status", SCAN_GROUP, user, apiKey, mapOf("scan_code" to scanCode))
)
}
3 changes: 2 additions & 1 deletion clients/github-graphql/src/main/kotlin/GitHubService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ class GitHubService private constructor(
owner: String,
repository: String,
paging: Paging = Paging.INITIAL
): QueryResult<Release> = runCatching {
): QueryResult<Release> =
runCatching {
val query = ReleasesQuery(ReleasesQuery.Variables(owner, repository, paging.pageSize, paging.cursor))
val result = client.executeAndCheck(query)

Expand Down
3 changes: 2 additions & 1 deletion clients/osv/src/funTest/kotlin/OsvServiceFunTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ private val VULNERABILITY_FOR_PACKAGE_BY_INVALID_COMMIT_REQUEST = Vulnerabilitie
commit = "6879efc2c1596d11a6a6ad296f80063b558d5e0c"
)

private fun Vulnerability.patchIgnorableFields() = copy(
private fun Vulnerability.patchIgnorableFields() =
copy(
modified = Instant.EPOCH,
databaseSpecific = emptyJsonObject.takeIf { databaseSpecific != null },
affected = affected.mapTo(mutableSetOf()) { affected ->
Expand Down
3 changes: 1 addition & 2 deletions clients/osv/src/main/kotlin/OsvApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ interface OsvApiClient {
* Create an OsvApiClient instance for communicating with the given [server], optionally using a pre-built
* OkHttp [client].
*/
fun create(server: Server, client: OkHttpClient? = null): OsvApiClient =
create(server.url, client)
fun create(server: Server, client: OkHttpClient? = null): OsvApiClient = create(server.url, client)

fun create(serverUrl: String? = null, client: OkHttpClient? = null): OsvApiClient {
val converterFactory = JSON.asConverterFactory(contentType = "application/json".toMediaType())
Expand Down
8 changes: 2 additions & 6 deletions clients/osv/src/main/kotlin/OsvService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ class OsvService(serverUrl: String? = null, httpClient: OkHttpClient? = null) {
/**
* Get the vulnerabilities for the package matching the given [request].
*/
fun getVulnerabilitiesForPackage(
request: VulnerabilitiesForPackageRequest
): Result<List<Vulnerability>> {
fun getVulnerabilitiesForPackage(request: VulnerabilitiesForPackageRequest): Result<List<Vulnerability>> {
val response = client.getVulnerabilitiesForPackage(request).execute()
val body = response.body()

Expand All @@ -55,9 +53,7 @@ class OsvService(serverUrl: String? = null, httpClient: OkHttpClient? = null) {
/**
* Return the vulnerability IDs for the respective package matched by the given [requests].
*/
fun getVulnerabilityIdsForPackages(
requests: List<VulnerabilitiesForPackageRequest>
): Result<List<List<String>>> {
fun getVulnerabilityIdsForPackages(requests: List<VulnerabilitiesForPackageRequest>): Result<List<List<String>>> {
if (requests.isEmpty()) return Result.success(emptyList())

val result = mutableListOf<MutableList<String>>()
Expand Down
3 changes: 1 addition & 2 deletions detekt-rules/src/main/kotlin/OrtRuleSet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ import io.gitlab.arturbosch.detekt.api.RuleSetProvider
class OrtRuleSet : RuleSetProvider {
override val ruleSetId: String = "ORT"

override fun instance(config: Config) =
RuleSet(ruleSetId, listOf(OrtImportOrder(config), OrtPackageNaming(config)))
override fun instance(config: Config) = RuleSet(ruleSetId, listOf(OrtImportOrder(config), OrtPackageNaming(config)))
}
13 changes: 9 additions & 4 deletions downloader/src/main/kotlin/VcsHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ enum class VcsHost(
val unknownVcsInfo = VcsInfo.EMPTY.copy(url = projectUrl)
val projectUri = projectUrl.toUri().getOrElse { return unknownVcsInfo }

fun URI.isTfsGitUrl() = path != null && host != null &&
("/tfs/" in path || ".visualstudio.com" in host) && "/_git/" in path
fun URI.isTfsGitUrl() =
path != null && host != null && ("/tfs/" in path || ".visualstudio.com" in host) && "/_git/" in path

// Fall back to generic URL detection for unknown VCS hosts.
val svnBranchOrTagMatch = SVN_BRANCH_OR_TAG_PATTERN.matchEntire(projectUrl)
Expand Down Expand Up @@ -587,8 +587,13 @@ private fun gitProjectUrlToVcsInfo(projectUrl: URI, pathParser: (String, Iterato
}

private fun toGitPermalink(
vcsUrl: URI, revision: String, path: String, startLine: Int, endLine: Int,
startLineMarker: String, endLineMarker: String
vcsUrl: URI,
revision: String,
path: String,
startLine: Int,
endLine: Int,
startLineMarker: String,
endLineMarker: String
): String {
var permalink = "https://${vcsUrl.host}${vcsUrl.path.removeSuffix(".git")}"

Expand Down
3 changes: 2 additions & 1 deletion downloader/src/main/kotlin/VersionControlSystem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ abstract class VersionControlSystem(
/**
* Return the applicable VCS for the given [vcsType], or null if none is applicable.
*/
fun forType(vcsType: VcsType) = ALL.find {
fun forType(vcsType: VcsType) =
ALL.find {
it.isAvailable() && it.isApplicableType(vcsType)
}

Expand Down
3 changes: 2 additions & 1 deletion downloader/src/main/kotlin/vcs/Git.kt
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ class Git : VersionControlSystem(), CommandLineTool {
match.groups["version"]!!.value
}.orEmpty()

override fun getWorkingTree(vcsDirectory: File): WorkingTree = GitWorkingTree(
override fun getWorkingTree(vcsDirectory: File): WorkingTree =
GitWorkingTree(
workingDir = vcsDirectory,
vcsType = type,
repositoryUrlPrefixReplacements = REPOSITORY_URL_PREFIX_REPLACEMENTS
Expand Down
3 changes: 1 addition & 2 deletions downloader/src/main/kotlin/vcs/Mercurial.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ class Mercurial : VersionControlSystem(MercurialCommand) {

override fun getWorkingTree(vcsDirectory: File) = MercurialWorkingTree(vcsDirectory, type)

override fun isApplicableUrlInternal(vcsUrl: String) =
ProcessCapture("hg", "identify", vcsUrl).isSuccess
override fun isApplicableUrlInternal(vcsUrl: String) = ProcessCapture("hg", "identify", vcsUrl).isSuccess

override fun initWorkingTree(targetDir: File, vcs: VcsInfo): WorkingTree {
// We cannot detect beforehand if the Large Files extension would be required, so enable it by default.
Expand Down
3 changes: 1 addition & 2 deletions downloader/src/main/kotlin/vcs/SubversionWorkingTree.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,5 @@ class SubversionWorkingTree(
return refs
}

private fun doSvnInfo() =
runCatching { clientManager.wcClient.doInfo(workingDir, SVNRevision.WORKING) }.getOrNull()
private fun doSvnInfo() = runCatching { clientManager.wcClient.doInfo(workingDir, SVNRevision.WORKING) }.getOrNull()
}
6 changes: 2 additions & 4 deletions evaluator/src/main/kotlin/PackageRule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,7 @@ open class PackageRule(
/**
* Add a [hint][Severity.HINT] to the list of [violations].
*/
fun hint(message: String, howToFix: String) =
hint(pkg.metadata.id, license, licenseSource, message, howToFix)
fun hint(message: String, howToFix: String) = hint(pkg.metadata.id, license, licenseSource, message, howToFix)

/**
* Add a [warning][Severity.WARNING] to the list of [violations].
Expand All @@ -267,7 +266,6 @@ open class PackageRule(
/**
* Add an [error][Severity.ERROR] to the list of [violations].
*/
fun error(message: String, howToFix: String) =
error(pkg.metadata.id, license, licenseSource, message, howToFix)
fun error(message: String, howToFix: String) = error(pkg.metadata.id, license, licenseSource, message, howToFix)
}
}
10 changes: 3 additions & 7 deletions evaluator/src/main/kotlin/ProjectSourceRule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ open class ProjectSourceRule(
/**
* Return the detected licenses for any file matching the given [glob expressions][patterns].
*/
fun projectSourceGetDetectedLicensesByFilePath(
vararg patterns: String
): Map<String, Set<String>> =
fun projectSourceGetDetectedLicensesByFilePath(vararg patterns: String): Map<String, Set<String>> =
detectedLicensesForFilePath.filter { (filePath, _) ->
FileMatcher.match(patterns.toList(), filePath)
}
Expand Down Expand Up @@ -139,8 +137,7 @@ open class ProjectSourceRule(
override val description =
"projectSourceHasFileWithContents('$contentPattern', '${patterns.joinToString()}')"

override fun matches(): Boolean =
projectSourceFindFilesWithContent(contentPattern, *patterns).isNotEmpty()
override fun matches(): Boolean = projectSourceFindFilesWithContent(contentPattern, *patterns).isNotEmpty()
}

/**
Expand All @@ -154,7 +151,6 @@ open class ProjectSourceRule(
override val description =
"projectSourceHasVcsType('${vcsTypes.joinToString()}')"

override fun matches(): Boolean =
projectSourceGetVcsType() in types
override fun matches(): Boolean = projectSourceGetVcsType() in types
}
}
12 changes: 5 additions & 7 deletions evaluator/src/main/kotlin/Rule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ abstract class Rule(
/**
* Return true if all [matchers] match.
*/
private fun matches() = matchers.all { matcher ->
private fun matches() =
matchers.all { matcher ->
matcher.matches().also { matches ->
logger.info { "\t${matcher.description} == $matches" }
if (!matches) logger.info { "\tRule skipped." }
Expand Down Expand Up @@ -155,8 +156,7 @@ abstract class Rule(
licenseSource: LicenseSource?,
message: String,
howToFix: String
) =
issue(Severity.HINT, pkgId, license, licenseSource, message, howToFix)
) = issue(Severity.HINT, pkgId, license, licenseSource, message, howToFix)

/**
* Add a [warning][Severity.WARNING] to the list of [violations].
Expand All @@ -167,8 +167,7 @@ abstract class Rule(
licenseSource: LicenseSource?,
message: String,
howToFix: String
) =
issue(Severity.WARNING, pkgId, license, licenseSource, message, howToFix)
) = issue(Severity.WARNING, pkgId, license, licenseSource, message, howToFix)

/**
* Add an [error][Severity.ERROR] to the list of [violations].
Expand All @@ -179,8 +178,7 @@ abstract class Rule(
licenseSource: LicenseSource?,
message: String,
howToFix: String
) =
issue(Severity.ERROR, pkgId, license, licenseSource, message, howToFix)
) = issue(Severity.ERROR, pkgId, license, licenseSource, message, howToFix)

/**
* A DSL helper class, providing convenience functions for adding [RuleMatcher]s to this rule.
Expand Down
6 changes: 4 additions & 2 deletions evaluator/src/test/kotlin/RuleTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class RuleTest : WordSpec() {
private val message = "violation message"
private val howToFix = "how to fix"

private fun createRule() = object : Rule(ruleSet, "test") {
private fun createRule() =
object : Rule(ruleSet, "test") {
override val description = "test"
override fun issueSource() = name
}
Expand Down Expand Up @@ -102,7 +103,8 @@ class RuleTest : WordSpec() {

"require" should {
"add the expected matchers" {
fun matcher() = object : RuleMatcher {
fun matcher() =
object : RuleMatcher {
override val description = "test"
override fun matches() = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ private fun getScannedPackages(
return result.distinct()
}

private fun createAnalyzerResult(packages: Collection<ScannedPackage>) = OrtResult.EMPTY.copy(
private fun createAnalyzerResult(packages: Collection<ScannedPackage>) =
OrtResult.EMPTY.copy(
analyzer = AnalyzerRun(
startTime = Instant.now(),
endTime = Instant.now(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ internal class SetDependencyRepresentationCommand : CliktCommand(
enum class TargetFormat {
/** The dependency graph format. */
GRAPH {
override fun convert(result: AnalyzerResult): AnalyzerResult =
DependencyGraphConverter.convert(result)
override fun convert(result: AnalyzerResult): AnalyzerResult = DependencyGraphConverter.convert(result)
},

/** The classic dependency tree format. */
Expand Down
Loading

0 comments on commit f3123a7

Please sign in to comment.