From 9fb12d9f63a5b9264c1e7e400203af363c82be41 Mon Sep 17 00:00:00 2001 From: Maxr1998 Date: Sat, 13 Jan 2024 15:43:31 +0100 Subject: [PATCH] :rotating_light: Fix various detekt warnings and enable type resolution --- .github/workflows/bot-detekt.yaml | 2 +- detekt.yml | 4 ++++ .../integration/resolver/sources/WeiboImageSource.kt | 6 +++--- src/main/kotlin/de/maxr1998/diskord/util/exposed/Batch.kt | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/bot-detekt.yaml b/.github/workflows/bot-detekt.yaml index 5f4efb2..4122c3c 100644 --- a/.github/workflows/bot-detekt.yaml +++ b/.github/workflows/bot-detekt.yaml @@ -18,7 +18,7 @@ jobs: - name: Setup Gradle uses: gradle/gradle-build-action@842c587ad8aa4c68eeba24c396e15af4c2e9f30a # v2.9.0 - name: Run detekt task - run: ./gradlew detekt + run: ./gradlew detekt detektMain - name: Upload SARIF files uses: github/codeql-action/upload-sarif@74483a38d39275f33fcff5f35b679b5ca4a26a99 # v2.22.5 if: ${{ always() }} diff --git a/detekt.yml b/detekt.yml index 136599c..62f99cf 100644 --- a/detekt.yml +++ b/detekt.yml @@ -10,6 +10,10 @@ complexity: thresholdInEnums: 8 ignoreDeprecated: true +coroutines: + InjectDispatcher: + active: false + exceptions: SwallowedException: active: false diff --git a/src/main/kotlin/de/maxr1998/diskord/integration/resolver/sources/WeiboImageSource.kt b/src/main/kotlin/de/maxr1998/diskord/integration/resolver/sources/WeiboImageSource.kt index 0ee8ce7..09eacd6 100644 --- a/src/main/kotlin/de/maxr1998/diskord/integration/resolver/sources/WeiboImageSource.kt +++ b/src/main/kotlin/de/maxr1998/diskord/integration/resolver/sources/WeiboImageSource.kt @@ -50,13 +50,13 @@ class WeiboImageSource( val renderDataString = body.substring(startIndex, endIndex) val renderData: JsonObject = json.parseToJsonElement(renderDataString).jsonObject - val status = renderData["status"]!!.jsonObject - val picIds = status["pic_ids"]!!.jsonArray.map { element -> element.jsonPrimitive.content } + val status = requireNotNull(renderData["status"]).jsonObject + val picIds = requireNotNull(status["pic_ids"]).jsonArray.map { element -> element.jsonPrimitive.content } picIds.map { id -> val imageUrl = "https://wx4.sinaimg.cn/original/$id.jpg" CommandEntryEntity.image(imageUrl, normalizedUrl) } - } catch (e: NullPointerException) { + } catch (e: IllegalArgumentException) { logger.error("Couldn't parse response") return ImageResolver.Status.ParsingFailed() } catch (e: Exception) { diff --git a/src/main/kotlin/de/maxr1998/diskord/util/exposed/Batch.kt b/src/main/kotlin/de/maxr1998/diskord/util/exposed/Batch.kt index bfbef37..fc1adfb 100644 --- a/src/main/kotlin/de/maxr1998/diskord/util/exposed/Batch.kt +++ b/src/main/kotlin/de/maxr1998/diskord/util/exposed/Batch.kt @@ -37,7 +37,7 @@ suspend fun FieldSet.processBatches( if (batch.size < batchSize) break - lastOffset = toLong(batch.last()[autoIncColumn]!!) + lastOffset = toLong(checkNotNull(batch.last()[autoIncColumn]) { "Batch element autoIncColumn is null" }) } }