Skip to content

Commit

Permalink
chore: Bump detekt version from 1.21.0 to 1.23.1 (#1870)
Browse files Browse the repository at this point in the history
* chore: Bump detekt version from 1.21.0 to 1.23.1

* chore: Disable ArgumentListWrapping rule which is active by default since v1.22.0

* chore: Remove SpacingBetweenDeclarationsWithComments rule warnings in exposed-core

* chore: Remove MultiLineIfElse rule warnings in exposed-core

* chore: Add maxLineLength to ParameterListWrapping rule

* chore: Set properties for Wrapping rule

* chore: Disable PropertyWrapping rule which is active by default since v1.23.0

* chore: Disable EnumEntryNameCase rule which is active by default since v1.22.0

* chore: Remove AnnotationOnSeparateLine rule warning in exposed-core

* chore: Remove NoEmptyFirstLineInMethodBlock rule warning in exposed-core

* chore: Remove SpacingBetweenDeclarationsWithAnnotations rule warnings in exposed-core

* chore: Remove SpacingAroundUnaryOperator rule warnings in exposed-core

* chore: Rename ComplexMethod to CyclomaticComplexMethod

Property 'complexity>ComplexMethod' is deprecated. Rule is renamed to `CyclomaticComplexMethod` to distinguish between Cyclomatic Complexity and Cognitive Complexity.

* chore: Remove SpacingBetweenDeclarationsWithAnnotations rule warnings in exposed-crypt

* chore: Remove NoEmptyFirstLineInMethodBlock rule warnings in exposed-crypt

* chore: Remove MultiLineIfElse rule warning in exposed-dao

* chore: Remove FunctionReturnTypeSpacing rule warnings in exposed-dao

* chore: Remove CommentWrapping rule warning in exposed-dao

* chore: Remove SpacingAroundUnaryOperator rule warnings in exposed-dao

* chore: Remove NoSemicolons rule warning in exposed-dao

* chore: Remove SpacingAroundUnaryOperator rule warning in exposed-jdbc

* chore: Suppress Wrapping rule in JodaTimeMiscTableTest.kt

* chore: Remove NoEmptyFirstLineInMethodBlock rule warning in exposed-kotlin-datetime

* chore: Remove SpacingBetweenDeclarationsWithAnnotations rule warnings in exposed-kotlin-datetime

* chore: Remove PackageName rule warnings in exposed-spring-boot-starter

* chore: Remove NoEmptyFirstLineInMethodBlock rule warning in spring-transaction

* chore: Remove AnnotationOnSeparateLine rule warning in spring-transaction
  • Loading branch information
joc-a committed Sep 26, 2023
1 parent 3b4402a commit 926c5b1
Show file tree
Hide file tree
Showing 33 changed files with 139 additions and 74 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: "set-up-detekt"
uses: peter-murray/setup-detekt@v2
with:
detekt_version: 1.21.0
detekt_version: 1.23.1
# Runs detekt on changed files
- name: "run-detekt"
run: |
Expand All @@ -45,7 +45,7 @@ jobs:
fi
echo "Running detekt check..."
DETEKT_ISSUES=$(detekt-cli --build-upon-default-config --config detekt/detekt-config.yml --plugins detekt/detekt-formatting-1.21.0.jar --input $CHANGED_FILES)
DETEKT_ISSUES=$(detekt-cli --build-upon-default-config --config detekt/detekt-config.yml --plugins detekt/detekt-formatting-1.23.1.jar --input $CHANGED_FILES)
if [ -n "$DETEKT_ISSUES" ]; then
echo "***********************************************"
echo "$DETEKT_ISSUES"
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ val reportMerge by tasks.registering(ReportMergeTask::class) {

subprojects {
dependencies {
detektPlugins("io.gitlab.arturbosch.detekt", "detekt-formatting", "1.21.0")
detektPlugins("io.gitlab.arturbosch.detekt", "detekt-formatting", "1.23.1")
}
tasks.withType<Detekt>().configureEach detekt@{
onlyIf { this@subprojects.name !== "exposed-tests" }
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencies {
gradleApi()
implementation("org.jetbrains.kotlin.jvm", "org.jetbrains.kotlin.jvm.gradle.plugin", "1.9.10")
implementation("com.avast.gradle", "gradle-docker-compose-plugin", "0.17.4")
implementation("io.gitlab.arturbosch.detekt", "detekt-gradle-plugin", "1.21.0")
implementation("io.gitlab.arturbosch.detekt", "detekt-gradle-plugin", "1.23.1")
}

plugins {
Expand Down
12 changes: 11 additions & 1 deletion detekt/detekt-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ build:
maxIssues: 52

formatting:
ArgumentListWrapping:
active: false
EnumEntryNameCase:
active: false
MaximumLineLength:
maxLineLength: 166
MultiLineIfElse:
Expand All @@ -13,14 +17,20 @@ formatting:
active: true
autoCorrect: true
indentSize: 4
maxLineLength: 166
NoWildcardImports:
active: false
NoMultipleSpaces:
active: true
autoCorrect: false
PropertyWrapping:
active: false
SpacingAroundUnaryOperator:
active: true
autoCorrect: true
Wrapping:
active: true
maxLineLength: 166

style:
MaxLineLength:
Expand All @@ -46,7 +56,7 @@ complexity:
thresholdInClasses: 40
thresholdInFiles: 100
thresholdInObjects: 26
ComplexMethod:
CyclomaticComplexMethod:
threshold: 26
LongMethod:
threshold: 90
Expand Down
Binary file removed detekt/detekt-formatting-1.21.0.jar
Binary file not shown.
Binary file added detekt/detekt-formatting-1.23.1.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.jetbrains.exposed.dao.id

open class EntityID<T : Comparable<T>> protected constructor(val table: IdTable<T>, id: T?) : Comparable<EntityID<T>> {
constructor(id: T, table: IdTable<T>) : this(table, id)

@Suppress("VariableNaming")
var _value: Any? = id
val value: T get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package org.jetbrains.exposed.sql
*/
abstract class CompositeColumn<T> : Expression<T>() {
internal var nullable: Boolean = false

/**
* Parse values from [compositeValue] and return list of real columns with its values
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@ data class Index(
val table = columns.distinctBy { it.table }.singleOrNull()?.table
requireNotNull(table) { "Columns from different tables can't persist in one index" }
table
} else null
} else {
null
}
if (functions?.isNotEmpty() == true) {
requireNotNull(functionsTable) { "functionsTable argument must also be provided if functions are defined to create an index" }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class QueryBuilder(
) {
private val internalBuilder = StringBuilder()
private val _args = mutableListOf<Pair<IColumnType, Any?>>()

/** Returns the list of arguments used in this query. */
val args: List<Pair<IColumnType, Any?>> get() = _args

Expand Down
28 changes: 14 additions & 14 deletions exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Op.kt
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,11 @@ class AndBitOp<T, S : T>(
when (dialect.isSecondVersion) {
false -> append("BITAND(", expr1, ", ", expr2, ")")
true -> {
+ "BITAND("
+"BITAND("
castToExpressionTypeForH2BitWiseIps(expr1, this)
+ ", "
+", "
castToExpressionTypeForH2BitWiseIps(expr2, this)
+ ")"
+")"
}
}
}
Expand Down Expand Up @@ -460,11 +460,11 @@ class OrBitOp<T, S : T>(
when (dialect.isSecondVersion) {
false -> append("BITOR(", expr1, ", ", expr2, ")")
true -> {
+ "BITOR("
+"BITOR("
castToExpressionTypeForH2BitWiseIps(expr1, this)
+ ", "
+", "
castToExpressionTypeForH2BitWiseIps(expr2, this)
+ ")"
+")"
}
}
}
Expand Down Expand Up @@ -495,11 +495,11 @@ class XorBitOp<T, S : T>(
when (dialect.isSecondVersion) {
false -> append("BITXOR(", expr1, ", ", expr2, ")")
true -> {
+ "BITXOR("
+"BITXOR("
castToExpressionTypeForH2BitWiseIps(expr1, this)
+ ", "
+", "
castToExpressionTypeForH2BitWiseIps(expr2, this)
+ ")"
+")"
}
}
}
Expand All @@ -519,8 +519,8 @@ class LikeEscapeOp(expr1: Expression<*>, expr2: Expression<*>, like: Boolean, va
super.toQueryBuilder(queryBuilder)
if (escapeChar != null) {
with(queryBuilder) {
+ " ESCAPE "
+ stringParam(escapeChar.toString())
+" ESCAPE "
+stringParam(escapeChar.toString())
}
}
}
Expand Down Expand Up @@ -594,7 +594,7 @@ sealed class SubQueryOp<T>(
override fun toQueryBuilder(queryBuilder: QueryBuilder): Unit = queryBuilder {
append(expr, " $operator (")
query.prepareSQL(this)
+ ")"
+")"
}
}

Expand Down Expand Up @@ -628,7 +628,7 @@ class LiteralOp<T>(
/** Returns the value being used as a literal. */
val value: T
) : ExpressionWithColumnType<T>() {
override fun toQueryBuilder(queryBuilder: QueryBuilder): Unit = queryBuilder { + columnType.valueToString(value) }
override fun toQueryBuilder(queryBuilder: QueryBuilder): Unit = queryBuilder { +columnType.valueToString(value) }
}

/** Returns the specified [value] as a boolean literal. */
Expand Down Expand Up @@ -741,7 +741,7 @@ class NoOpConversion<T, S>(
val expr: Expression<T>,
override val columnType: IColumnType
) : ExpressionWithColumnType<S>() {
override fun toQueryBuilder(queryBuilder: QueryBuilder): Unit = queryBuilder { + expr }
override fun toQueryBuilder(queryBuilder: QueryBuilder): Unit = queryBuilder { +expr }
}

private fun QueryBuilder.appendExpression(expr: Expression<*>) {
Expand Down
12 changes: 4 additions & 8 deletions exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Query.kt
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,7 @@ open class Query(override var set: FieldSet, where: Op<Boolean>?) : AbstractQuer
*/
fun Query.andWhere(andPart: SqlExpressionBuilder.() -> Op<Boolean>) = adjustWhere {
val expr = Op.build { andPart() }
if (this == null) expr
else this and expr
if (this == null) expr else this and expr
}

/**
Expand All @@ -238,8 +237,7 @@ fun Query.andWhere(andPart: SqlExpressionBuilder.() -> Op<Boolean>) = adjustWher
*/
fun Query.orWhere(orPart: SqlExpressionBuilder.() -> Op<Boolean>) = adjustWhere {
val expr = Op.build { orPart() }
if (this == null) expr
else this or expr
if (this == null) expr else this or expr
}

/**
Expand All @@ -248,8 +246,7 @@ fun Query.orWhere(orPart: SqlExpressionBuilder.() -> Op<Boolean>) = adjustWhere
*/
fun Query.andHaving(andPart: SqlExpressionBuilder.() -> Op<Boolean>) = adjustHaving {
val expr = Op.build { andPart() }
if (this == null) expr
else this and expr
if (this == null) expr else this and expr
}

/**
Expand All @@ -258,6 +255,5 @@ fun Query.andHaving(andPart: SqlExpressionBuilder.() -> Op<Boolean>) = adjustHav
*/
fun Query.orHaving(orPart: SqlExpressionBuilder.() -> Op<Boolean>) = adjustHaving {
val expr = Op.build { orPart() }
if (this == null) expr
else this or expr
if (this == null) expr else this or expr
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ data class Schema(
fun exists(): Boolean = currentDialect.schemaExists(this)

fun createStatement(): List<String> {

if (!currentDialect.supportsCreateSchema) {
throw UnsupportedByDialectException("The current dialect doesn't support create schema statement", currentDialect)
}
Expand All @@ -64,6 +63,7 @@ data class Schema(
return listOf(currentDialect.setSchema(this))
}
}

/** Appends both [str1] and [str2] to the receiver [StringBuilder] if [str2] is not `null`. */
internal fun StringBuilder.appendIfNotNull(str1: String, str2: Any?) = apply {
if (str2 != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ class CeilingFunction<T : Number?>(expression: ExpressionWithColumnType<T>) : Cu
functionName = if (
currentDialectIfAvailable is SQLiteDialect || currentDialectIfAvailable is OracleDialect ||
currentDialectIfAvailable?.h2Mode == H2Dialect.H2CompatibilityMode.Oracle
) "CEIL" else "CEILING",
) {
"CEIL"
} else {
"CEILING"
},
columnType = LongColumnType(),
expr = arrayOf(expression)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ abstract class BaseBatchInsertStatement(
override fun valuesAndDefaults(values: Map<Column<*>, Any?>) = arguments!!.first().toMap()

override fun prepared(transaction: Transaction, sql: String): PreparedStatementApi {
return if (!shouldReturnGeneratedValues) transaction.connection.prepareStatement(sql, false)
else super.prepared(transaction, sql)
return if (!shouldReturnGeneratedValues) {
transaction.connection.prepareStatement(sql, false)
} else {
super.prepared(transaction, sql)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ open class SQLServerBatchInsertStatement(table: Table, ignore: Boolean = false,

override fun prepareSQL(transaction: Transaction, prepared: Boolean): String {
val values = arguments!!
val sql = if (values.isEmpty()) ""
else {
val sql = if (values.isEmpty()) {
""
} else {
val output = columnToReturnValue?.let {
" OUTPUT inserted.${transaction.identity(it)} AS GENERATED_KEYS"
}.orEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ open class InsertStatement<Key : Any>(val table: Table, val isIgnore: Boolean =
}
pairs.forEach { (col, value) ->
if (value != DefaultValueMarker) {
if (col.columnType.isAutoInc || value is NextVal<*>) map.getOrPut(col) { value }
else map[col] = value
if (col.columnType.isAutoInc || value is NextVal<*>) {
map.getOrPut(col) { value }
} else {
map[col] = value
}
}
}

Expand Down Expand Up @@ -124,19 +127,25 @@ open class InsertStatement<Key : Any>(val table: Table, val isIgnore: Boolean =

protected fun List<Pair<Column<*>, Any?>>.toSqlString(prepared: Boolean): String {
val builder = QueryBuilder(prepared)
return if (isEmpty()) "" else with(builder) {
this@toSqlString.appendTo(prefix = "VALUES (", postfix = ")") { (column, value) ->
registerArgument(column, value)
return if (isEmpty()) {
""
} else {
with(builder) {
this@toSqlString.appendTo(prefix = "VALUES (", postfix = ")") { (column, value) ->
registerArgument(column, value)
}
toString()
}
toString()
}
}

protected open fun PreparedStatementApi.execInsertFunction(): Pair<Int, ResultSet?> {
val inserted = if (arguments().count() > 1 || isAlwaysBatch) executeBatch().sum() else executeUpdate()
val rs = if (autoIncColumns.isNotEmpty()) {
resultSet
} else null
} else {
null
}
return inserted to rs
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@file:Suppress("Filename", "MatchingDeclarationName")

package org.jetbrains.exposed.sql.statements.api

interface ExposedConnection<OriginalConnection : Any> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,12 @@ interface TransactionManager {
companion object {
internal val currentDefaultDatabase = AtomicReference<Database>()

@Suppress("SpacingBetweenDeclarationsWithAnnotations")
var defaultDatabase: Database?
@Synchronized get() = currentDefaultDatabase.get() ?: databases.firstOrNull()
@Synchronized set(value) { currentDefaultDatabase.set(value) }
@Synchronized set(value) {
currentDefaultDatabase.set(value)
}

private val databases = ConcurrentLinkedDeque<Database>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ open class H2Dialect : VendorDialect(dialectName, H2DataTypeProvider, H2Function
H2MajorVersion.One -> "NAME" to "VALUE"
H2MajorVersion.Two -> "SETTING_NAME" to "SETTING_VALUE"
}

@Language("H2")
val fetchModeQuery = "SELECT $settingValueField FROM INFORMATION_SCHEMA.SETTINGS WHERE $settingNameField = 'MODE'"
val modeValue = TransactionManager.current().exec(fetchModeQuery) { rs ->
Expand Down Expand Up @@ -217,7 +218,6 @@ open class H2Dialect : VendorDialect(dialectName, H2DataTypeProvider, H2Function
override val supportsCreateSequence: Boolean by lazy { resolveDelegatedDialect()?.supportsCreateSequence ?: super.supportsCreateSequence }
override val needsSequenceToAutoInc: Boolean by lazy { resolveDelegatedDialect()?.needsSequenceToAutoInc ?: super.needsSequenceToAutoInc }
override val defaultReferenceOption: ReferenceOption by lazy { resolveDelegatedDialect()?.defaultReferenceOption ?: super.defaultReferenceOption }
// override val needsQuotesWhenSymbolsInNames: Boolean by lazy { resolveDelegatedDialect()?.needsQuotesWhenSymbolsInNames ?: super.needsQuotesWhenSymbolsInNames }
override val supportsSequenceAsGeneratedKeys: Boolean by lazy {
resolveDelegatedDialect()?.supportsSequenceAsGeneratedKeys ?: super.supportsSequenceAsGeneratedKeys
}
Expand Down
Loading

0 comments on commit 926c5b1

Please sign in to comment.