Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Remove more detekt issues (part 4) #1794

Merged
merged 25 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
81a0151
chore: Remove Suppress annotation where it's unnecessary
joc-a Jul 18, 2023
5d13faa
chore: Suppress MagicNumber detekt warnings
joc-a Jul 18, 2023
9c5d28a
chore: Suppress TooGenericExceptionThrown detekt warnings
joc-a Jul 18, 2023
0021580
chore: Suppress TooGenericExceptionCaught detekt warnings
joc-a Jul 18, 2023
3aedca1
chore: Suppress FunctionNaming detekt warnings
joc-a Jul 18, 2023
18d49b8
chore: Suppress SwallowedException detekt warnings
joc-a Jul 18, 2023
7231b80
chore: Remove ForbiddenComment detekt issue
joc-a Jul 18, 2023
8b41d66
chore: Increase detekt LongMethod threshold from 60 (default) to 90 a…
joc-a Jul 18, 2023
4133d3e
chore: Suppress UnnecessaryAbstractClass detekt warnings
joc-a Jul 18, 2023
f587c60
chore: Suppress NestedBlockDepth detekt warnings
joc-a Jul 18, 2023
87c3f5b
chore: Suppress ComplexMethod detekt warnings
joc-a Jul 18, 2023
d24af9f
chore: Suppress MatchingDeclarationName detekt warning
joc-a Jul 18, 2023
71528db
chore: Suppress VariableNaming detekt warnings
joc-a Jul 18, 2023
551ce42
chore: Fix detekt issues in PR build
joc-a Jul 18, 2023
d75ea78
chore: Fix detekt issues in PR build
joc-a Jul 18, 2023
be03ffe
chore: Remove path to formatting jar file
joc-a Jul 18, 2023
a1acbde
chore: Fix detekt issues in PR build
joc-a Jul 18, 2023
f381aeb
chore: Suppress detekt warnings in exposed-core module
joc-a Jul 18, 2023
52ecb69
chore: Suppress detekt warning in exposed-crypt module
joc-a Jul 18, 2023
2b7718d
chore: Suppress detekt warning in exposed-dao module
joc-a Jul 18, 2023
835a1e8
chore: Remove detekt issue in exposed-java-time module
joc-a Jul 18, 2023
f003f7b
chore: Remove detekt issue in exposed-kotlin-datetime module
joc-a Jul 18, 2023
9cb5e14
chore: Remove detekt issues in exposed-spring-boot-starter module
joc-a Jul 18, 2023
2ddb17b
chore: Remove detekt issues in spring-transaction module
joc-a Jul 18, 2023
f991755
chore: Remove detekt issues in samples module
joc-a Jul 18, 2023
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
5 changes: 0 additions & 5 deletions .idea/detekt.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("FunctionName")

package org.jetbrains.exposed.gradle

import com.avast.gradle.dockercompose.ComposeExtension
Expand All @@ -8,5 +6,5 @@ import org.gradle.kotlin.dsl.getByName

private inline fun <reified T : Any> Project.extByName(name: String): T = extensions.getByName<T>(name)

val Project._dockerCompose
val Project.dockerCompose
get() = extByName<ComposeExtension>("dockerCompose")
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
@file:Suppress("UnstableApiUsage")

package org.jetbrains.exposed.gradle

import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.provider.Property
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPom
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.plugins.signing.SigningExtension
import org.gradle.api.plugins.JavaPluginExtension

infix fun <T> Property<T>.by(value: T) {
set(value)
Expand Down Expand Up @@ -55,10 +53,12 @@ fun MavenPublication.signPublicationIfKeyPresent(project: Project) {
}
}

@Suppress("FunctionNaming")
fun Project._publishing(configure: PublishingExtension.() -> Unit) {
extensions.configure("publishing", configure)
}

@Suppress("FunctionNaming")
fun Project._java(configure: JavaPluginExtension.() -> Unit) {
extensions.configure("java", configure)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.jetbrains.exposed.gradle.tasks

import com.avast.gradle.dockercompose.ComposeSettings
import org.gradle.api.tasks.Input
import org.jetbrains.exposed.gradle._dockerCompose
import org.jetbrains.exposed.gradle.dockerCompose
import java.io.File
import java.time.Duration
import javax.inject.Inject
Expand All @@ -16,13 +16,15 @@ open class DBTestWithDockerCompose(dialect: String, @get:Input val port: Int, @g
@Inject
constructor(parameters: Parameters) : this(parameters.dialect, parameters.port, parameters.dockerComposeServiceName)

private val dockerCompose: ComposeSettings = project._dockerCompose.nested(dockerComposeServiceName).apply {
private val dockerCompose: ComposeSettings = project.dockerCompose.nested(dockerComposeServiceName).apply {
environment.put("COMPOSE_CONVERT_WINDOWS_PATHS", true)
useComposeFiles.add(
File(project.rootProject.projectDir, "buildScripts/docker/docker-compose-$dockerComposeServiceName.yml").absolutePath
)
captureContainersOutput.set(true)
removeVolumes.set(true)

@Suppress("MagicNumber")
waitForHealthyStateTimeout.set(Duration.ofMinutes(60))
}

Expand Down
4 changes: 4 additions & 0 deletions detekt/detekt-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ style:
MagicNumber:
ignoreNamedArgument: true
ignoreRanges: true
ThrowsCount:
active: false

complexity:
LongParameterList:
Expand All @@ -43,6 +45,8 @@ complexity:
thresholdInObjects: 26
ComplexMethod:
threshold: 26
LongMethod:
threshold: 90

naming:
ConstructorParameterNaming:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ object EntityIDFunctionProvider {
}
}

@Suppress("UNCHECKED_CAST")
fun <T : Comparable<T>> createEntityID(value: T, table: IdTable<T>) = factory.createEntityID(value, table)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class QueryAlias(val query: AbstractQuery<*>, val alias: String) : ColumnSet() {
query.set.source.columns.find { it == original }?.clone() as? Column<T>
?: error("Column not found in original table")

@Suppress("UNCHECKED_CAST")
operator fun <T : Any?> get(original: Expression<T>): Expression<T> {
val aliases = query.set.fields.filterIsInstance<ExpressionAlias<T>>()
return aliases.find { it == original }?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Column<T>(
internal fun isOneColumnPK(): Boolean = this == table.primaryKey?.columns?.singleOrNull()

/** Returns the SQL representation of this column. */
@Suppress("ComplexMethod")
fun descriptionDdl(modify: Boolean = false): String = buildString {
val tr = TransactionManager.current()
val column = this@Column
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ interface ISqlExpressionBuilder {
} as QueryParameter<T>

/** Returns the specified [value] as a literal of type [T]. */
@Suppress("UNCHECKED_CAST")
@Suppress("UNCHECKED_CAST", "ComplexMethod")
fun <T, S : T?> ExpressionWithColumnType<S>.asLiteral(value: T): LiteralOp<T> = when (value) {
is Boolean -> booleanLiteral(value)
is Byte -> byteLiteral(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,6 @@ open class Table(name: String = "") : ColumnSet(), DdlAware {
*
* @see ReferenceOption
*/
@Suppress("UNCHECKED_CAST")
@JvmName("optReferenceByIdColumn")
fun <T : Comparable<T>, E : EntityID<T>> optReference(
name: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ open class InsertStatement<Key : Any>(val table: Table, val isIgnore: Boolean =

fun <T> getOrNull(column: Column<T>): T? = resultedValues?.firstOrNull()?.getOrNull(column)

@Suppress("NestedBlockDepth")
@Suppress("NestedBlockDepth", "ComplexMethod")
private fun processResults(rs: ResultSet?, inserted: Int): List<ResultRow> {
val autoGeneratedKeys = arrayListOf<MutableMap<Column<*>, Any?>>()

Expand Down Expand Up @@ -98,6 +98,7 @@ open class InsertStatement<Key : Any>(val table: Table, val isIgnore: Boolean =
return autoGeneratedKeys.map { ResultRow.createAndFillValues(it as Map<Expression<*>, Any?>) }
}

@Suppress("NestedBlockDepth")
protected open fun valuesAndDefaults(values: Map<Column<*>, Any?> = this.values): Map<Column<*>, Any?> {
val result = values.toMutableMap()
targets.forEach { table ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ fun <T> transaction(
}
}

@Suppress("LongParameterList")
fun <T> inTopLevelTransaction(
transactionIsolation: Int,
readOnly: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ internal inline fun TransactionInterface.closeLoggingException(log: (Exception)
}
}

@Suppress("TooGenericExceptionThrown")
val Database?.transactionManager: TransactionManager
get() = TransactionManager.managerFor(this)
?: throw RuntimeException("database $this don't have any transaction manager")
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ abstract class DataTypeProvider {
/** Binary type for storing [UUID]. */
open fun uuidType(): String = "BINARY(16)"

@Suppress("MagicNumber")
open fun uuidToDB(value: UUID): Any =
ByteBuffer.allocate(16).putLong(value.mostSignificantBits).putLong(value.leastSignificantBits).array()

Expand Down Expand Up @@ -1042,6 +1043,7 @@ abstract class VendorDialect(
protected val identifierManager
get() = TransactionManager.current().db.identifierManager

@Suppress("UnnecessaryAbstractClass")
abstract class DialectNameProvider(val dialectName: String)

/* Cached values */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ internal object OracleDataTypeProvider : DataTypeProvider() {
override fun booleanFromStringToBoolean(value: String): Boolean = try {
value.toLong() != 0L
} catch (ex: NumberFormatException) {
@Suppress("SwallowedException")
try {
value.lowercase().toBooleanStrict()
} catch (ex: IllegalArgumentException) {
Expand Down Expand Up @@ -322,6 +323,7 @@ open class OracleDialect : VendorDialect(dialectName, OracleDataTypeProvider, Or

override fun createSchema(schema: Schema): String = buildString {
if ((schema.quota == null) xor (schema.on == null)) {
@Suppress("UseRequire")
throw IllegalArgumentException("You must either provide both <quota> and <on> options or non of them")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ open class SQLServerDialect : VendorDialect(dialectName, SQLServerDataTypeProvid
return columnDefault !in nonAcceptableDefaults
}

// TODO: Fix changing default value on column as it requires to drop/create constraint
// https://stackoverflow.com/questions/15547210/modify-default-value-in-sql-server
// EXPOSED-85 Fix changing default value on column in SQL Server as it requires to drop/create constraint
override fun modifyColumn(column: Column<*>, columnDiff: ColumnDiff): List<String> =
super.modifyColumn(column, columnDiff).map { it.replace("MODIFY COLUMN", "ALTER COLUMN") }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import javax.crypto.spec.SecretKeySpec
import kotlin.math.ceil

object Algorithms {
@Suppress("MagicNumber")
private fun base64EncodedLength(byteSize: Int): Int = ceil(byteSize.toDouble() / 3).toInt() * 4
private fun paddingLen(len: Int, blockSize: Int): Int = if (len % blockSize == 0) 0 else blockSize - len % blockSize
private val base64Decoder = Base64.getDecoder()
Expand Down Expand Up @@ -82,7 +83,7 @@ object Algorithms {

private const val TRIPLE_DES_KEY_LENGTH = 24
private const val TRIPLE_DES_BLOCK_LENGTH = 8
@Suppress("FunctionNaming")
@Suppress("FunctionNaming", "UseRequire")
fun TRIPLE_DES(secretKey: CharSequence): Encryptor {
if (secretKey.toString().toByteArray().size != TRIPLE_DES_KEY_LENGTH) {
throw IllegalArgumentException("secretKey must have 24 bytes")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ open class Entity<ID : Comparable<ID>>(val id: EntityID<ID>) {
internal set

val writeValues = LinkedHashMap<Column<Any?>, Any?>()

@Suppress("VariableNaming")
var _readValues: ResultRow? = null

val readValues: ResultRow
get() = _readValues ?: run {
val table = klass.table
Expand Down Expand Up @@ -178,7 +181,6 @@ open class Entity<ID : Comparable<ID>>(val id: EntityID<ID>) {
return this.restoreValueFromParts(values)
}

@Suppress("UNCHECKED_CAST")
fun <T, R : Any> Column<T>.lookupInReadValues(found: (T?) -> R?, notFound: () -> R?): R? =
if (_readValues?.hasValue(this) == true) {
found(readValues[this])
Expand Down Expand Up @@ -261,6 +263,7 @@ open class Entity<ID : Comparable<ID>>(val id: EntityID<ID>) {
if (batch == null) {
val table = klass.table
// Store values before update to prevent flush inside UpdateStatement
@Suppress("VariableNaming")
val _writeValues = writeValues.toMap()
storeWrittenValues()
// In case of batch all changes will be registered after all entities flushed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class EntityCache(private val transaction: Transaction) {
* Amount of entities to keep in a cache per an Entity class.
* On setting a new value all data stored in cache will be adjusted to a new size
*/
@Suppress("MemberVisibilityCanBePrivate")
var maxEntitiesToStore = transaction.db.config.maxEntitiesToStoreInCachePerEntity
set(value) {
val diff = value - field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ abstract class EntityClass<ID : Comparable<ID>, out T : Entity<ID>>(

private fun Query.setForUpdateStatus(): Query = if (this@EntityClass is ImmutableEntityClass<*, *>) this.notForUpdate() else this

@Suppress("CAST_NEVER_SUCCEEDS")
fun <SID> warmUpOptReferences(references: List<SID>, refColumn: Column<SID?>, forUpdate: Boolean? = null): List<T> =
warmUpReferences(references, refColumn as Column<SID>, forUpdate)

Expand Down Expand Up @@ -419,6 +418,7 @@ abstract class EntityClass<ID : Comparable<ID>, out T : Entity<ID>>(
else -> findQuery
}.toList()

@Suppress("ComplexMethod")
internal fun <SID : Comparable<SID>> warmUpLinkedReferences(
references: List<EntityID<SID>>,
sourceRefColumn: Column<EntityID<SID>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ fun <ID : Comparable<ID>, T : Entity<ID>> EntityChange.toEntity(): T? = (entityC

fun <ID : Comparable<ID>, T : Entity<ID>> EntityChange.toEntity(klass: EntityClass<ID, T>): T? {
if (!entityClass.isAssignableTo(klass)) return null
@Suppress("UNCHECKED_CAST")
return toEntity<ID, T>()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class EntityLifecycleInterceptor : GlobalStatementInterceptor {
return userData.filterValues { it is EntityCache }
}

@Suppress("ComplexMethod")
override fun beforeExecution(transaction: Transaction, context: StatementContext) {
when (val statement = context.statement) {
is Query -> transaction.flushEntities(statement)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package org.jetbrains.exposed.dao
import org.jetbrains.exposed.dao.id.EntityID
import org.jetbrains.exposed.dao.id.IdTable

@Suppress("UnnecessaryAbstractClass")
abstract class IntEntity(id: EntityID<Int>) : Entity<Int>(id)

@Suppress("UnnecessaryAbstractClass")
abstract class IntEntityClass<out E : IntEntity> constructor(
table: IdTable<Int>,
entityType: Class<E>? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package org.jetbrains.exposed.dao
import org.jetbrains.exposed.dao.id.EntityID
import org.jetbrains.exposed.dao.id.IdTable

@Suppress("UnnecessaryAbstractClass")
abstract class LongEntity(id: EntityID<Long>) : Entity<Long>(id)

@Suppress("UnnecessaryAbstractClass")
abstract class LongEntityClass<out E : LongEntity>(
table: IdTable<Long>,
entityType: Class<E>? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private fun <SRC : Entity<*>> filterRelationsForEntity(
return validMembers.filter { it in relations } as Collection<KProperty1<SRC, Any?>>
}

@Suppress("UNCHECKED_CAST")
@Suppress("UNCHECKED_CAST", "NestedBlockDepth", "ComplexMethod")
private fun <ID : Comparable<ID>> List<Entity<ID>>.preloadRelations(
vararg relations: KProperty1<out Entity<*>, Any?>,
nodesVisited: MutableSet<EntityClass<*, *>> = mutableSetOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import org.jetbrains.exposed.dao.id.EntityID
import org.jetbrains.exposed.dao.id.IdTable
import java.util.*

@Suppress("UnnecessaryAbstractClass")
abstract class UUIDEntity(id: EntityID<UUID>) : Entity<UUID>(id)

@Suppress("UnnecessaryAbstractClass")
abstract class UUIDEntityClass<out E : UUIDEntity>(
table: IdTable<UUID>,
entityType: Class<E>? = null,
Expand Down
8 changes: 2 additions & 6 deletions exposed-java-time/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@ dependencies {
testImplementation(kotlin("test-junit"))
}

//tasks.withType<Detekt>().configureEach {
// // Target version of the generated JVM bytecode. It is used for type resolution.
// jvmTarget = "1.8"
//}

tasks.withType<Test>().configureEach {
if (JavaVersion.VERSION_1_8 > JavaVersion.current())
if (JavaVersion.VERSION_1_8 > JavaVersion.current()) {
jvmArgs = listOf("-XX:MaxPermSize=256m")
}
testLogging {
events.addAll(listOf(TestLogEvent.PASSED, TestLogEvent.FAILED, TestLogEvent.SKIPPED))
showStandardStreams = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ internal fun dateTimeWithFractionFormat(fraction: Int): DateTimeFormatter {
return DateTimeFormatter.ofPattern(newFormat).withLocale(Locale.ROOT).withZone(ZoneId.systemDefault())
}

@Suppress("MagicNumber")
internal val LocalDate.millis get() = atStartOfDay(ZoneId.systemDefault()).toEpochSecond() * 1000

@Suppress("MagicNumber")
class JavaLocalDateColumnType : ColumnType(), IDateColumnType {
override val hasTimePart: Boolean = false

Expand Down Expand Up @@ -94,6 +96,7 @@ class JavaLocalDateColumnType : ColumnType(), IDateColumnType {
}
}

@Suppress("MagicNumber")
class JavaLocalDateTimeColumnType : ColumnType(), IDateColumnType {
override val hasTimePart: Boolean = true
override fun sqlType(): String = currentDialect.dataTypeProvider.dateTimeType()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@file:Suppress("MaximumLineLength")
@file:Suppress("MaximumLineLength", "LongMethod")

package org.jetbrains.exposed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ internal class JdbcIdentifierManager(metadata: DatabaseMetaData) : IdentifierMan
override val supportsMixedQuotedIdentifiers = metadata.supportsMixedCaseQuotedIdentifiers()
private val _keywords = metadata.sqlKeywords.split(',')
override fun dbKeywords(): List<String> = _keywords
override val extraNameCharacters = metadata.extraNameCharacters!!
override val extraNameCharacters = metadata.extraNameCharacters !!

@Suppress("MagicNumber")
override val oracleVersion = when {
metadata.databaseProductName != "Oracle" -> OracleVersion.NonOracle
metadata.databaseMajorVersion <= 11 -> OracleVersion.Oracle11g
Expand Down
Loading