Skip to content

Commit

Permalink
Update dependency com.pinterest.ktlint:ktlint-cli to v1.3.0 (sqldelig…
Browse files Browse the repository at this point in the history
…ht#5285)

* Update dependency com.pinterest.ktlint:ktlint-cli to v1.3.0

* Disable expression rule

* Reformat

* Reformat again

* Manual format

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Jake Wharton <jw@squareup.com>
  • Loading branch information
renovate[bot] and JakeWharton authored Jun 21, 2024
1 parent f8ea136 commit 6aa2924
Show file tree
Hide file tree
Showing 47 changed files with 130 additions and 68 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ spotless {
ktlint(libs.versions.ktlint.get()).editorConfigOverride([
"ktlint_standard_discouraged-comment-location": "disabled",
"ktlint_standard_package-name": "disabled",
// Making something an expression body should be a choice around readability.
'ktlint_standard_function-expression-body': 'disabled',
])
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import com.alecstrong.sql.psi.core.psi.QueryElement.QueryResult
import com.alecstrong.sql.psi.core.psi.impl.SqlResultColumnImpl
import com.intellij.lang.ASTNode

internal abstract class ResultColumnMixin(node: ASTNode) : SqlResultColumnImpl(node), HsqlResultColumn {
internal abstract class ResultColumnMixin(node: ASTNode) :
SqlResultColumnImpl(node),
HsqlResultColumn {
private val queryExposed = ModifiableFileLazy lazy@{
if (windowFunctionInvocation != null) {
var column = QueryElement.QueryColumn(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import com.alecstrong.sql.psi.core.psi.SqlColumnDef
import com.alecstrong.sql.psi.core.psi.impl.SqlColumnDefImpl
import com.intellij.lang.ASTNode

internal open class ColumnDefMixin(node: ASTNode) : SqlColumnDefImpl(node), SqlColumnDef {
internal open class ColumnDefMixin(node: ASTNode) :
SqlColumnDefImpl(node),
SqlColumnDef {

override fun hasDefaultValue(): Boolean {
return isSerial() || super.hasDefaultValue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import com.alecstrong.sql.psi.core.psi.SqlTableName
import com.intellij.lang.ASTNode
import com.intellij.psi.PsiElement

internal abstract class CopyMixin(node: ASTNode) : SqlCompositeElementImpl(node), PostgreSqlCopyStdin {
internal abstract class CopyMixin(node: ASTNode) :
SqlCompositeElementImpl(node),
PostgreSqlCopyStdin {
override fun queryAvailable(child: PsiElement): Collection<QueryResult> {
val tableName = child.parent.children.filterIsInstance<SqlTableName>().single()
return tableAvailable(child, tableName.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import com.intellij.psi.PsiElement
* brin = [autosummarize (on|off|true|false), pages_per_range (1-2147483647) ]
*/
internal abstract class CreateIndexMixin(node: ASTNode) :
SqlCreateIndexStmtImpl(node), PostgreSqlCreateIndexStmt {
SqlCreateIndexStmtImpl(node),
PostgreSqlCreateIndexStmt {

override fun annotate(annotationHolder: SqlAnnotationHolder) {
withStorageParameter?.let { wsp ->
wsp.storageParametersList.zip(wsp.storageParameterList).forEach {
sp ->
wsp.storageParametersList.zip(wsp.storageParameterList).forEach { sp ->
indexMethod?.let { im ->
when (im.text.lowercase()) {
"brin" -> when (sp.first.text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.util.PsiTreeUtil

internal abstract class DistinctOnExpressionMixin(node: ASTNode) :
SqlCompositeElementImpl(node), PostgreSqlDistinctOnExpr {
SqlCompositeElementImpl(node),
PostgreSqlDistinctOnExpr {

private val distinctOnColumns get() = children.filterIsInstance<SqlResultColumn>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import com.intellij.lang.ASTNode
import com.intellij.psi.util.PsiTreeUtil

internal abstract class ReturningClauseMixin(node: ASTNode) :
SqlCompositeElementImpl(node), PostgreSqlReturningClause, FromQuery {
SqlCompositeElementImpl(node),
PostgreSqlReturningClause,
FromQuery {

private val queryExposed = ModifiableFileLazy {
listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import com.intellij.psi.PsiElement

internal abstract class SqlDeleteStmtLimitedMixin(
node: ASTNode,
) : SqlDeleteStmtLimitedImpl(node), PostgreSqlDeleteStmtLimited {
) : SqlDeleteStmtLimitedImpl(node),
PostgreSqlDeleteStmtLimited {

override fun tablesAvailable(child: PsiElement): Collection<LazyQuery> {
val tablesAvailable = super.tablesAvailable(child)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import com.intellij.psi.PsiElement

internal abstract class SqlInsertStmtMixin(
node: ASTNode,
) : SqlInsertStmtImpl(node), PostgreSqlInsertStmt {
) : SqlInsertStmtImpl(node),
PostgreSqlInsertStmt {

override fun tablesAvailable(child: PsiElement): Collection<LazyQuery> {
val tablesAvailable = super.tablesAvailable(child)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ internal abstract class InsertStmtMixin(
insertOr != null && insertOr.elementType == SqlTypes.OR -> {
val type = insertOr.treeNext.elementType
check(
type == SqlTypes.ROLLBACK || type == SqlTypes.ABORT ||
type == SqlTypes.FAIL || type == SqlTypes.IGNORE,
type == SqlTypes.ROLLBACK ||
type == SqlTypes.ABORT ||
type == SqlTypes.FAIL ||
type == SqlTypes.IGNORE,
)
type
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import com.alecstrong.sql.psi.core.psi.QueryElement.QueryResult
import com.alecstrong.sql.psi.core.psi.impl.SqlResultColumnImpl
import com.intellij.lang.ASTNode

internal abstract class ResultColumnMixin(node: ASTNode) : SqlResultColumnImpl(node), SqliteResultColumn {
internal abstract class ResultColumnMixin(node: ASTNode) :
SqlResultColumnImpl(node),
SqliteResultColumn {
private val queryExposed = ModifiableFileLazy lazy@{
if (windowFunctionInvocation != null) {
var column = QueryElement.QueryColumn(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ internal abstract class InsertStmtMixin(
insertOr != null && insertOr.elementType == SqlTypes.OR -> {
val type = insertOr.treeNext.elementType
check(
type == SqlTypes.ROLLBACK || type == SqlTypes.ABORT ||
type == SqlTypes.FAIL || type == SqlTypes.IGNORE,
type == SqlTypes.ROLLBACK ||
type == SqlTypes.ABORT ||
type == SqlTypes.FAIL ||
type == SqlTypes.IGNORE,
)
type
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ class JsonModule : SqlDelightModule {
}
}

private class JsonTypeResolver(private val parentResolver: TypeResolver) :
TypeResolver by parentResolver {
private class JsonTypeResolver(private val parentResolver: TypeResolver) : TypeResolver by parentResolver {
override fun functionType(functionExpr: SqlFunctionExpr): IntermediateType? {
when (functionExpr.functionName.text) {
"json_array", "json", "json_insert", "json_replace", "json_set", "json_object", "json_patch",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import com.intellij.lang.ASTNode
import com.intellij.lang.PsiBuilder
import com.intellij.psi.PsiElement

internal abstract class TableOrSubqueryMixin(node: ASTNode?) : SqlTableOrSubqueryImpl(node), SqliteJsonTableOrSubquery {
internal abstract class TableOrSubqueryMixin(node: ASTNode?) :
SqlTableOrSubqueryImpl(node),
SqliteJsonTableOrSubquery {
private val queryExposed = ModifiableFileLazy lazy@{
if (jsonFunctionName != null) {
return@lazy listOf(
Expand All @@ -44,7 +46,10 @@ internal abstract class TableOrSubqueryMixin(node: ASTNode?) : SqlTableOrSubquer
}
}

internal abstract class JsonFunctionNameMixin(node: ASTNode) : SqlNamedElementImpl(node), SqlTableName, ExposableType {
internal abstract class JsonFunctionNameMixin(node: ASTNode) :
SqlNamedElementImpl(node),
SqlTableName,
ExposableType {
override fun getId(): PsiElement? = null
override fun getString(): PsiElement? = null
override val parseRule: (PsiBuilder, Int) -> Boolean = JsonParser::json_function_name_real
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ private class AndroidQuery(
private val database: SupportSQLiteDatabase,
override val argCount: Int,
private val windowSizeBytes: Long?,
) : SupportSQLiteQuery, AndroidStatement {
) : SupportSQLiteQuery,
AndroidStatement {
private val binds = MutableList<((SupportSQLiteProgram) -> Unit)?>(argCount) { null }

override fun bindBytes(index: Int, bytes: ByteArray?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ interface ConnectionManager {
}
}

abstract class JdbcDriver : SqlDriver, ConnectionManager {
abstract class JdbcDriver :
SqlDriver,
ConnectionManager {
override fun close() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ sealed class ConnectionWrapper : SqlDriver {
class NativeSqliteDriver(
private val databaseManager: DatabaseManager,
maxReaderConnections: Int = 1,
) : ConnectionWrapper(), SqlDriver {
) : ConnectionWrapper(),
SqlDriver {
constructor(
configuration: DatabaseConfiguration,
maxReaderConnections: Int = 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ internal class AsyncPublisherIterator<T : Any>(
}

class R2dbcCursor
internal constructor(private val results: AsyncPublisherIterator<List<Any?>>) : SqlCursor {
internal constructor(
private val results: AsyncPublisherIterator<List<Any?>>,
) : SqlCursor {
private lateinit var currentRow: List<Any?>

override fun next(): QueryResult.AsyncValue<Boolean> = QueryResult.AsyncValue {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class JdbcSqliteDriver constructor(
*/
url: String,
properties: Properties = Properties(),
) : JdbcDriver(), ConnectionManager by connectionManager(url, properties) {
) : JdbcDriver(),
ConnectionManager by connectionManager(url, properties) {
private val listeners = linkedMapOf<String, MutableSet<Query.Listener>>()

override fun addListener(vararg queryKeys: String, listener: Query.Listener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class BatchingListUpdateCallback(callback: ListUpdateCallback) : ListUpdateCallb
}

override fun onInserted(position: Int, count: Int) {
if (mLastEventType == TYPE_ADD && position >= mLastEventPosition &&
if (mLastEventType == TYPE_ADD &&
position >= mLastEventPosition &&
position <= mLastEventPosition + mLastEventCount
) {
mLastEventCount += count
Expand All @@ -81,7 +82,8 @@ class BatchingListUpdateCallback(callback: ListUpdateCallback) : ListUpdateCallb
}

override fun onRemoved(position: Int, count: Int) {
if (mLastEventType == TYPE_REMOVE && mLastEventPosition >= position &&
if (mLastEventType == TYPE_REMOVE &&
mLastEventPosition >= position &&
mLastEventPosition <= position + count
) {
mLastEventCount += count
Expand All @@ -103,7 +105,8 @@ class BatchingListUpdateCallback(callback: ListUpdateCallback) : ListUpdateCallb
if (mLastEventType == TYPE_CHANGE &&
!(
position > mLastEventPosition + mLastEventCount ||
position + count < mLastEventPosition || mLastEventPayload != payload
position + count < mLastEventPosition ||
mLastEventPayload != payload
)
) {
// take potential overlap into account
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ private class QueryOnSubscribe<T : Any>(
private class QueryListenerAndDisposable<T : Any>(
private val emitter: ObservableEmitter<Query<T>>,
private val query: Query<T>,
) : AtomicBoolean(), Query.Listener, Disposable {
) : AtomicBoolean(),
Query.Listener,
Disposable {
override fun queryResultsChanged() {
emitter.onNext(query)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ internal class RecordingObserver(val numberOfColumns: Int) : DisposableObserver<
override fun onNext(value: Query<*>) {
val allRows = value.execute { cursor ->
val data = mutableListOf<List<String?>>()
while (cursor.next().value)
while (cursor.next().value) {
data.add((0 until numberOfColumns).map(cursor::getString))
}
QueryResult.Value(data)
}.value
events.add(allRows)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ private class QueryOnSubscribe<T : Any>(
private class QueryListenerAndDisposable<T : Any>(
private val emitter: ObservableEmitter<Query<T>>,
private val query: Query<T>,
) : AtomicBoolean(), Query.Listener, Disposable {
) : AtomicBoolean(),
Query.Listener,
Disposable {
override fun queryResultsChanged() {
emitter.onNext(query)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ internal class RecordingObserver(val numberOfColumns: Int) : DisposableObserver<
override fun onNext(value: Query<*>) {
val allRows = value.execute { cursor ->
val data = mutableListOf<List<String?>>()
while (cursor.next().value)
while (cursor.next().value) {
data.add((0 until numberOfColumns).map(cursor::getString))
}
QueryResult.Value(data)
}.value
events.add(allRows)
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sqliter = "1.3.1"
sqljs = "1.8.0"
paging-mpp = "3.1.1-0.3.1"
paging3 = "3.1.1"
ktlint = "1.2.1"
ktlint = "1.3.0"
agp = "8.5.0"
compileSdk = "34"
minSdk = "21"
Expand Down
14 changes: 10 additions & 4 deletions runtime/src/commonMain/kotlin/app/cash/sqldelight/Transacter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ private class RollbackException(val value: Any? = null) : Throwable()

private class TransactionWrapper<R>(
val transaction: Transaction,
) : TransactionWithoutReturn, TransactionWithReturn<R> {
) : TransactionWithoutReturn,
TransactionWithReturn<R> {
override fun rollback(): Nothing {
transaction.checkThreadConfinement()
throw RollbackException()
Expand Down Expand Up @@ -226,7 +227,8 @@ private class TransactionWrapper<R>(

private class SuspendingTransactionWrapper<R>(
val transaction: Transaction,
) : SuspendingTransactionWithoutReturn, SuspendingTransactionWithReturn<R> {
) : SuspendingTransactionWithoutReturn,
SuspendingTransactionWithReturn<R> {
override fun rollback(): Nothing {
transaction.checkThreadConfinement()
throw RollbackException()
Expand Down Expand Up @@ -341,7 +343,9 @@ abstract class BaseTransacterImpl(protected val driver: SqlDriver) {
/**
* A transaction-aware [SqlDriver] wrapper which can begin a [Transaction] on the current connection.
*/
abstract class TransacterImpl(driver: SqlDriver) : BaseTransacterImpl(driver), Transacter {
abstract class TransacterImpl(driver: SqlDriver) :
BaseTransacterImpl(driver),
Transacter {
override fun transaction(
noEnclosing: Boolean,
body: TransactionWithoutReturn.() -> Unit,
Expand Down Expand Up @@ -378,7 +382,9 @@ abstract class TransacterImpl(driver: SqlDriver) : BaseTransacterImpl(driver), T
}
}

abstract class SuspendingTransacterImpl(driver: SqlDriver) : BaseTransacterImpl(driver), SuspendingTransacter {
abstract class SuspendingTransacterImpl(driver: SqlDriver) :
BaseTransacterImpl(driver),
SuspendingTransacter {
override suspend fun <R> transactionWithResult(
noEnclosing: Boolean,
bodyWithReturn: suspend SuspendingTransactionWithReturn<R>.() -> R,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package app.cash.sqldelight.db

class OptimisticLockException(message: String?, cause: Throwable? = null) :
IllegalStateException(message, cause)
class OptimisticLockException(message: String?, cause: Throwable? = null) : IllegalStateException(message, cause)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class PragmaWithResults(pragmaStmt: SqlPragmaStmt) : QueryWithResults {
override val pureTable: NamedElement? = null
}

class SqlDelightPragmaName(node: ASTNode?) : SqlPragmaNameImpl(node), QueryElement {
class SqlDelightPragmaName(node: ASTNode?) :
SqlPragmaNameImpl(node),
QueryElement {
override fun queryExposed() = listOf(
QueryResult(
column = this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import com.alecstrong.sql.psi.core.psi.SqlBindParameter
import com.alecstrong.sql.psi.core.psi.SqlCompositeElementImpl
import com.intellij.lang.ASTNode

abstract class BindParameterMixin(node: ASTNode) : SqlCompositeElementImpl(node), SqlBindParameter {
abstract class BindParameterMixin(node: ASTNode) :
SqlCompositeElementImpl(node),
SqlBindParameter {
/**
* Overwrite, if the user provided sql parameter should be overwritten by sqldelight with [replaceWith].
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ class MutatorQueryGenerator(
val columns = trigger.columnNameList.map { it.name }
val updateColumns = query.update.updateStmtSubsequentSetterList.map { it.columnName?.name } +
query.update.columnNameList.map { it.name }
trigger.childOfType(SqlTypes.UPDATE) != null && (
columns.isEmpty() ||
updateColumns.any { it in columns }
)
trigger.childOfType(SqlTypes.UPDATE) != null &&
(
columns.isEmpty() ||
updateColumns.any { it in columns }
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ data class NamedQuery(

if (typeOne.column !== typeTwo.column &&
typeOne.asNonNullable().cursorGetter(0) != typeTwo.asNonNullable().cursorGetter(0) &&
typeOne.column != null && typeTwo.column != null
typeOne.column != null &&
typeTwo.column != null
) {
// Incompatible adapters. Revert to unadapted java type.
return if (typeOne.javaType.copy(nullable = false) == typeTwo.javaType.copy(nullable = false)) {
Expand Down
Loading

0 comments on commit 6aa2924

Please sign in to comment.