From 456d656a40973c9570abd2f3c45bdcc74dbb00fc Mon Sep 17 00:00:00 2001 From: Alex Simons Date: Fri, 29 Jul 2022 18:37:14 -0500 Subject: [PATCH] Fixed lint. --- build.gradle.kts | 4 +- detekt-config.yml | 8 +++- .../io/unthrottled/amii/assets/AssetModels.kt | 23 +++++++++- .../amii/assets/BackgroundAssetService.kt | 2 +- .../amii/assets/LocalContentManager.kt | 3 -- .../amii/assets/LocalVisualContentManager.kt | 43 +++++++++++-------- .../amii/assets/MemeAssetService.kt | 2 +- .../amii/config/ui/MemeCategoriesPanel.kt | 8 +++- .../amii/config/ui/MemeCategoriesSet.kt | 25 +++++++++-- .../unthrottled/amii/memes/MemeInfoService.kt | 3 +- .../io/unthrottled/amii/tools/SwingTools.kt | 3 +- .../emotions/NegativeEmotionCoreTests.kt | 18 ++++---- .../emotions/PositiveEmotionCoreTests.kt | 2 +- 13 files changed, 100 insertions(+), 44 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 3693a137..e824cf76 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -13,9 +13,9 @@ plugins { // gradle-changelog-plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin id("org.jetbrains.changelog") version "1.1.2" // detekt linter - read more: https://detekt.github.io/detekt/gradle.html - id("io.gitlab.arturbosch.detekt") version "1.16.0" + id("io.gitlab.arturbosch.detekt") version "1.21.0" // ktlint linter - read more: https://github.com/JLLeitschuh/ktlint-gradle - id("org.jlleitschuh.gradle.ktlint") version "10.0.0" + id("org.jlleitschuh.gradle.ktlint") version "10.3.0" } // Import variables from gradle.properties file diff --git a/detekt-config.yml b/detekt-config.yml index 9f899827..2c26f8cf 100644 --- a/detekt-config.yml +++ b/detekt-config.yml @@ -7,9 +7,15 @@ exceptions: SwallowedException: active: false +complexity: + LongMethod: + active: true + threshold: 69 + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + formatting: Indentation: - active: true + active: false autoCorrect: true indentSize: 2 continuationIndentSize: 2 diff --git a/src/main/kotlin/io/unthrottled/amii/assets/AssetModels.kt b/src/main/kotlin/io/unthrottled/amii/assets/AssetModels.kt index 4d975b27..0e2cd96a 100644 --- a/src/main/kotlin/io/unthrottled/amii/assets/AssetModels.kt +++ b/src/main/kotlin/io/unthrottled/amii/assets/AssetModels.kt @@ -79,8 +79,16 @@ data class VisualAssetEntity( audibleAssetId, ) - fun duplicate(categories: Set, audibleAssetId: String?, representation: VisualAssetRepresentation) = - copy(assetCategories = categories, audibleAssetId = audibleAssetId, representation = representation) + fun duplicate( + categories: Set, + audibleAssetId: String?, + representation: VisualAssetRepresentation + ) = + copy( + assetCategories = categories, + audibleAssetId = audibleAssetId, + representation = representation + ) } data class VisualAssetRepresentation( @@ -126,6 +134,17 @@ data class VisualAssetRepresentation( override fun hashCode(): Int { return id.hashCode() } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as VisualAssetRepresentation + + if (id != other.id) return false + + return true + } } data class AudibleRepresentation( diff --git a/src/main/kotlin/io/unthrottled/amii/assets/BackgroundAssetService.kt b/src/main/kotlin/io/unthrottled/amii/assets/BackgroundAssetService.kt index 62313a75..ab0369f7 100644 --- a/src/main/kotlin/io/unthrottled/amii/assets/BackgroundAssetService.kt +++ b/src/main/kotlin/io/unthrottled/amii/assets/BackgroundAssetService.kt @@ -16,7 +16,7 @@ object BackgroundAssetService { fun downloadNewAssets( memeAssetCategory: MemeAssetCategory, ) { - if(Config.instance.onlyCustomAssets) { + if (Config.instance.onlyCustomAssets) { return } diff --git a/src/main/kotlin/io/unthrottled/amii/assets/LocalContentManager.kt b/src/main/kotlin/io/unthrottled/amii/assets/LocalContentManager.kt index 6339d816..47198a12 100644 --- a/src/main/kotlin/io/unthrottled/amii/assets/LocalContentManager.kt +++ b/src/main/kotlin/io/unthrottled/amii/assets/LocalContentManager.kt @@ -1,9 +1,6 @@ package io.unthrottled.amii.assets import com.intellij.openapi.application.ApplicationManager -import com.intellij.openapi.project.Project -import io.unthrottled.amii.onboarding.UpdateNotification -import io.unthrottled.amii.tools.PluginMessageBundle object LocalContentManager { diff --git a/src/main/kotlin/io/unthrottled/amii/assets/LocalVisualContentManager.kt b/src/main/kotlin/io/unthrottled/amii/assets/LocalVisualContentManager.kt index e94372a6..b68141fa 100644 --- a/src/main/kotlin/io/unthrottled/amii/assets/LocalVisualContentManager.kt +++ b/src/main/kotlin/io/unthrottled/amii/assets/LocalVisualContentManager.kt @@ -20,6 +20,7 @@ import java.util.function.Function import java.util.stream.Collectors import java.util.stream.Stream +@Suppress("TooManyFunctions", "LongMethod") // cuz I said so object LocalVisualContentManager : Logging, Disposable, ConfigListener { private val messageBusConnection = ApplicationManager.getApplication().messageBus.connect() @@ -111,7 +112,7 @@ object LocalVisualContentManager : Logging, Disposable, ConfigListener { } } - fun autoTagAssets(workingDirectory: String) { + private fun autoTagAssets(workingDirectory: String) { if (Config.instance.createAutoTagDirectories.not()) { logger().info("Not tagging items because auto tagging is not enabled.") return @@ -121,18 +122,7 @@ object LocalVisualContentManager : Logging, Disposable, ConfigListener { createAutoTagDirectories(workingDirectory) - val allLocalAssets = readDirectory( - AssetFetchOptions( - workingDirectory, - includeLewds = true, - ) - ) - .stream() - .collect( - Collectors.toMap( - VisualAssetRepresentation::id, - Function.identity() - ) { a, _ -> a }) + val allLocalAssets = associateAllAssets(workingDirectory) val partitionedAutoTagAssets: Map> = getAutoTagDirectories(workingDirectory) @@ -143,9 +133,11 @@ object LocalVisualContentManager : Logging, Disposable, ConfigListener { ) .map { assetPath: Path? -> // todo: probably shouldn't calculate md5 hash. - allLocalAssets[calculateMD5Hash( - assetPath!! - )] + allLocalAssets[ + calculateMD5Hash( + assetPath!! + ) + ] } .filter { obj: VisualAssetRepresentation? -> Objects.nonNull( @@ -162,7 +154,7 @@ object LocalVisualContentManager : Logging, Disposable, ConfigListener { modified = true } - if(autoTagDir.isLewd && usableRep.lewd?.not() == true) { + if (autoTagDir.isLewd && usableRep.lewd?.not() == true) { usableRep = usableRep.copy(lewd = true) } @@ -190,6 +182,23 @@ object LocalVisualContentManager : Logging, Disposable, ConfigListener { } } + private fun associateAllAssets( + workingDirectory: String + ): MutableMap = + readDirectory( + AssetFetchOptions( + workingDirectory, + includeLewds = true, + ) + ) + .stream() + .collect( + Collectors.toMap( + VisualAssetRepresentation::id, + Function.identity() + ) { a, _ -> a } + ) + private fun readLocalDirectoryWithAutoTag(assetFetchOptions: AssetFetchOptions): Set { val workingDirectory = assetFetchOptions.workingDirectory if (workingDirectory.isEmpty() || diff --git a/src/main/kotlin/io/unthrottled/amii/assets/MemeAssetService.kt b/src/main/kotlin/io/unthrottled/amii/assets/MemeAssetService.kt index 811c7224..4483754e 100644 --- a/src/main/kotlin/io/unthrottled/amii/assets/MemeAssetService.kt +++ b/src/main/kotlin/io/unthrottled/amii/assets/MemeAssetService.kt @@ -12,7 +12,7 @@ class MemeAsset( val audibleMemeContent: AudibleContent? = null, ) -object MemeAssetService: Logging { +object MemeAssetService : Logging { private val ranbo = Random(System.currentTimeMillis()) diff --git a/src/main/kotlin/io/unthrottled/amii/config/ui/MemeCategoriesPanel.kt b/src/main/kotlin/io/unthrottled/amii/config/ui/MemeCategoriesPanel.kt index afe19cd0..1e4ff9ff 100644 --- a/src/main/kotlin/io/unthrottled/amii/config/ui/MemeCategoriesPanel.kt +++ b/src/main/kotlin/io/unthrottled/amii/config/ui/MemeCategoriesPanel.kt @@ -40,12 +40,18 @@ internal fun msg(@PropertyKey(resourceBundle = DEFAULT_MESSAGE_BUNDLE) key: Stri object MemeCategoriesPanel { + @Suppress("MagicNumber") @JvmStatic fun createComponent(): Pair { val memeCategories = MemeCategoriesComponent() return panel(MigLayout(createLayoutConstraints())) { panel(MigLayout(createLayoutConstraints()), constraint = CC().growX().wrap()) { - border = border(msg("amii.settings.meme.categories.title"), false, JBUI.insetsBottom(10), false) + border = border( + msg("amii.settings.meme.categories.title"), + false, + JBUI.insetsBottom(10), + false + ) add(memeCategories.component, CC().width("350px").height("150px")) } diff --git a/src/main/kotlin/io/unthrottled/amii/config/ui/MemeCategoriesSet.kt b/src/main/kotlin/io/unthrottled/amii/config/ui/MemeCategoriesSet.kt index 2689a782..8c321af1 100644 --- a/src/main/kotlin/io/unthrottled/amii/config/ui/MemeCategoriesSet.kt +++ b/src/main/kotlin/io/unthrottled/amii/config/ui/MemeCategoriesSet.kt @@ -67,6 +67,7 @@ class MemeCategoriesSet : override fun initPanel() {} + @Suppress("MagicNumber") override fun getListCellRenderer(): ListCellRenderer<*> = ConfigurableListCellRenderer { component, category -> component.configure { @@ -78,7 +79,14 @@ class MemeCategoriesSet : override fun addElement(itemToAdd: MemeAssetCategory?) { itemToAdd ?: return removeExistedCategories(itemToAdd) - val positionToInsert = -(myListModel.elements().toList().binarySearch(itemToAdd, Comparator.comparing(MemeAssetCategory::name)) + 1) + val positionToInsert = -( + myListModel.elements() + .toList() + .binarySearch( + itemToAdd, + Comparator.comparing(MemeAssetCategory::name) + ) + 1 + ) myListModel.add(positionToInsert, itemToAdd) myList.clearSelection() myList.setSelectedValue(itemToAdd, true) @@ -175,7 +183,12 @@ class MemeCategoriesSet : } } -internal class ConfigurableListCellRenderer(val configure: (DefaultListCellRenderer, T) -> Unit) : DefaultListCellRenderer() { +internal class ConfigurableListCellRenderer( + val configure: ( + DefaultListCellRenderer, + T + ) -> Unit +) : DefaultListCellRenderer() { override fun getListCellRendererComponent( list: JList<*>?, value: Any?, @@ -183,7 +196,13 @@ internal class ConfigurableListCellRenderer(val configure: (DefaultListCellRe isSelected: Boolean, cellHasFocus: Boolean ): Component { - val component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus) as DefaultListCellRenderer + val component = super.getListCellRendererComponent( + list, + value, + index, + isSelected, + cellHasFocus + ) as DefaultListCellRenderer configure(component, value as T) return component } diff --git a/src/main/kotlin/io/unthrottled/amii/memes/MemeInfoService.kt b/src/main/kotlin/io/unthrottled/amii/memes/MemeInfoService.kt index 27cd7dde..6c95b123 100644 --- a/src/main/kotlin/io/unthrottled/amii/memes/MemeInfoService.kt +++ b/src/main/kotlin/io/unthrottled/amii/memes/MemeInfoService.kt @@ -57,7 +57,8 @@ class MemeInfoService(private val project: Project) { val content = """
| Anime: ${animeShown.joinToString(", ")}
| Character$characterPluralization: ${characters.joinToString(", ")} - |
""".trimMargin() + | + """.trimMargin() notificationGroup.createNotification( content, diff --git a/src/main/kotlin/io/unthrottled/amii/tools/SwingTools.kt b/src/main/kotlin/io/unthrottled/amii/tools/SwingTools.kt index d0284021..52e1dec0 100644 --- a/src/main/kotlin/io/unthrottled/amii/tools/SwingTools.kt +++ b/src/main/kotlin/io/unthrottled/amii/tools/SwingTools.kt @@ -1,10 +1,9 @@ package io.unthrottled.amii.tools import java.awt.EventQueue -import java.lang.IllegalStateException fun assertNotAWTThread() { if (EventQueue.isDispatchThread()) { - throw IllegalStateException("You are on the AWT thread, check yourself before you wreck yourself") + error("You are on the AWT thread, check yourself before you wreck yourself") } } diff --git a/src/test/kotlin/io/unthrottled/amii/core/personality/emotions/NegativeEmotionCoreTests.kt b/src/test/kotlin/io/unthrottled/amii/core/personality/emotions/NegativeEmotionCoreTests.kt index 40c93959..68cb24b1 100644 --- a/src/test/kotlin/io/unthrottled/amii/core/personality/emotions/NegativeEmotionCoreTests.kt +++ b/src/test/kotlin/io/unthrottled/amii/core/personality/emotions/NegativeEmotionCoreTests.kt @@ -47,7 +47,7 @@ class NegativeEmotionCoreTests { """At index #$index |$event |did not create $expectedMood but did $deriveMood - """.trimMargin() + """.trimMargin() ).isEqualTo(expectedMood) } } @@ -99,7 +99,7 @@ class NegativeEmotionCoreTests { """At index #$index |${arguments.first} |did not create ${arguments.second} but did $deriveMood - """.trimMargin() + """.trimMargin() ).isIn(arguments.second) } } @@ -152,7 +152,7 @@ class NegativeEmotionCoreTests { """At index #$index |${arguments.first} |did not create ${arguments.second} but did $deriveMood - """.trimMargin() + """.trimMargin() ).isIn(arguments.second) } } @@ -184,7 +184,7 @@ class NegativeEmotionCoreTests { """At index #$index |$motivationEvent |did not create $OTHER_NEGATIVE_EMOTIONS but did $deriveMood - """.trimMargin() + """.trimMargin() ).isIn( *negativeEmotions ) @@ -217,7 +217,7 @@ class NegativeEmotionCoreTests { """At index #$index |$motivationEvent |did not create $OTHER_NEGATIVE_EMOTIONS but did $deriveMood - """.trimMargin() + """.trimMargin() ).isIn( *negativeEmotions ) @@ -273,7 +273,7 @@ class NegativeEmotionCoreTests { """At index #$index |${arguments.first} |did not create ${arguments.second} but did $deriveMood - """.trimMargin() + """.trimMargin() ).isIn(arguments.second) } } @@ -338,7 +338,7 @@ class NegativeEmotionCoreTests { """At index #$index |${arguments.first} |did not create ${arguments.second} but did $deriveMood - """.trimMargin() + """.trimMargin() ).isIn(arguments.second) } } @@ -425,7 +425,7 @@ class NegativeEmotionCoreTests { """At index #$index |${arguments.first} |did not create ${arguments.second} but did $deriveMood - """.trimMargin() + """.trimMargin() ).isIn(arguments.second) } } @@ -496,7 +496,7 @@ class NegativeEmotionCoreTests { """At index #$index |${arguments.first} |did not create ${arguments.second} but did $deriveMood - """.trimMargin() + """.trimMargin() ).isIn(arguments.second) } } diff --git a/src/test/kotlin/io/unthrottled/amii/core/personality/emotions/PositiveEmotionCoreTests.kt b/src/test/kotlin/io/unthrottled/amii/core/personality/emotions/PositiveEmotionCoreTests.kt index a37d1ab7..09ccbc02 100644 --- a/src/test/kotlin/io/unthrottled/amii/core/personality/emotions/PositiveEmotionCoreTests.kt +++ b/src/test/kotlin/io/unthrottled/amii/core/personality/emotions/PositiveEmotionCoreTests.kt @@ -47,7 +47,7 @@ class PositiveEmotionCoreTests { """At index #$index |${arguments.first} |did not create ${arguments.second} but did $deriveMood - """.trimMargin() + """.trimMargin() ).isIn(arguments.second) } }