Skip to content

Commit

Permalink
Fixed lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unthrottled committed Jul 29, 2022
1 parent 835cee2 commit 456d656
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 44 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion detekt-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 21 additions & 2 deletions src/main/kotlin/io/unthrottled/amii/assets/AssetModels.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,16 @@ data class VisualAssetEntity(
audibleAssetId,
)

fun duplicate(categories: Set<MemeAssetCategory>, audibleAssetId: String?, representation: VisualAssetRepresentation) =
copy(assetCategories = categories, audibleAssetId = audibleAssetId, representation = representation)
fun duplicate(
categories: Set<MemeAssetCategory>,
audibleAssetId: String?,
representation: VisualAssetRepresentation
) =
copy(
assetCategories = categories,
audibleAssetId = audibleAssetId,
representation = representation
)
}

data class VisualAssetRepresentation(
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object BackgroundAssetService {
fun downloadNewAssets(
memeAssetCategory: MemeAssetCategory,
) {
if(Config.instance.onlyCustomAssets) {
if (Config.instance.onlyCustomAssets) {
return
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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<Boolean, List<VisualAssetRepresentation>> = getAutoTagDirectories(workingDirectory)
Expand All @@ -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(
Expand All @@ -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)
}

Expand Down Expand Up @@ -190,6 +182,23 @@ object LocalVisualContentManager : Logging, Disposable, ConfigListener {
}
}

private fun associateAllAssets(
workingDirectory: String
): MutableMap<String, VisualAssetRepresentation> =
readDirectory(
AssetFetchOptions(
workingDirectory,
includeLewds = true,
)
)
.stream()
.collect(
Collectors.toMap(
VisualAssetRepresentation::id,
Function.identity()
) { a, _ -> a }
)

private fun readLocalDirectoryWithAutoTag(assetFetchOptions: AssetFetchOptions): Set<VisualAssetRepresentation> {
val workingDirectory = assetFetchOptions.workingDirectory
if (workingDirectory.isEmpty() ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MemeAsset(
val audibleMemeContent: AudibleContent? = null,
)

object MemeAssetService: Logging {
object MemeAssetService : Logging {

private val ranbo = Random(System.currentTimeMillis())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,18 @@ internal fun msg(@PropertyKey(resourceBundle = DEFAULT_MESSAGE_BUNDLE) key: Stri

object MemeCategoriesPanel {

@Suppress("MagicNumber")
@JvmStatic
fun createComponent(): Pair<JPanel, MemeCategoriesComponent> {
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"))
}

Expand Down
25 changes: 22 additions & 3 deletions src/main/kotlin/io/unthrottled/amii/config/ui/MemeCategoriesSet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class MemeCategoriesSet :

override fun initPanel() {}

@Suppress("MagicNumber")
override fun getListCellRenderer(): ListCellRenderer<*> =
ConfigurableListCellRenderer<MemeAssetCategory> { component, category ->
component.configure {
Expand All @@ -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)
Expand Down Expand Up @@ -175,15 +183,26 @@ class MemeCategoriesSet :
}
}

internal class ConfigurableListCellRenderer<T>(val configure: (DefaultListCellRenderer, T) -> Unit) : DefaultListCellRenderer() {
internal class ConfigurableListCellRenderer<T>(
val configure: (
DefaultListCellRenderer,
T
) -> Unit
) : DefaultListCellRenderer() {
override fun getListCellRendererComponent(
list: JList<*>?,
value: Any?,
index: Int,
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
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/io/unthrottled/amii/memes/MemeInfoService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class MemeInfoService(private val project: Project) {
val content = """<div>
| <span>Anime: ${animeShown.joinToString(", ")}</span><br/>
| <span>Character$characterPluralization: ${characters.joinToString(", ")}</span>
|</div>""".trimMargin()
|</div>
""".trimMargin()

notificationGroup.createNotification(
content,
Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/io/unthrottled/amii/tools/SwingTools.kt
Original file line number Diff line number Diff line change
@@ -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")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class NegativeEmotionCoreTests {
"""At index #$index
|$event
|did not create $expectedMood but did $deriveMood
""".trimMargin()
""".trimMargin()
).isEqualTo(expectedMood)
}
}
Expand Down Expand Up @@ -99,7 +99,7 @@ class NegativeEmotionCoreTests {
"""At index #$index
|${arguments.first}
|did not create ${arguments.second} but did $deriveMood
""".trimMargin()
""".trimMargin()
).isIn(arguments.second)
}
}
Expand Down Expand Up @@ -152,7 +152,7 @@ class NegativeEmotionCoreTests {
"""At index #$index
|${arguments.first}
|did not create ${arguments.second} but did $deriveMood
""".trimMargin()
""".trimMargin()
).isIn(arguments.second)
}
}
Expand Down Expand Up @@ -184,7 +184,7 @@ class NegativeEmotionCoreTests {
"""At index #$index
|$motivationEvent
|did not create $OTHER_NEGATIVE_EMOTIONS but did $deriveMood
""".trimMargin()
""".trimMargin()
).isIn(
*negativeEmotions
)
Expand Down Expand Up @@ -217,7 +217,7 @@ class NegativeEmotionCoreTests {
"""At index #$index
|$motivationEvent
|did not create $OTHER_NEGATIVE_EMOTIONS but did $deriveMood
""".trimMargin()
""".trimMargin()
).isIn(
*negativeEmotions
)
Expand Down Expand Up @@ -273,7 +273,7 @@ class NegativeEmotionCoreTests {
"""At index #$index
|${arguments.first}
|did not create ${arguments.second} but did $deriveMood
""".trimMargin()
""".trimMargin()
).isIn(arguments.second)
}
}
Expand Down Expand Up @@ -338,7 +338,7 @@ class NegativeEmotionCoreTests {
"""At index #$index
|${arguments.first}
|did not create ${arguments.second} but did $deriveMood
""".trimMargin()
""".trimMargin()
).isIn(arguments.second)
}
}
Expand Down Expand Up @@ -425,7 +425,7 @@ class NegativeEmotionCoreTests {
"""At index #$index
|${arguments.first}
|did not create ${arguments.second} but did $deriveMood
""".trimMargin()
""".trimMargin()
).isIn(arguments.second)
}
}
Expand Down Expand Up @@ -496,7 +496,7 @@ class NegativeEmotionCoreTests {
"""At index #$index
|${arguments.first}
|did not create ${arguments.second} but did $deriveMood
""".trimMargin()
""".trimMargin()
).isIn(arguments.second)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class PositiveEmotionCoreTests {
"""At index #$index
|${arguments.first}
|did not create ${arguments.second} but did $deriveMood
""".trimMargin()
""".trimMargin()
).isIn(arguments.second)
}
}
Expand Down

0 comments on commit 456d656

Please sign in to comment.