Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
lint
  • Loading branch information
sugarmanz committed May 17, 2023
commit 62d297f398ac8450adeefd5103b18af7600a2fb7
4 changes: 3 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
[*.{kt,kts}]
disabled_rules=no-wildcard-imports
ktlint_code_style = ktlint_official
ktlint_disabled_rules = no-wildcard-imports
ij_kotlin_allow_trailing_comma_on_call_site = true
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ tasks {

val publish by creating {
group = "publishing"
if (!isSnapshot)
if (!isSnapshot) {
finalizedBy("closeAndReleaseSonatypeStagingRepository", ":docs:orchidDeploy", ":gradle-plugin:publishPlugins")
}
}

val version by creating {
Expand Down
2 changes: 1 addition & 1 deletion docs/src/orchid/kotlin/com/intuit/hooks/docs/HooksTheme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ class HooksTheme @Inject constructor(context: OrchidContext) : Theme(context, "H
listOfNotNull(super.getResourceSource(), delegateTheme.resourceSource),
emptyList(),
priority,
ThemeResourceSource
ThemeResourceSource,
)
}
2 changes: 1 addition & 1 deletion example-library/src/test/kotlin/CarHooksTest.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.intuit.hooks.example.library

import com.intuit.hooks.example.library.car.Car
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

internal class CarHooksTest {
Expand Down
4 changes: 3 additions & 1 deletion example-library/src/test/kotlin/GenericHookTests.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.intuit.hooks.example.library

import com.intuit.hooks.BailResult.*
import com.intuit.hooks.BailResult.Bail
import com.intuit.hooks.BailResult.Continue
import com.intuit.hooks.HookContext
import com.intuit.hooks.LoopResult
import com.intuit.hooks.example.library.generic.GenericHooksImpl
Expand Down Expand Up @@ -140,6 +141,7 @@ class GenericHookTests {
val result = h.call("Kian")
Assertions.assertEquals("bail now", result)
}

@Test
fun `async series loop`() = runBlocking {
var incrementedA = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@ public class HooksGradlePlugin : Plugin<Project> {

private fun Project.addDependency(configuration: String, dependencyNotation: String) = configurations
.getByName(configuration).dependencies.add(
dependencies.create(dependencyNotation)
dependencies.create(dependencyNotation),
)

override fun apply(project: Project): Unit = with(project) {
extensions.create(
"hooks",
HooksGradleExtension::class.java
HooksGradleExtension::class.java,
)

if (!pluginManager.hasPlugin("com.google.devtools.ksp"))
if (!pluginManager.hasPlugin("com.google.devtools.ksp")) {
pluginManager.apply("com.google.devtools.ksp")
}

addDependency("api", "com.intuit.hooks:hooks:$hooksVersion")
addDependency("ksp", "com.intuit.hooks:processor:$hooksVersion")
Expand Down
6 changes: 3 additions & 3 deletions gradle-plugin/src/test/kotlin/HooksGradlePluginTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ class HooksGradlePluginTest {
kotlin("jvm")
id("com.intuit.hooks")
}
"""
""",
)
}

@Test fun `can apply plugin`() {
buildFile.appendKotlin(
"""
hooks {}
"""
""",
)

assertDoesNotThrow {
Expand All @@ -66,7 +66,7 @@ class HooksGradlePluginTest {
@Sync<(String) -> Unit>
abstract val testSyncHook: Hook
}
"""
""",
)

val runner = GradleRunner.create()
Expand Down
2 changes: 1 addition & 1 deletion hooks/src/main/kotlin/com/intuit/hooks/BaseHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public data class TapInfo<FWithContext : Function<*>> internal constructor(
public val name: String,
public val id: String,
public val type: String,
public val f: FWithContext,
public val f: FWithContext
// val stage: Int, // todo: maybe this should be forEachIndexed?
// before?: string | Array // todo: do we even really need this?
)
Expand Down
3 changes: 2 additions & 1 deletion hooks/src/main/kotlin/com/intuit/hooks/dsl/Hooks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public abstract class Hooks {
ReplaceWith("@Hooks.AsyncParallelBail<F>"),
DeprecationLevel.ERROR,
)
@ExperimentalCoroutinesApi protected fun <F : Function<BailResult<*>>> asyncParallelBailHook(): AsyncParallelBailHook<*, *> = stub()
@ExperimentalCoroutinesApi
protected fun <F : Function<BailResult<*>>> asyncParallelBailHook(): AsyncParallelBailHook<*, *> = stub()

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.intuit.hooks

import io.mockk.*
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.mockk
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Assertions
Expand All @@ -10,7 +12,7 @@ class AsyncSeriesLoopHookTests {
class LoopHook1<T1> : AsyncSeriesLoopHook<suspend (HookContext, T1) -> LoopResult, suspend (HookContext, T1) -> Unit>() {
suspend fun call(p1: T1) = super.call(
invokeTap = { f, context -> f(context, p1) },
invokeInterceptor = { f, context -> f(context, p1) }
invokeInterceptor = { f, context -> f(context, p1) },
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class AsyncSeriesWaterfallHookTests {
suspend fun call(p1: R) = super.call(
p1,
invokeTap = { f, r, context -> f(context, r) },
invokeInterceptor = { f, context -> f(context, p1) }
invokeInterceptor = { f, context -> f(context, p1) },
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SyncLoopHookTests {
class LoopHook1<T1> : SyncLoopHook<(HookContext, T1) -> LoopResult, (HookContext, T1) -> Unit>() {
fun call(p1: T1) = super.call(
invokeTap = { f, context -> f(context, p1) },
invokeInterceptor = { f, context -> f(context, p1) }
invokeInterceptor = { f, context -> f(context, p1) },
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ class SyncWaterfallHookTests {
fun call(p1: T1) = super.call(
p1,
invokeTap = { f, acc, context -> f(context, acc) },
invokeInterceptor = { f, context -> f(context, p1) }
invokeInterceptor = { f, context -> f(context, p1) },
)
}

class Hook2<T1, T2> : SyncWaterfallHook<(HookContext, T1, T2) -> T1, T1>() {
fun call(p1: T1, p2: T2) = super.call(
p1,
invokeTap = { f, acc, context -> f(context, acc, p2) },
invokeInterceptor = { f, context -> f(context, p1, p2) }
invokeInterceptor = { f, context -> f(context, p1, p2) },
)
}

Expand Down
2 changes: 1 addition & 1 deletion maven-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tasks {
from(
configurations.compileClasspath.get().filter { dependency ->
dependency.absolutePath.contains("kotlin-maven-symbol-processing")
}.map(::zipTree)
}.map(::zipTree),
) {
this.duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
Expand Down
8 changes: 4 additions & 4 deletions processor/src/main/kotlin/com/intuit/hooks/plugin/Raise.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public inline fun <Error, A> Iterable<A>.accumulate(
flatMap {
recover({
operation(it); emptyList()
}) { it }
},) { it }
}.toNonEmptyListOrNull()?.let { raise(it) }
}

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

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

/** [mapOrAccumulate] variant that accumulates errors from a validator that may raise multiple errors */
context(Raise<NonEmptyList<Error>>)
Expand All @@ -80,4 +80,4 @@ public inline fun <Error, A, B> NonEmptySet<A>.mapOrAccumulate( // TODO: Conside
@BuilderInference operation: Raise<Nel<Error>>.(A) -> B
): NonEmptySet<B> = recover({
mapOrAccumulate(this@mapOrAccumulate) { operation(it) }
}) { errors -> raise(errors.flatMap { it }) }
},) { errors -> raise(errors.flatMap { it }) }
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ internal data class HooksContainer(
val superclass get() = originalClassName.let {
if (typeArguments.isNotEmpty()) {
it.parameterizedBy(typeArguments)
} else
} else {
it
}
}
}

Expand All @@ -24,7 +25,7 @@ internal data class HookSignature(
val isSuspend: Boolean,
val returnType: TypeName,
val returnTypeType: TypeName?,
val hookFunctionSignatureType: TypeName,
val hookFunctionSignatureType: TypeName
) {
val nullableReturnTypeType: TypeName get() {
requireNotNull(returnTypeType)
Expand All @@ -36,7 +37,7 @@ internal data class HookSignature(
internal class HookParameter(
val name: String?,
val type: TypeName,
val position: Int,
val position: Int
) {
val withType get() = "$withoutType: $type"
val withoutType get() = name ?: "p$position"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ internal fun HookInfo.generateClass(): TypeSpec {
val callBuilder = FunSpec.builder("call")
.addParameters(parameterSpecs)
.apply {
if ([email protected])
if ([email protected]) {
addModifiers(KModifier.SUSPEND)
}
}

val (superclass, call) = when (hookType) {
Expand All @@ -66,7 +67,7 @@ internal fun HookInfo.generateClass(): TypeSpec {
.addCode(
"return super.call(invokeTap = %L, invokeInterceptor = %L)",
CodeBlock.of("{ f, context -> f(context, $paramsWithoutTypes) }"),
CodeBlock.of("{ f, context -> f(context, $paramsWithoutTypes) }")
CodeBlock.of("{ f, context -> f(context, $paramsWithoutTypes) }"),
)

Pair(superclass, call)
Expand All @@ -81,7 +82,7 @@ internal fun HookInfo.generateClass(): TypeSpec {
"return super.call(%N, invokeTap = %L, invokeInterceptor = %L)",
accumulatorName,
CodeBlock.of("{ f, %N, context -> f(context, $paramsWithoutTypes) }", accumulatorName),
CodeBlock.of("{ f, context -> f(context, $paramsWithoutTypes) }")
CodeBlock.of("{ f, context -> f(context, $paramsWithoutTypes) }"),
)

Pair(superclass, call)
Expand Down Expand Up @@ -127,7 +128,7 @@ private val HookInfo.lambdaTypeName get() = createHookContextLambda(hookSignatur
private fun HookInfo.createHookContextLambda(returnType: TypeName): LambdaTypeName {
val get = LambdaTypeName.get(
parameters = listOf(ParameterSpec.unnamed(hookContext)) + parameterSpecs,
returnType = returnType
returnType = returnType,
)

return if (this.isAsync) get.copy(suspending = true) else get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class HooksProcessor(
}, { throwable: Throwable ->
logger.error("Uncaught exception while processing file: ${throwable.localizedMessage}", file)
logger.exception(throwable)
})
},)
}
}

Expand Down Expand Up @@ -107,7 +107,7 @@ public class HooksProcessor(
typeSpecKind,
visibilityModifier,
typeArguments,
hooks
hooks,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ internal val KSTypeArgument.text: String get() = when (variance) {
else -> "${variance.label} ${type!!.text}"
}

internal val List<KSTypeArgument>.text: String get() = if (isEmpty()) "" else
internal val List<KSTypeArgument>.text: String get() = if (isEmpty()) {
""
} else {
"<${joinToString(transform = KSTypeArgument::text)}>"
}

internal val KSTypeReference.text: String get() = element?.let {
when (it) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ internal fun KSPropertyDeclaration.validateHookAnnotation(parentResolver: TypePa
{ annotation.mustBeHookType(parentResolver) },
{ annotation.validateParameters(parentResolver) },
{ getVisibility().toKModifier() ?: KModifier.PUBLIC },
::HookInfo
::HookInfo,
)
}

Expand Down Expand Up @@ -106,7 +106,7 @@ private fun HookAnnotation.mustBeHookType(parentResolver: TypeParameterResolver)
isSuspend,
returnType,
returnTypeType,
hookFunctionSignatureType
hookFunctionSignatureType,
)
} catch (exception: Exception) {
raise(HookValidationError.MustBeHookTypeSignature(this))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.intuit.hooks.plugin.ensure
context(Raise<Nel<HookValidationError>>)
internal fun HookProperty.validate(
info: HookInfo,
property: KSPropertyDeclaration,
property: KSPropertyDeclaration
) {
when (this) {
is HookProperty.Bail -> Unit
Expand All @@ -30,7 +30,7 @@ private fun HookInfo.validateAsync(property: KSPropertyDeclaration) {
context(Raise<Nel<HookValidationError>>)
private fun HookProperty.Waterfall.validate(
info: HookInfo,
property: KSPropertyDeclaration,
property: KSPropertyDeclaration
) {
zipOrAccumulate(
{ arity(info, property) },
Expand All @@ -41,15 +41,15 @@ private fun HookProperty.Waterfall.validate(
context(Raise<HookValidationError.WaterfallMustHaveParameters>)
private fun HookProperty.Waterfall.arity(
info: HookInfo,
property: KSPropertyDeclaration,
property: KSPropertyDeclaration
) {
ensure(!info.zeroArity) { HookValidationError.WaterfallMustHaveParameters(property) }
}

context(Raise<HookValidationError.WaterfallParameterTypeMustMatch>)
private fun HookProperty.Waterfall.parameters(
info: HookInfo,
property: KSPropertyDeclaration,
property: KSPropertyDeclaration
) {
ensure(info.hookSignature.returnType == info.params.firstOrNull()?.type) {
HookValidationError.WaterfallParameterTypeMustMatch(property)
Expand Down
Loading