From 5648128217deccbffe9dd75d3f7f995c3d0d56db Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Tue, 14 Sep 2021 11:45:23 -0700 Subject: [PATCH] kotlin: Switch from ktfmt to ktlint (fixes build) --- cloud-kotlin-extensions/build.gradle.kts | 7 +--- .../kotlin/MutableCommandBuilder.kt | 42 ++++++++++++------- .../coroutines/KotlinAnnotatedMethods.kt | 11 +++-- .../extension/CommandBuildingExtensions.kt | 9 ++-- .../kotlin/CommandBuildingDSLTest.kt | 36 +++++++++------- .../coroutines/KotlinAnnotatedMethodsTest.kt | 13 +++--- 6 files changed, 69 insertions(+), 49 deletions(-) diff --git a/cloud-kotlin-extensions/build.gradle.kts b/cloud-kotlin-extensions/build.gradle.kts index 560b01e8..cdcb4d70 100644 --- a/cloud-kotlin-extensions/build.gradle.kts +++ b/cloud-kotlin-extensions/build.gradle.kts @@ -1,10 +1,9 @@ import org.jetbrains.dokka.gradle.DokkaTask -import java.net.URL plugins { kotlin("jvm") version "1.4.31" id("org.jetbrains.dokka") version "1.4.20" - id("com.ncorti.ktfmt.gradle") version "0.6.0" + id("org.jlleitschuh.gradle.ktlint") version "10.0.0" } configurations.all { @@ -50,7 +49,3 @@ tasks { kotlin { explicitApi() } - -ktfmt { - dropboxStyle() -} diff --git a/cloud-kotlin-extensions/src/main/kotlin/cloud/commandframework/kotlin/MutableCommandBuilder.kt b/cloud-kotlin-extensions/src/main/kotlin/cloud/commandframework/kotlin/MutableCommandBuilder.kt index bec987d7..1a1d8374 100644 --- a/cloud-kotlin-extensions/src/main/kotlin/cloud/commandframework/kotlin/MutableCommandBuilder.kt +++ b/cloud-kotlin-extensions/src/main/kotlin/cloud/commandframework/kotlin/MutableCommandBuilder.kt @@ -57,7 +57,8 @@ public class MutableCommandBuilder { @Suppress("DEPRECATION") @Deprecated( message = "ArgumentDescription should be used over Description", - level = DeprecationLevel.HIDDEN) + level = DeprecationLevel.HIDDEN + ) public constructor( name: String, description: Description = Description.empty(), @@ -100,7 +101,8 @@ public class MutableCommandBuilder { @Suppress("DEPRECATION") @Deprecated( message = "ArgumentDescription should be used over Description", - level = DeprecationLevel.HIDDEN) + level = DeprecationLevel.HIDDEN + ) public constructor( name: String, description: Description = Description.empty(), @@ -171,7 +173,7 @@ public class MutableCommandBuilder { return this } - private fun onlyMutate(mutator: (Command.Builder) -> Command.Builder): Unit { + private fun onlyMutate(mutator: (Command.Builder) -> Command.Builder) { mutate(mutator) } @@ -207,7 +209,8 @@ public class MutableCommandBuilder { @Suppress("DEPRECATION") @Deprecated( message = "ArgumentDescription should be used over Description", - level = DeprecationLevel.HIDDEN) + level = DeprecationLevel.HIDDEN + ) public fun copy( literal: String, description: Description, @@ -306,7 +309,8 @@ public class MutableCommandBuilder { @Suppress("DEPRECATION") @Deprecated( message = "ArgumentDescription should be used over Description", - level = DeprecationLevel.HIDDEN) + level = DeprecationLevel.HIDDEN + ) public fun registerCopy( literal: String, description: Description, @@ -341,8 +345,8 @@ public class MutableCommandBuilder { */ public fun meta(key: CommandMeta.Key, value: T): MutableCommandBuilder = mutate { - it.meta(key, value) - } + it.meta(key, value) + } /** * Set the value for a certain [CommandMeta.Key] in the command meta storage for this builder @@ -481,7 +485,8 @@ public class MutableCommandBuilder { @Suppress("DEPRECATION") @Deprecated( message = "ArgumentDescription should be used over Description", - level = DeprecationLevel.HIDDEN) + level = DeprecationLevel.HIDDEN + ) public fun argument( argument: CommandArgument, description: Description = Description.empty() @@ -511,7 +516,8 @@ public class MutableCommandBuilder { @Suppress("DEPRECATION") @Deprecated( message = "ArgumentDescription should be used over Description", - level = DeprecationLevel.HIDDEN) + level = DeprecationLevel.HIDDEN + ) public fun argument( argument: CommandArgument.Builder, description: Description = Description.empty() @@ -541,7 +547,8 @@ public class MutableCommandBuilder { @Suppress("DEPRECATION") @Deprecated( message = "ArgumentDescription should be used over Description", - level = DeprecationLevel.HIDDEN) + level = DeprecationLevel.HIDDEN + ) public fun argument( description: Description = Description.empty(), argumentSupplier: () -> CommandArgument @@ -572,7 +579,8 @@ public class MutableCommandBuilder { @Suppress("DEPRECATION") @Deprecated( message = "ArgumentDescription should be used over Description", - level = DeprecationLevel.HIDDEN) + level = DeprecationLevel.HIDDEN + ) public fun literal( name: String, description: Description = Description.empty(), @@ -627,7 +635,8 @@ public class MutableCommandBuilder { .withAliases(*aliases) .withDescription(description) .withArgument(argumentSupplier()) - .build()) + .build() + ) } /** @@ -652,7 +661,8 @@ public class MutableCommandBuilder { .withAliases(*aliases) .withDescription(description) .withArgument(argument) - .build()) + .build() + ) } /** @@ -677,7 +687,8 @@ public class MutableCommandBuilder { .withAliases(*aliases) .withDescription(description) .withArgument(argumentBuilder) - .build()) + .build() + ) } /** @@ -699,6 +710,7 @@ public class MutableCommandBuilder { .flagBuilder(name) .withAliases(*aliases) .withDescription(description) - .build()) + .build() + ) } } diff --git a/cloud-kotlin-extensions/src/main/kotlin/cloud/commandframework/kotlin/coroutines/KotlinAnnotatedMethods.kt b/cloud-kotlin-extensions/src/main/kotlin/cloud/commandframework/kotlin/coroutines/KotlinAnnotatedMethods.kt index d5782970..5fa1acfa 100644 --- a/cloud-kotlin-extensions/src/main/kotlin/cloud/commandframework/kotlin/coroutines/KotlinAnnotatedMethods.kt +++ b/cloud-kotlin-extensions/src/main/kotlin/cloud/commandframework/kotlin/coroutines/KotlinAnnotatedMethods.kt @@ -27,6 +27,10 @@ import cloud.commandframework.annotations.AnnotationParser import cloud.commandframework.annotations.MethodCommandExecutionHandler import cloud.commandframework.context.CommandContext import cloud.commandframework.execution.CommandExecutionCoordinator +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.async +import kotlinx.coroutines.future.asCompletableFuture import java.lang.reflect.Method import java.util.concurrent.CompletableFuture import java.util.function.Predicate @@ -34,8 +38,6 @@ import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext import kotlin.reflect.full.callSuspend import kotlin.reflect.jvm.kotlinFunction -import kotlinx.coroutines.* -import kotlinx.coroutines.future.asCompletableFuture /** * Adds coroutine support to the [AnnotationParser]. @@ -48,8 +50,9 @@ public fun AnnotationParser.installCoroutineSupport( ) { if (manager().commandExecutionCoordinator() is CommandExecutionCoordinator.SimpleCoordinator) { RuntimeException( - """You are highly advised to not use the simple command execution coordinator together - with coroutine support. Consider using the asynchronous command execution coordinator instead.""") + """You are highly advised to not use the simple command execution coordinator together + with coroutine support. Consider using the asynchronous command execution coordinator instead.""" + ) .printStackTrace() } diff --git a/cloud-kotlin-extensions/src/main/kotlin/cloud/commandframework/kotlin/extension/CommandBuildingExtensions.kt b/cloud-kotlin-extensions/src/main/kotlin/cloud/commandframework/kotlin/extension/CommandBuildingExtensions.kt index db77c35c..7d265050 100644 --- a/cloud-kotlin-extensions/src/main/kotlin/cloud/commandframework/kotlin/extension/CommandBuildingExtensions.kt +++ b/cloud-kotlin-extensions/src/main/kotlin/cloud/commandframework/kotlin/extension/CommandBuildingExtensions.kt @@ -42,7 +42,8 @@ import kotlin.reflect.KClass @Suppress("DEPRECATION") @Deprecated( message = "ArgumentDescription should be used over Description", - level = DeprecationLevel.HIDDEN) + level = DeprecationLevel.HIDDEN +) public fun CommandManager.commandBuilder( name: String, description: Description = Description.empty(), @@ -79,7 +80,8 @@ public fun CommandManager.commandBuilder( @Suppress("DEPRECATION") @Deprecated( message = "ArgumentDescription should be used over Description", - level = DeprecationLevel.HIDDEN) + level = DeprecationLevel.HIDDEN +) public fun CommandManager.buildAndRegister( name: String, description: Description = Description.empty(), @@ -137,7 +139,8 @@ public fun Command.Builder.senderType(type: KClass): Command @Suppress("DEPRECATION") @Deprecated( message = "Use interface variant that allows for rich text", - replaceWith = ReplaceWith("argumentDescription(description)")) + replaceWith = ReplaceWith("argumentDescription(description)") +) public fun description(description: String = ""): Description = if (description.isEmpty()) Description.empty() else Description.of(description) diff --git a/cloud-kotlin-extensions/src/test/kotlin/cloud/commandframework/kotlin/CommandBuildingDSLTest.kt b/cloud-kotlin-extensions/src/test/kotlin/cloud/commandframework/kotlin/CommandBuildingDSLTest.kt index d930cfcc..a09cdfd9 100644 --- a/cloud-kotlin-extensions/src/test/kotlin/cloud/commandframework/kotlin/CommandBuildingDSLTest.kt +++ b/cloud-kotlin-extensions/src/test/kotlin/cloud/commandframework/kotlin/CommandBuildingDSLTest.kt @@ -27,7 +27,10 @@ import cloud.commandframework.CommandManager import cloud.commandframework.arguments.standard.StringArgument import cloud.commandframework.execution.CommandExecutionCoordinator import cloud.commandframework.internal.CommandRegistrationHandler -import cloud.commandframework.kotlin.extension.* +import cloud.commandframework.kotlin.extension.argumentDescription +import cloud.commandframework.kotlin.extension.buildAndRegister +import cloud.commandframework.kotlin.extension.command +import cloud.commandframework.kotlin.extension.commandBuilder import cloud.commandframework.meta.CommandMeta import cloud.commandframework.meta.SimpleCommandMeta import org.junit.jupiter.api.Assertions @@ -58,8 +61,10 @@ class CommandBuildingDSLTest { handler { // ... } - }) - }) + } + ) + } + ) manager.buildAndRegister("is") { commandDescription("Command description") @@ -85,20 +90,21 @@ class CommandBuildingDSLTest { Assertions.assertEquals( manager.commandHelpHandler.allCommands.map { it.syntaxString }.sorted(), setOf( - "kotlin dsl ", - "kotlin dsl bruh_moment", - "is", - "is this", - "is this going", - "is this going too_far", - ) - .sorted()) + "kotlin dsl ", + "kotlin dsl bruh_moment", + "is", + "is this", + "is this going", + "is this going too_far", + ) + .sorted() + ) } - class TestCommandManager : - CommandManager( - CommandExecutionCoordinator.simpleCoordinator(), - CommandRegistrationHandler.nullCommandRegistrationHandler()) { + class TestCommandManager : CommandManager( + CommandExecutionCoordinator.simpleCoordinator(), + CommandRegistrationHandler.nullCommandRegistrationHandler() + ) { override fun createDefaultCommandMeta(): SimpleCommandMeta { return SimpleCommandMeta.empty() } diff --git a/cloud-kotlin-extensions/src/test/kotlin/cloud/commandframework/kotlin/coroutines/KotlinAnnotatedMethodsTest.kt b/cloud-kotlin-extensions/src/test/kotlin/cloud/commandframework/kotlin/coroutines/KotlinAnnotatedMethodsTest.kt index d6ae1726..bfbb4a77 100644 --- a/cloud-kotlin-extensions/src/test/kotlin/cloud/commandframework/kotlin/coroutines/KotlinAnnotatedMethodsTest.kt +++ b/cloud-kotlin-extensions/src/test/kotlin/cloud/commandframework/kotlin/coroutines/KotlinAnnotatedMethodsTest.kt @@ -30,14 +30,14 @@ import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator import cloud.commandframework.internal.CommandRegistrationHandler import cloud.commandframework.meta.CommandMeta import cloud.commandframework.meta.SimpleCommandMeta -import java.util.concurrent.Executors -import java.util.concurrent.TimeUnit import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.future.await import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test +import java.util.concurrent.Executors +import java.util.concurrent.TimeUnit class KotlinAnnotatedMethodsTest { @@ -60,22 +60,23 @@ class KotlinAnnotatedMethodsTest { @Test fun `test suspending command methods`(): Unit = runBlocking { AnnotationParser(commandManager, TestCommandSender::class.java) { - SimpleCommandMeta.empty() - } + SimpleCommandMeta.empty() + } .also { it.installCoroutineSupport() } .parse(CommandMethods()) commandManager.executeCommand(TestCommandSender(), "test").await() } - private class TestCommandSender {} + private class TestCommandSender private class TestCommandManager : CommandManager( AsynchronousCommandExecutionCoordinator.newBuilder() .withExecutor(executorService) .build(), - CommandRegistrationHandler.nullCommandRegistrationHandler()) { + CommandRegistrationHandler.nullCommandRegistrationHandler() + ) { override fun hasPermission(sender: TestCommandSender, permission: String): Boolean = true