Skip to content
This repository has been archived by the owner on Jul 30, 2023. It is now read-only.

Commit

Permalink
#1 Consistent line length enforcement by Spotless & Ktlint
Browse files Browse the repository at this point in the history
  • Loading branch information
mjstrasser committed Jul 6, 2023
1 parent 846acb0 commit 91fa7b4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*.{kt,kts}]
max_line_length = 100
Original file line number Diff line number Diff line change
Expand Up @@ -51,53 +51,36 @@ fun Project.configureSpotless(ktlintVersion: String) {

configure<SpotlessExtension> {
format("markdown") {
target(
fileTree(
mapOf(
"dir" to ".",
"include" to listOf("**/*.md"),
"exclude" to listOf(".gradle/**", ".gradle-cache/**", ".batect/**", "build/**")
)
)
)

target("**/*.md")
targetExclude(".gradle/**", ".gradle-cache/**", ".batect/**", "build/**")
indentWithSpaces()
endWithNewline()
}

format("misc") {
target(
fileTree(
mapOf(
"dir" to ".",
"include" to listOf("**/.gitignore", "**/*.yaml", "**/*.yml", "**/*.sh", "**/Dockerfile"),
"exclude" to listOf("**/*.md", ".gradle/**", ".gradle-cache/**", ".batect/**", "build/**")
)
)
)

target("**/.gitignore", "**/*.yaml", "**/*.yml", "**/*.sh", "**/Dockerfile")
targetExclude("**/*.md", ".gradle/**", ".gradle-cache/**", ".batect/**", "build/**")
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}

kotlinGradle {
target("*.gradle.kts", "gradle/*.gradle.kts", "buildSrc/*.gradle.kts")
target("*.gradle.kts", "gradle/*.gradle.kts", "buildSrc/*.gradle.kts", "buildSrc/**/*.kt")
ktlint(ktlintVersion)
.editorConfigOverride(mapOf("max_line_length" to "off"))

@Suppress("INACCESSIBLE_TYPE")
licenseHeader(kotlinLicenceHeader, "import|tasks|apply|plugins|rootProject|dependencyResolutionManagement")
licenseHeader(kotlinLicenceHeader, "package|import|tasks|apply|plugins|rootProject|dependencyResolutionManagement")

trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}

kotlin {
target("src/**/*.kt", "buildSrc/**/*.kt")
target("src/**/*.kt")
ktlint(ktlintVersion)

@Suppress("INACCESSIBLE_TYPE")
licenseHeader(kotlinLicenceHeader)

trimTrailingWhitespace()
Expand All @@ -108,7 +91,6 @@ fun Project.configureSpotless(ktlintVersion: String) {
java {
target("src/**/*.java")

@Suppress("INACCESSIBLE_TYPE")
licenseHeader(kotlinLicenceHeader)

trimTrailingWhitespace()
Expand Down
7 changes: 6 additions & 1 deletion src/main/kotlin/io/klogging/slf4j/NoCoLoggerWrapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,12 @@ public class NoCoLoggerWrapper(
* Forward an event and exception with context items from [MDC], handling null [format] and
* absence of [arguments].
*/
private fun emitEvent(level: Level, throwable: Throwable?, format: String? = null, vararg arguments: Any?) {
private fun emitEvent(
level: Level,
throwable: Throwable?,
format: String? = null,
vararg arguments: Any?
) {
val formatted = MessageFormatter.arrayFormat(format, arguments).message
if (format == null || arguments.isEmpty()) {
noCoLogger.emitEvent(level, throwable, formatted, contextItems())
Expand Down
12 changes: 10 additions & 2 deletions src/test/kotlin/io/klogging/slf4j/NoCoLoggerWrapperTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,12 @@ class NoCoLoggerWrapperTest : DescribeSpec({
val id = randomString()
val name = randomString()
val age = Random.nextInt(50)
LoggerFactory.getLogger(randomString()).info("User {id} called {name} is {age}", id, name, age)
LoggerFactory.getLogger(randomString()).info(
"User {id} called {name} is {age}",
id,
name,
age
)
waitForDispatch()

saved shouldHaveSize 1
Expand Down Expand Up @@ -224,7 +229,10 @@ class NoCoLoggerWrapperTest : DescribeSpec({

it("passes `Throwable` object") {
val saved = savedEvents()
LoggerFactory.getLogger(randomString()).warn(randomString(), java.lang.RuntimeException(randomString()))
LoggerFactory.getLogger(randomString()).warn(
randomString(),
java.lang.RuntimeException(randomString())
)
waitForDispatch()

saved shouldHaveSize 1
Expand Down

0 comments on commit 91fa7b4

Please sign in to comment.