Skip to content

Commit 62d297f

Browse files
committed
lint
1 parent 75b46cd commit 62d297f

File tree

25 files changed

+80
-65
lines changed

25 files changed

+80
-65
lines changed

.editorconfig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
[*.{kt,kts}]
2-
disabled_rules=no-wildcard-imports
2+
ktlint_code_style = ktlint_official
3+
ktlint_disabled_rules = no-wildcard-imports
4+
ij_kotlin_allow_trailing_comma_on_call_site = true

build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ tasks {
6060

6161
val publish by creating {
6262
group = "publishing"
63-
if (!isSnapshot)
63+
if (!isSnapshot) {
6464
finalizedBy("closeAndReleaseSonatypeStagingRepository", ":docs:orchidDeploy", ":gradle-plugin:publishPlugins")
65+
}
6566
}
6667

6768
val version by creating {

docs/src/orchid/kotlin/com/intuit/hooks/docs/HooksTheme.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ class HooksTheme @Inject constructor(context: OrchidContext) : Theme(context, "H
3535
listOfNotNull(super.getResourceSource(), delegateTheme.resourceSource),
3636
emptyList(),
3737
priority,
38-
ThemeResourceSource
38+
ThemeResourceSource,
3939
)
4040
}

example-library/src/test/kotlin/CarHooksTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.intuit.hooks.example.library
22

33
import com.intuit.hooks.example.library.car.Car
4-
import org.junit.jupiter.api.Assertions.*
4+
import org.junit.jupiter.api.Assertions.assertEquals
55
import org.junit.jupiter.api.Test
66

77
internal class CarHooksTest {

example-library/src/test/kotlin/GenericHookTests.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.intuit.hooks.example.library
22

3-
import com.intuit.hooks.BailResult.*
3+
import com.intuit.hooks.BailResult.Bail
4+
import com.intuit.hooks.BailResult.Continue
45
import com.intuit.hooks.HookContext
56
import com.intuit.hooks.LoopResult
67
import com.intuit.hooks.example.library.generic.GenericHooksImpl
@@ -140,6 +141,7 @@ class GenericHookTests {
140141
val result = h.call("Kian")
141142
Assertions.assertEquals("bail now", result)
142143
}
144+
143145
@Test
144146
fun `async series loop`() = runBlocking {
145147
var incrementedA = 0

gradle-plugin/src/main/kotlin/com/intuit/hooks/plugin/gradle/HooksGradlePlugin.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,18 @@ public class HooksGradlePlugin : Plugin<Project> {
2121

2222
private fun Project.addDependency(configuration: String, dependencyNotation: String) = configurations
2323
.getByName(configuration).dependencies.add(
24-
dependencies.create(dependencyNotation)
24+
dependencies.create(dependencyNotation),
2525
)
2626

2727
override fun apply(project: Project): Unit = with(project) {
2828
extensions.create(
2929
"hooks",
30-
HooksGradleExtension::class.java
30+
HooksGradleExtension::class.java,
3131
)
3232

33-
if (!pluginManager.hasPlugin("com.google.devtools.ksp"))
33+
if (!pluginManager.hasPlugin("com.google.devtools.ksp")) {
3434
pluginManager.apply("com.google.devtools.ksp")
35+
}
3536

3637
addDependency("api", "com.intuit.hooks:hooks:$hooksVersion")
3738
addDependency("ksp", "com.intuit.hooks:processor:$hooksVersion")

gradle-plugin/src/test/kotlin/HooksGradlePluginTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ class HooksGradlePluginTest {
3333
kotlin("jvm")
3434
id("com.intuit.hooks")
3535
}
36-
"""
36+
""",
3737
)
3838
}
3939

4040
@Test fun `can apply plugin`() {
4141
buildFile.appendKotlin(
4242
"""
4343
hooks {}
44-
"""
44+
""",
4545
)
4646

4747
assertDoesNotThrow {
@@ -66,7 +66,7 @@ class HooksGradlePluginTest {
6666
@Sync<(String) -> Unit>
6767
abstract val testSyncHook: Hook
6868
}
69-
"""
69+
""",
7070
)
7171

7272
val runner = GradleRunner.create()

hooks/src/main/kotlin/com/intuit/hooks/BaseHook.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public data class TapInfo<FWithContext : Function<*>> internal constructor(
3737
public val name: String,
3838
public val id: String,
3939
public val type: String,
40-
public val f: FWithContext,
40+
public val f: FWithContext
4141
// val stage: Int, // todo: maybe this should be forEachIndexed?
4242
// before?: string | Array // todo: do we even really need this?
4343
)

hooks/src/main/kotlin/com/intuit/hooks/dsl/Hooks.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ public abstract class Hooks {
6060
ReplaceWith("@Hooks.AsyncParallelBail<F>"),
6161
DeprecationLevel.ERROR,
6262
)
63-
@ExperimentalCoroutinesApi protected fun <F : Function<BailResult<*>>> asyncParallelBailHook(): AsyncParallelBailHook<*, *> = stub()
63+
@ExperimentalCoroutinesApi
64+
protected fun <F : Function<BailResult<*>>> asyncParallelBailHook(): AsyncParallelBailHook<*, *> = stub()
6465

6566
protected annotation class AsyncSeries<F : Function<*>>
6667

hooks/src/test/kotlin/com/intuit/hooks/AsyncSeriesLoopHookTests.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.intuit.hooks
22

3-
import io.mockk.*
3+
import io.mockk.coEvery
4+
import io.mockk.coVerify
5+
import io.mockk.mockk
46
import kotlinx.coroutines.delay
57
import kotlinx.coroutines.runBlocking
68
import org.junit.jupiter.api.Assertions
@@ -10,7 +12,7 @@ class AsyncSeriesLoopHookTests {
1012
class LoopHook1<T1> : AsyncSeriesLoopHook<suspend (HookContext, T1) -> LoopResult, suspend (HookContext, T1) -> Unit>() {
1113
suspend fun call(p1: T1) = super.call(
1214
invokeTap = { f, context -> f(context, p1) },
13-
invokeInterceptor = { f, context -> f(context, p1) }
15+
invokeInterceptor = { f, context -> f(context, p1) },
1416
)
1517
}
1618

hooks/src/test/kotlin/com/intuit/hooks/AsyncSeriesWaterfallHookTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class AsyncSeriesWaterfallHookTests {
1010
suspend fun call(p1: R) = super.call(
1111
p1,
1212
invokeTap = { f, r, context -> f(context, r) },
13-
invokeInterceptor = { f, context -> f(context, p1) }
13+
invokeInterceptor = { f, context -> f(context, p1) },
1414
)
1515
}
1616

hooks/src/test/kotlin/com/intuit/hooks/SyncLoopHookTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class SyncLoopHookTests {
1313
class LoopHook1<T1> : SyncLoopHook<(HookContext, T1) -> LoopResult, (HookContext, T1) -> Unit>() {
1414
fun call(p1: T1) = super.call(
1515
invokeTap = { f, context -> f(context, p1) },
16-
invokeInterceptor = { f, context -> f(context, p1) }
16+
invokeInterceptor = { f, context -> f(context, p1) },
1717
)
1818
}
1919

hooks/src/test/kotlin/com/intuit/hooks/SyncWaterfallHookTests.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ class SyncWaterfallHookTests {
88
fun call(p1: T1) = super.call(
99
p1,
1010
invokeTap = { f, acc, context -> f(context, acc) },
11-
invokeInterceptor = { f, context -> f(context, p1) }
11+
invokeInterceptor = { f, context -> f(context, p1) },
1212
)
1313
}
1414

1515
class Hook2<T1, T2> : SyncWaterfallHook<(HookContext, T1, T2) -> T1, T1>() {
1616
fun call(p1: T1, p2: T2) = super.call(
1717
p1,
1818
invokeTap = { f, acc, context -> f(context, acc, p2) },
19-
invokeInterceptor = { f, context -> f(context, p1, p2) }
19+
invokeInterceptor = { f, context -> f(context, p1, p2) },
2020
)
2121
}
2222

maven-plugin/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ tasks {
1616
from(
1717
configurations.compileClasspath.get().filter { dependency ->
1818
dependency.absolutePath.contains("kotlin-maven-symbol-processing")
19-
}.map(::zipTree)
19+
}.map(::zipTree),
2020
) {
2121
this.duplicatesStrategy = DuplicatesStrategy.EXCLUDE
2222
}

processor/src/main/kotlin/com/intuit/hooks/plugin/Raise.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public inline fun <Error, A> Iterable<A>.accumulate(
4444
flatMap {
4545
recover({
4646
operation(it); emptyList()
47-
}) { it }
47+
},) { it }
4848
}.toNonEmptyListOrNull()?.let { raise(it) }
4949
}
5050

@@ -62,7 +62,7 @@ public inline fun <Error, A, B> Iterable<A>.mapOrAccumulate( // TODO: Consider r
6262
@BuilderInference operation: Raise<Nel<Error>>.(A) -> B
6363
): List<B> = recover({
6464
mapOrAccumulate(this@mapOrAccumulate) { operation(it) }
65-
}) { errors -> raise(errors.flatMap { it }) }
65+
},) { errors -> raise(errors.flatMap { it }) }
6666

6767
/** [mapOrAccumulate] variant that accumulates errors from a validator that may raise multiple errors */
6868
context(Raise<NonEmptyList<Error>>)
@@ -71,7 +71,7 @@ public inline fun <Error, A, B> NonEmptyList<A>.mapOrAccumulate( // TODO: Consid
7171
@BuilderInference operation: Raise<Nel<Error>>.(A) -> B
7272
): NonEmptyList<B> = recover({
7373
mapOrAccumulate(this@mapOrAccumulate) { operation(it) }
74-
}) { errors -> raise(errors.flatMap { it }) }
74+
},) { errors -> raise(errors.flatMap { it }) }
7575

7676
/** [mapOrAccumulate] variant that accumulates errors from a validator that may raise multiple errors */
7777
context(Raise<NonEmptyList<Error>>)
@@ -80,4 +80,4 @@ public inline fun <Error, A, B> NonEmptySet<A>.mapOrAccumulate( // TODO: Conside
8080
@BuilderInference operation: Raise<Nel<Error>>.(A) -> B
8181
): NonEmptySet<B> = recover({
8282
mapOrAccumulate(this@mapOrAccumulate) { operation(it) }
83-
}) { errors -> raise(errors.flatMap { it }) }
83+
},) { errors -> raise(errors.flatMap { it }) }

processor/src/main/kotlin/com/intuit/hooks/plugin/codegen/HookInfo.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ internal data class HooksContainer(
1414
val superclass get() = originalClassName.let {
1515
if (typeArguments.isNotEmpty()) {
1616
it.parameterizedBy(typeArguments)
17-
} else
17+
} else {
1818
it
19+
}
1920
}
2021
}
2122

@@ -24,7 +25,7 @@ internal data class HookSignature(
2425
val isSuspend: Boolean,
2526
val returnType: TypeName,
2627
val returnTypeType: TypeName?,
27-
val hookFunctionSignatureType: TypeName,
28+
val hookFunctionSignatureType: TypeName
2829
) {
2930
val nullableReturnTypeType: TypeName get() {
3031
requireNotNull(returnTypeType)
@@ -36,7 +37,7 @@ internal data class HookSignature(
3637
internal class HookParameter(
3738
val name: String?,
3839
val type: TypeName,
39-
val position: Int,
40+
val position: Int
4041
) {
4142
val withType get() = "$withoutType: $type"
4243
val withoutType get() = name ?: "p$position"

processor/src/main/kotlin/com/intuit/hooks/plugin/codegen/Poet.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ internal fun HookInfo.generateClass(): TypeSpec {
4444
val callBuilder = FunSpec.builder("call")
4545
.addParameters(parameterSpecs)
4646
.apply {
47-
if (this@generateClass.isAsync)
47+
if (this@generateClass.isAsync) {
4848
addModifiers(KModifier.SUSPEND)
49+
}
4950
}
5051

5152
val (superclass, call) = when (hookType) {
@@ -66,7 +67,7 @@ internal fun HookInfo.generateClass(): TypeSpec {
6667
.addCode(
6768
"return super.call(invokeTap = %L, invokeInterceptor = %L)",
6869
CodeBlock.of("{ f, context -> f(context, $paramsWithoutTypes) }"),
69-
CodeBlock.of("{ f, context -> f(context, $paramsWithoutTypes) }")
70+
CodeBlock.of("{ f, context -> f(context, $paramsWithoutTypes) }"),
7071
)
7172

7273
Pair(superclass, call)
@@ -81,7 +82,7 @@ internal fun HookInfo.generateClass(): TypeSpec {
8182
"return super.call(%N, invokeTap = %L, invokeInterceptor = %L)",
8283
accumulatorName,
8384
CodeBlock.of("{ f, %N, context -> f(context, $paramsWithoutTypes) }", accumulatorName),
84-
CodeBlock.of("{ f, context -> f(context, $paramsWithoutTypes) }")
85+
CodeBlock.of("{ f, context -> f(context, $paramsWithoutTypes) }"),
8586
)
8687

8788
Pair(superclass, call)
@@ -127,7 +128,7 @@ private val HookInfo.lambdaTypeName get() = createHookContextLambda(hookSignatur
127128
private fun HookInfo.createHookContextLambda(returnType: TypeName): LambdaTypeName {
128129
val get = LambdaTypeName.get(
129130
parameters = listOf(ParameterSpec.unnamed(hookContext)) + parameterSpecs,
130-
returnType = returnType
131+
returnType = returnType,
131132
)
132133

133134
return if (this.isAsync) get.copy(suspending = true) else get

processor/src/main/kotlin/com/intuit/hooks/plugin/ksp/HooksProcessor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class HooksProcessor(
5656
}, { throwable: Throwable ->
5757
logger.error("Uncaught exception while processing file: ${throwable.localizedMessage}", file)
5858
logger.exception(throwable)
59-
})
59+
},)
6060
}
6161
}
6262

@@ -107,7 +107,7 @@ public class HooksProcessor(
107107
typeSpecKind,
108108
visibilityModifier,
109109
typeArguments,
110-
hooks
110+
hooks,
111111
)
112112
}
113113
}

processor/src/main/kotlin/com/intuit/hooks/plugin/ksp/Text.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ internal val KSTypeArgument.text: String get() = when (variance) {
99
else -> "${variance.label} ${type!!.text}"
1010
}
1111

12-
internal val List<KSTypeArgument>.text: String get() = if (isEmpty()) "" else
12+
internal val List<KSTypeArgument>.text: String get() = if (isEmpty()) {
13+
""
14+
} else {
1315
"<${joinToString(transform = KSTypeArgument::text)}>"
16+
}
1417

1518
internal val KSTypeReference.text: String get() = element?.let {
1619
when (it) {

processor/src/main/kotlin/com/intuit/hooks/plugin/ksp/validation/AnnotationValidations.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ internal fun KSPropertyDeclaration.validateHookAnnotation(parentResolver: TypePa
6464
{ annotation.mustBeHookType(parentResolver) },
6565
{ annotation.validateParameters(parentResolver) },
6666
{ getVisibility().toKModifier() ?: KModifier.PUBLIC },
67-
::HookInfo
67+
::HookInfo,
6868
)
6969
}
7070

@@ -106,7 +106,7 @@ private fun HookAnnotation.mustBeHookType(parentResolver: TypeParameterResolver)
106106
isSuspend,
107107
returnType,
108108
returnTypeType,
109-
hookFunctionSignatureType
109+
hookFunctionSignatureType,
110110
)
111111
} catch (exception: Exception) {
112112
raise(HookValidationError.MustBeHookTypeSignature(this))

processor/src/main/kotlin/com/intuit/hooks/plugin/ksp/validation/HookPropertyValidations.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import com.intuit.hooks.plugin.ensure
1010
context(Raise<Nel<HookValidationError>>)
1111
internal fun HookProperty.validate(
1212
info: HookInfo,
13-
property: KSPropertyDeclaration,
13+
property: KSPropertyDeclaration
1414
) {
1515
when (this) {
1616
is HookProperty.Bail -> Unit
@@ -30,7 +30,7 @@ private fun HookInfo.validateAsync(property: KSPropertyDeclaration) {
3030
context(Raise<Nel<HookValidationError>>)
3131
private fun HookProperty.Waterfall.validate(
3232
info: HookInfo,
33-
property: KSPropertyDeclaration,
33+
property: KSPropertyDeclaration
3434
) {
3535
zipOrAccumulate(
3636
{ arity(info, property) },
@@ -41,15 +41,15 @@ private fun HookProperty.Waterfall.validate(
4141
context(Raise<HookValidationError.WaterfallMustHaveParameters>)
4242
private fun HookProperty.Waterfall.arity(
4343
info: HookInfo,
44-
property: KSPropertyDeclaration,
44+
property: KSPropertyDeclaration
4545
) {
4646
ensure(!info.zeroArity) { HookValidationError.WaterfallMustHaveParameters(property) }
4747
}
4848

4949
context(Raise<HookValidationError.WaterfallParameterTypeMustMatch>)
5050
private fun HookProperty.Waterfall.parameters(
5151
info: HookInfo,
52-
property: KSPropertyDeclaration,
52+
property: KSPropertyDeclaration
5353
) {
5454
ensure(info.hookSignature.returnType == info.params.firstOrNull()?.type) {
5555
HookValidationError.WaterfallParameterTypeMustMatch(property)

0 commit comments

Comments
 (0)