Skip to content

Commit

Permalink
Bump ktlint to 0.48.2 (#4049)
Browse files Browse the repository at this point in the history
  • Loading branch information
hfhbd committed Apr 11, 2023
1 parent dd20f6c commit 3a62ba0
Show file tree
Hide file tree
Showing 43 changed files with 179 additions and 108 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ spotless {
targetExclude "**/gen/**/*.*", "**/generated/**/*.*", "sqldelight-compiler/integration-tests/src/test/kotlin/com/example/**/*.*", "sqldelight-compiler/src/test/migration-interface-fixtures/**/*.*"
ktlint(libs.versions.ktlint.get()).editorConfigOverride([
"indent_size": "2",
"disabled_rules": "package-name",
"ij_kotlin_allow_trailing_comma": "true",
"ij_kotlin_allow_trailing_comma_on_call_site": "true",
"ktlint_standard_package-name": "disabled",
"ij_kotlin_allow_trailing_comma": "true",
"ij_kotlin_allow_trailing_comma_on_call_site": "true",
])
trimTrailingWhitespace()
endWithNewline()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ internal enum class HsqlType(override val javaType: TypeName) : DialectType {
override fun decode(value: CodeBlock) = CodeBlock.of("%L == 1L", value)

override fun encode(value: CodeBlock) = CodeBlock.of("if (%L) 1L else 0L", value)
};
},
;

override fun prepareStatementBinder(columnIndex: String, value: CodeBlock): CodeBlock {
return CodeBlock.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ internal enum class MySqlType(override val javaType: TypeName) : DialectType {
DATE(ClassName("java.time", "LocalDate")),
TIME(ClassName("java.time", "LocalTime")),
DATETIME(ClassName("java.time", "LocalDateTime")),
TIMESTAMP(ClassName("java.time", "OffsetDateTime"))
TIMESTAMP(ClassName("java.time", "OffsetDateTime")),
;

override fun prepareStatementBinder(columnIndex: String, value: CodeBlock): CodeBlock {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ class MySqlTypeResolver(
override fun argumentType(parent: PsiElement, argument: SqlExpr): IntermediateType {
when (parent) {
is MySqlExtensionExpr -> {
return if (argument == parent.ifExpr?.children?.first()) IntermediateType(PrimitiveType.BOOLEAN)
else IntermediateType(ARGUMENT)
return if (argument == parent.ifExpr?.children?.first()) {
IntermediateType(PrimitiveType.BOOLEAN)
} else {
IntermediateType(ARGUMENT)
}
}
}
return parentResolver.argumentType(parent, argument)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ internal abstract class AlterTableChangeColumnMixin(
super.annotate(annotationHolder)

if (tablesAvailable(this)
.filter { it.tableName.textMatches(alterStmt.tableName) }
.flatMap { it.query.columns }
.none { (it.element as? SqlColumnName)?.textMatches(columnName) == true }
.filter { it.tableName.textMatches(alterStmt.tableName) }
.flatMap { it.query.columns }
.none { (it.element as? SqlColumnName)?.textMatches(columnName) == true }
) {
annotationHolder.createErrorAnnotation(
element = columnDef.columnName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ internal abstract class AlterTableModifyColumnMixin(
super.annotate(annotationHolder)

if (tablesAvailable(this)
.filter { it.tableName.textMatches(alterStmt.tableName) }
.flatMap { it.query.columns }
.none { (it.element as? SqlColumnName)?.textMatches(columnDef.columnName) == true }
.filter { it.tableName.textMatches(alterStmt.tableName) }
.flatMap { it.query.columns }
.none { (it.element as? SqlColumnName)?.textMatches(columnDef.columnName) == true }
) {
annotationHolder.createErrorAnnotation(
element = columnDef.columnName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ internal fun MySqlPlacementClause?.placeInQuery(
replace: QueryColumn? = null,
): List<QueryColumn> {
if (this == null) {
return if (replace == null) columns + column
else columns.map { if (it == replace) column else it }
return if (replace == null) {
columns + column
} else {
columns.map { if (it == replace) column else it }
}
}

return if (columnName != null) {
Expand All @@ -22,10 +25,12 @@ internal fun MySqlPlacementClause?.placeInQuery(
if (replace != null) remove(replace)

val index = indexOfFirst { (it.element as SqlColumnName).textMatches(columnName!!) }
if (index == -1) throw AnnotationException(
msg = "Unable to replace $replace with $column after $columnName in $columns",
element = this@placeInQuery,
)
if (index == -1) {
throw AnnotationException(
msg = "Unable to replace $replace with $column after $columnName in $columns",
element = this@placeInQuery,
)
}
add(index + 1, column)
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ internal class MySqlConnectionManager : ConnectionManager {
prefilledProperties: ConnectionProperties?,
): ConnectionProperties? {
val dialog =
if (prefilledProperties == null) MySqlConnectionDialog(project)
else {
if (prefilledProperties == null) {
MySqlConnectionDialog(project)
} else {
val properties = adapter.fromJson(prefilledProperties.serializedProperties)!!
MySqlConnectionDialog(
project = project,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ class PostgreSqlTypeResolver(private val parentResolver: TypeResolver) : TypeRes
val tableDef = columnDef.parent as? SqlCreateTableStmt ?: return intermediateType
tableDef.tableConstraintList.forEach {
if (columnDef.columnName.name in it.indexedColumnList.mapNotNull {
val expr = it.expr
if (expr is SqlColumnExpr) expr.columnName.name else null
}
val expr = it.expr
if (expr is SqlColumnExpr) expr.columnName.name else null
}
) {
return intermediateType.asNonNullable()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ internal abstract class AlterTableRenameColumnMixin(
super.annotate(annotationHolder)

if (tablesAvailable(this)
.filter { it.tableName.textMatches(alterStmt.tableName) }
.flatMap { it.query.columns }
.none { (it.element as? SqlColumnName)?.textMatches(columnName) == true }
.filter { it.tableName.textMatches(alterStmt.tableName) }
.flatMap { it.query.columns }
.none { (it.element as? SqlColumnName)?.textMatches(columnName) == true }
) {
annotationHolder.createErrorAnnotation(
element = columnName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ internal class PostgresConnectionManager : ConnectionManager {
prefilledProperties: ConnectionProperties?,
): ConnectionProperties? {
val dialog =
if (prefilledProperties == null) PostgresConnectionDialog(project)
else {
if (prefilledProperties == null) {
PostgresConnectionDialog(project)
} else {
val properties = adapter.fromJson(prefilledProperties.serializedProperties)!!
PostgresConnectionDialog(
project = project,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ internal abstract class AlterTableRenameColumnMixin(
super.annotate(annotationHolder)

if (tablesAvailable(this)
.filter { it.tableName.textMatches(alterStmt.tableName) }
.flatMap { it.query.columns }
.none { (it.element as? SqlColumnName)?.textMatches(columnName) == true }
.filter { it.tableName.textMatches(alterStmt.tableName) }
.flatMap { it.query.columns }
.none { (it.element as? SqlColumnName)?.textMatches(columnName) == true }
) {
annotationHolder.createErrorAnnotation(
element = columnName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ private class JsonTypeResolver(private val parentResolver: TypeResolver) :
override fun functionType(functionExpr: SqlFunctionExpr): IntermediateType? {
when (functionExpr.functionName.text) {
"json_array", "json", "json_insert", "json_replace", "json_set", "json_object", "json_patch",
"json_remove", "json_type", "json_quote", "json_group_array", "json_group_object", ->
"json_remove", "json_type", "json_quote", "json_group_array", "json_group_object",
->
return IntermediateType(PrimitiveType.TEXT)
"json_array_length" -> return IntermediateType(PrimitiveType.INTEGER)
"json_extract" -> return IntermediateType(PrimitiveType.TEXT).asNullable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,11 @@ private class AndroidPreparedStatement(
}

override fun bindBoolean(index: Int, boolean: Boolean?) {
if (boolean == null) statement.bindNull(index + 1)
else statement.bindLong(index + 1, if (boolean) 1L else 0L)
if (boolean == null) {
statement.bindNull(index + 1)
} else {
statement.bindLong(index + 1, if (boolean) 1L else 0L)
}
}

override fun <R> executeQuery(mapper: (SqlCursor) -> R): R = throw UnsupportedOperationException()
Expand Down Expand Up @@ -271,8 +274,11 @@ private class AndroidQuery(

override fun bindBoolean(index: Int, boolean: Boolean?) {
binds[index] = {
if (boolean == null) it.bindNull(index + 1)
else it.bindLong(index + 1, if (boolean) 1L else 0L)
if (boolean == null) {
it.bindNull(index + 1)
} else {
it.bindLong(index + 1, if (boolean) 1L else 0L)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ interface ConnectionManager {
) : Transacter.Transaction() {
override fun endTransaction(successful: Boolean): QueryResult<Unit> {
if (enclosingTransaction == null) {
if (successful) connectionManager.apply { connection.endTransaction() }
else connectionManager.apply { connection.rollbackTransaction() }
if (successful) {
connectionManager.apply { connection.endTransaction() }
} else {
connectionManager.apply { connection.rollbackTransaction() }
}
}
connectionManager.transaction = enclosingTransaction
return QueryResult.Unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,11 @@ private class JsSqlCursor(private val statement: Statement) : SqlCursor {

override fun getBoolean(index: Int): Boolean? {
val double = (statement.get()[index] as? Double)
return if (double == null) null
else double.toLong() == 1L
return if (double == null) {
null
} else {
double.toLong() == 1L
}
}

fun close() { statement.freemem() }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@file:JsModule("sql.js")
@file:JsNonModule
@file:Suppress("INTERFACE_WITH_SUPERCLASS", "OVERRIDING_FINAL_MEMBER", "RETURN_TYPE_MISMATCH_ON_OVERRIDE", "CONFLICTING_OVERLOADS", "EXTERNAL_DELEGATION")

package app.cash.sqldelight.driver.sqljs

import org.khronos.webgl.Uint8Array
Expand Down
6 changes: 5 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ testhelp = "0.6.5"
sqljs = "1.6.2"
paging-mpp = "3.1.1-0.2.0"
paging3 = "3.1.1"
ktlint = "0.46.1"
ktlint = "0.48.2"
agp = "7.4.2"
compileSdk = "33"
minSdk = "16"
Expand Down Expand Up @@ -90,6 +90,10 @@ testContainers-mysql = { module = "org.testcontainers:mysql", version.ref = "tes
testContainers-postgres = { module = "org.testcontainers:postgresql", version.ref = "testContainers" }
testContainers-r2dbc = { module = "org.testcontainers:r2dbc", version.ref = "testContainers" }

# dummy to get renovate updates.
# The version is used in rootProject build.gradle with spotless.
ktlint-dummy = { module = "com.pinterest:ktlint", version.ref = "ktlint" }

[plugins]
android-library = { id = "com.android.library", version.ref = "agp" }
android-application = { id = "com.android.application", version.ref = "agp" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package com.example.sqldelight.hockey.data
interface PlayerVals {
enum class Shoots {
RIGHT,
LEFT
LEFT,
}

enum class Position {
LEFT_WING,
RIGHT_WING,
CENTER,
DEFENSE,
GOALIE
GOALIE,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ enum class PrimitiveType(override val javaType: TypeName) : DialectType {
REAL(DOUBLE),
TEXT(String::class.asTypeName()),
BOOLEAN(com.squareup.kotlinpoet.BOOLEAN),
BLOB(ByteArray::class.asTypeName());
BLOB(ByteArray::class.asTypeName()),
;

override fun prepareStatementBinder(columnIndex: String, value: CodeBlock): CodeBlock {
return CodeBlock.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package app.cash.sqldelight.core.integration

enum class Shoots {
LEFT,
RIGHT;
RIGHT,
;

enum class Type {
ONE,
TWO
TWO,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,12 @@ class SqlDelightEnvironment(

for (sourceFolder in sourceFolders(file)) {
val path = file.parent!!.relativePathUnder(sourceFolder)
if (path != null) return path.joinToString(separator = ".") {
SqlDelightFileIndex.sanitizeDirectoryName(
it,
)
if (path != null) {
return path.joinToString(separator = ".") {
SqlDelightFileIndex.sanitizeDirectoryName(
it,
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,11 @@ class SelectQueryGenerator(
}

private fun NamedQuery.supertype() =
if (tablesObserved.isNullOrEmpty()) EXECUTABLE_QUERY_TYPE
else QUERY_TYPE
if (tablesObserved.isNullOrEmpty()) {
EXECUTABLE_QUERY_TYPE
} else {
QUERY_TYPE
}

/**
* The private query subtype for this specific query.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ data class NamedQuery(
* by the generated api.
*/
val resultColumns: List<IntermediateType> by lazy {
if (queryable is SelectQueryable) resultColumns(queryable.select)
else queryable.select.typesExposed(LinkedHashSet())
if (queryable is SelectQueryable) {
resultColumns(queryable.select)
} else {
queryable.select.typesExposed(LinkedHashSet())
}
}

private fun resultColumns(select: SqlCompoundSelectStmt): List<IntermediateType> {
Expand All @@ -86,8 +89,11 @@ data class NamedQuery(
* the types to be exposed by the generated api.
*/
internal val resultColumnRequiredAdapters: List<PropertySpec> by lazy {
if (queryable is SelectQueryable) resultColumnRequiredAdapters(queryable.select)
else queryable.select.typesExposed(LinkedHashSet()).mapNotNull { it.parentAdapter() }
if (queryable is SelectQueryable) {
resultColumnRequiredAdapters(queryable.select)
} else {
queryable.select.typesExposed(LinkedHashSet()).mapNotNull { it.parentAdapter() }
}
}

private fun resultColumnRequiredAdapters(select: SqlCompoundSelectStmt): List<PropertySpec> {
Expand All @@ -112,9 +118,9 @@ data class NamedQuery(
}
var packageName = queryable.select.sqFile().packageName!!
if (queryable.select.sqFile().parent?.files
?.filterIsInstance<SqlDelightQueriesFile>()?.flatMap { it.namedQueries }
?.filter { it.needsInterface() && it != this }
?.any { it.name == name } == true
?.filterIsInstance<SqlDelightQueriesFile>()?.flatMap { it.namedQueries }
?.filter { it.needsInterface() && it != this }
?.any { it.name == name } == true
) {
packageName = "$packageName.${queryable.select.sqFile().virtualFile!!.nameWithoutExtension.decapitalize()}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ internal abstract class ColumnTypeMixin(
val columnIndex = it.columnNameList.map { it.name }.indexOf(columnName.name)
if (columnIndex != -1) {
it.foreignKeyClause?.columnNameList?.get(columnIndex)
} else null
} else {
null
}
}?.singleOrNull()

val columnConstraint = columnConstraintList.mapNotNull {
Expand All @@ -100,9 +102,9 @@ internal abstract class ColumnTypeMixin(
)
}
if (columnConstraintList.none {
(it.node.findChildByType(SqlTypes.NOT) != null && it.node.findChildByType(SqlTypes.NULL) != null) ||
it.node.findChildByType(SqlTypes.PRIMARY) != null
}
(it.node.findChildByType(SqlTypes.NOT) != null && it.node.findChildByType(SqlTypes.NULL) != null) ||
it.node.findChildByType(SqlTypes.PRIMARY) != null
}
) {
type = type.asNullable()
}
Expand Down
Loading

0 comments on commit 3a62ba0

Please sign in to comment.