Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
Spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacSweers committed Feb 3, 2024
1 parent 0f855ab commit 5c29535
Show file tree
Hide file tree
Showing 22 changed files with 73 additions and 90 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ spotless {
endWithNewline()
licenseHeaderFile(
"spotless/spotless.kt",
"(import|plugins|buildscript|dependencies|pluginManagement)"
"(import|plugins|buildscript|dependencies|pluginManagement)",
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/slack/cli/CliUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public fun Sequence<File>.filterByExtension(extension: String): Sequence<File> {
/** Filters by a specific [name]. */
public fun Sequence<File>.filterByName(
name: String,
withoutExtension: Boolean = true
withoutExtension: Boolean = true,
): Sequence<File> {
return if (withoutExtension) {
filter { it.nameWithoutExtension == name }
Expand All @@ -94,7 +94,7 @@ public fun Sequence<Path>.filterByExtension(extension: String): Sequence<Path> {
@JvmName("filterByNamePath")
public fun Sequence<Path>.filterByName(
name: String,
withoutExtension: Boolean = true
withoutExtension: Boolean = true,
): Sequence<Path> {
return if (withoutExtension) {
filter { it.nameWithoutExtension == name }
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/slack/cli/CliktExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@file:Suppress(
"LongParameterList", // These are how many parameters are in Clikt options.
"SpreadOperator", // Not spreading would change semantics.
"unused"
"unused",
)

package slack.cli
Expand All @@ -34,14 +34,14 @@ import java.nio.file.Paths
/** A dry run option for [clikt commands][CliktCommand]. */
public fun CliktCommand.dryRunOption(
vararg names: String = arrayOf("--dry-run"),
help: String = "Runs this as a dry run, no modifications."
help: String = "Runs this as a dry run, no modifications.",
): OptionWithValues<Boolean, Boolean, Boolean> =
option(names = names, help = help).flag(default = false)

/** A project dir option for [clikt commands][CliktCommand]. */
public fun CliktCommand.projectDirOption(
vararg names: String = arrayOf("--project-dir"),
help: String = "The project directory. Defaults to the current working directory."
help: String = "The project directory. Defaults to the current working directory.",
): OptionDelegate<Path> =
option(names = names, help = help).path(mustExist = true, canBeFile = false).defaultLazy {
Paths.get("").toAbsolutePath()
Expand Down
10 changes: 4 additions & 6 deletions src/main/kotlin/slack/cli/buildkite/BuildkiteDataBindings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ public data class ExternalNotification(
@Serializable
public data class GithubCheck(
/** GitHub commit status name */
val context: String? = null,
val context: String? = null
)

@Serializable
public data class GithubCommitStatus(
/** GitHub commit status name */
val context: String? = null,
val context: String? = null
)

@Serializable
Expand Down Expand Up @@ -715,7 +715,7 @@ public sealed interface SoftFail {
@Serializable
public data class SoftFailElement(
/** The exit status number that will cause this job to soft-fail */
@SerialName("exit_status") val exitStatus: ExitStatusUnion? = null,
@SerialName("exit_status") val exitStatus: ExitStatusUnion? = null
)

@Serializable
Expand Down Expand Up @@ -764,9 +764,7 @@ public sealed interface Setup {
public sealed interface Plugins {
@Serializable
@JvmInline
public value class AnythingMapValue(
public val value: JsonObject,
) : Plugins
public value class AnythingMapValue(public val value: JsonObject) : Plugins

@Serializable
@JvmInline
Expand Down
8 changes: 3 additions & 5 deletions src/main/kotlin/slack/cli/buildkite/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,15 @@ public object Conditions {

public fun githubStatusNotif(
context: String,
notifyIf: String = Conditions.NOT_CANCELLING
notifyIf: String = Conditions.NOT_CANCELLING,
): Notification =
Notification(
ExternalNotification(
githubCommitStatus = GithubCommitStatus(context = context),
notifyIf = notifyIf
notifyIf = notifyIf,
)
)

public fun CommandStep.withGithubStatus(context: String): CommandStep {
return copy(
notify = listOf(githubStatusNotif(context)),
)
return copy(notify = listOf(githubStatusNotif(context)))
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ internal object JsonObjectAsMapSerializer : KSerializer<JsonObject> {
buildClassSerialDescriptor("JsonObjectAsMap") {
element(
"properties",
mapSerialDescriptor(String.serializer().descriptor, JsonElementKamlSerializer.descriptor)
mapSerialDescriptor(String.serializer().descriptor, JsonElementKamlSerializer.descriptor),
)
}

override fun serialize(encoder: Encoder, value: JsonObject) {
val map = value.mapValues { it.value }
encoder.encodeSerializableValue(
MapSerializer(String.serializer(), JsonElementKamlSerializer),
map
map,
)
}

Expand Down Expand Up @@ -132,7 +132,7 @@ internal object JsonPrimitiveSerializer : KSerializer<JsonPrimitive> {
throw JsonDecodingException(
-1,
"Unexpected JSON element, expected JsonPrimitive, had ${result::class}",
result.toString()
result.toString(),
)
}
return result
Expand Down Expand Up @@ -205,7 +205,7 @@ private object JsonLiteralSerializer : KSerializer<JsonLiteral> {
throw JsonDecodingException(
-1,
"Unexpected JSON element, expected JsonLiteral, had ${result::class}",
result.toString()
result.toString(),
)
}
return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class GradleProjectFlattenerCli : CliktCommand(help = DESCRIPTION) {
"-s",
help =
"The settings.gradle file to use. Note this file _must_ only have a single, top-level `include()` call " +
"with vararg project args."
"with vararg project args.",
)
.path(mustExist = true, canBeDir = false)
.required()
Expand Down
12 changes: 6 additions & 6 deletions src/main/kotlin/slack/cli/gradle/GradleSettingsVerifierCli.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class GradleSettingsVerifierCli : CliktCommand(help = DESCRIPTION) {
"-s",
help =
"The settings.gradle file to use. Note this file _must_ only have a single, top-level `include()` call " +
"with vararg project args."
"with vararg project args.",
)
.path(mustExist = true, canBeDir = false)
.required()
Expand All @@ -71,15 +71,15 @@ public class GradleSettingsVerifierCli : CliktCommand(help = DESCRIPTION) {
"--implicit-path",
"-i",
help =
"Implicit project names that may not be present in the settings file but should be assumed present."
"Implicit project names that may not be present in the settings file but should be assumed present.",
)
.multiple()

private val deleteUnIncludedPaths by
option(
"--delete-un-included-paths",
"-d",
help = "Delete any paths that are not included in the settings file."
help = "Delete any paths that are not included in the settings file.",
)
.flag()

Expand Down Expand Up @@ -143,19 +143,19 @@ public class GradleSettingsVerifierCli : CliktCommand(help = DESCRIPTION) {
!realPath.exists() -> {
reportError(
"Project dir '${realPath.relativeTo(projectDir)}' does not exist.",
line.indexOfFirst { !it.isWhitespace() }
line.indexOfFirst { !it.isWhitespace() },
)
}
!realPath.resolve("build.gradle.kts").exists() -> {
reportError(
"Project build file '${realPath.relativeTo(projectDir).resolve("build.gradle.kts")}' does not exist.",
line.indexOfFirst { !it.isWhitespace() }
line.indexOfFirst { !it.isWhitespace() },
)
}
!realPath.isDirectory() -> {
reportError(
"Expected '$realPath' to be a directory.",
line.indexOfFirst { !it.isWhitespace() }
line.indexOfFirst { !it.isWhitespace() },
)
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/main/kotlin/slack/cli/lint/LintBaselineMergerCli.kt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public class LintBaselineMergerCli : CliktCommand(DESCRIPTION) {
help =
"Template for messages with each issue. This message can optionally " +
"contain '{id}' in it to be replaced with the issue ID and '{message}' " +
"for the original message."
"for the original message.",
)
.default("{message}")

Expand All @@ -117,7 +117,7 @@ public class LintBaselineMergerCli : CliktCommand(DESCRIPTION) {
name = issue.id,
shortDescription = MultiformatMessageString(text = issue.message),
fullDescription = MultiformatMessageString(text = issue.message),
defaultConfiguration = ReportingConfiguration(level = Level.Error)
defaultConfiguration = ReportingConfiguration(level = Level.Error),
)
}
.sortedBy { it.id }
Expand All @@ -141,7 +141,7 @@ public class LintBaselineMergerCli : CliktCommand(DESCRIPTION) {
{ it.id },
{ it.location.file },
{ it.location.line },
{ it.location.column }
{ it.location.column },
)
)
.map { key -> key to issues.getValue(key) }
Expand All @@ -157,11 +157,11 @@ public class LintBaselineMergerCli : CliktCommand(DESCRIPTION) {
Message(
text =
messageTemplate.replace("{id}", id).replace("{message}", issue.message)
)
),
)
}
},
)
)
),
)

SarifSerializer.toJson(outputSarif).let { outputFile.writeText(it) }
Expand Down Expand Up @@ -212,7 +212,7 @@ public class LintBaselineMergerCli : CliktCommand(DESCRIPTION) {
@Serializable(HtmlEscapeStringSerializer::class) val name: String,
@Serializable(HtmlEscapeStringSerializer::class) val variant: String,
@Serializable(HtmlEscapeStringSerializer::class) val version: String,
val issues: List<LintIssue>
val issues: List<LintIssue>,
) {
@Serializable
@XmlSerialName("issue")
Expand Down Expand Up @@ -269,8 +269,8 @@ public class LintBaselineMergerCli : CliktCommand(DESCRIPTION) {
$errorLine2
"""
.trimIndent()
)
)
),
),
)
)
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/slack/cli/sarif/ApplyBaselinesToSarifs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class ApplyBaselinesToSarifs : CliktCommand(help = DESCRIPTION) {
"--remove-uri-prefixes",
help =
"When enabled, removes the root project directory from location uris such that they are only " +
"relative to the root project dir."
"relative to the root project dir.",
)
.flag()

Expand Down Expand Up @@ -172,7 +172,7 @@ public class ApplyBaselinesToSarifs : CliktCommand(help = DESCRIPTION) {
newCurrentSchema.mergeWith(
absentResultsSchema,
removeUriPrefixes = removeUriPrefixes,
log = ::echo
log = ::echo,
)
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/slack/cli/sarif/MergeSarifReports.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class MergeSarifReports : CliktCommand(help = DESCRIPTION) {
option(
"--remap-src-roots",
help =
"When enabled, remaps uri roots to include the subproject path (relative to the root project)."
"When enabled, remaps uri roots to include the subproject path (relative to the root project).",
)
.flag()

Expand All @@ -75,15 +75,15 @@ public class MergeSarifReports : CliktCommand(help = DESCRIPTION) {
"--remove-uri-prefixes",
help =
"When enabled, removes the root project directory from location uris such that they are only " +
"relative to the root project dir."
"relative to the root project dir.",
)
.flag()

private val allowEmpty by
option(
"--allow-empty",
help = "Flag to allow graceful exiting if no sarif files are found.",
envvar = "SARIF_MERGING_ALLOW_EMPTY"
envvar = "SARIF_MERGING_ALLOW_EMPTY",
)
.flag()

Expand Down Expand Up @@ -229,7 +229,7 @@ public class MergeSarifReports : CliktCommand(help = DESCRIPTION) {
)
}
)
}
},
)
}
)
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/slack/cli/sarif/SarifUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import java.util.Objects
internal val BASELINE_SUPPRESSION: Suppression =
Suppression(
kind = SuppressionKind.External,
justification = "This issue was suppressed by the baseline"
justification = "This issue was suppressed by the baseline",
)

/**
Expand Down Expand Up @@ -97,7 +97,7 @@ internal fun CliktCommand.levelOption(): NullableOption<Level, Level> {
return option(
"--level",
"-l",
help = "Priority level. Defaults to Error. Options are $LEVEL_NAMES"
help = "Priority level. Defaults to Error. Options are $LEVEL_NAMES",
)
.enum<Level>()
}
Expand Down
Loading

0 comments on commit 5c29535

Please sign in to comment.