Skip to content

Commit 3527d23

Browse files
authored
Switch ktlint for ktfmt (#727)
* Switch ktlint for ktfmt * Code blocks * Reformat
1 parent 83a443d commit 3527d23

File tree

67 files changed

+992
-926
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+992
-926
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_size = 2
5+
charset = utf-8
6+
trim_trailing_whitespace = true
7+
insert_final_newline = true
8+
9+
[*.{kt,kts}]
10+
ij_kotlin_allow_trailing_comma = true
11+
ij_kotlin_allow_trailing_comma_on_call_site = true
12+
ij_kotlin_imports_layout = *

build.gradle

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@ spotless {
1616
kotlin {
1717
target "**/*.kt"
1818
targetExclude "**/gen/**/*.*"
19-
ktlint('0.49.1').editorConfigOverride([
20-
"indent_size": "2",
21-
"disabled_rules": "package-name",
22-
"ij_kotlin_allow_trailing_comma": "true",
23-
"ij_kotlin_allow_trailing_comma_on_call_site": "true",
24-
])
19+
ktfmt(libs.ktfmt.get().version).googleStyle()
2520
trimTrailingWhitespace()
2621
endWithNewline()
2722
}

core/src/main/kotlin/com/alecstrong/sql/psi/core/ModifiableFileLazy.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ package com.alecstrong.sql.psi.core
33
import com.intellij.psi.PsiFile
44
import java.util.concurrent.atomic.AtomicReference
55

6-
class ModifiableFileLazy<out T>(
7-
private val initializer: () -> T,
8-
) {
6+
class ModifiableFileLazy<out T>(private val initializer: () -> T) {
97
private var modifiedStamp = -1L
108
private var state = AtomicReference<T>()
119

core/src/main/kotlin/com/alecstrong/sql/psi/core/ModuleParserUtil.kt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@ import com.intellij.lang.parser.GeneratedParserUtilBase
77

88
abstract class ModuleParserUtil : GeneratedParserUtilBase() {
99
companion object {
10-
@JvmStatic fun custom_module_argument(builder: PsiBuilder, level: Int, columnName: Parser): Boolean {
11-
if (!GeneratedParserUtilBase.recursion_guard_(builder, level, "module_argument_real")) return false
10+
@JvmStatic
11+
fun custom_module_argument(builder: PsiBuilder, level: Int, columnName: Parser): Boolean {
12+
if (!GeneratedParserUtilBase.recursion_guard_(builder, level, "module_argument_real"))
13+
return false
1214
var result: Boolean
13-
val marker = GeneratedParserUtilBase.enter_section_(
14-
builder,
15-
level,
16-
GeneratedParserUtilBase._COLLAPSE_,
17-
MODULE_ARGUMENT,
18-
"<module argument real>",
19-
)
15+
val marker =
16+
GeneratedParserUtilBase.enter_section_(
17+
builder,
18+
level,
19+
GeneratedParserUtilBase._COLLAPSE_,
20+
MODULE_ARGUMENT,
21+
"<module argument real>",
22+
)
2023
columnName.parse(builder, level + 1)
2124
var parens = 0
2225
while (builder.tokenType != SqlTypes.COMMA) {

core/src/main/kotlin/com/alecstrong/sql/psi/core/SqlAnnotator.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ open class SqlAnnotator : Annotator {
2222
}
2323
}
2424

25-
class AnnotationException(val msg: String, val element: PsiElement? = null) : IllegalStateException(msg)
25+
class AnnotationException(val msg: String, val element: PsiElement? = null) :
26+
IllegalStateException(msg)
2627

2728
fun interface SqlAnnotationHolder {
2829
fun createErrorAnnotation(element: PsiElement, message: String)

core/src/main/kotlin/com/alecstrong/sql/psi/core/SqlElementType.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class SqlElementType(name: String) : IElementType(name, null) {
3131
abstract class SqlSchemaContributorElementType<SchemaType : SchemaContributor>(
3232
private val name: String,
3333
/**
34-
* This should be the same class used when interfacing with [com.alecstrong.sql.psi.core.psi.Schema]
34+
* This should be the same class used when interfacing with
35+
* [com.alecstrong.sql.psi.core.psi.Schema]
3536
*/
3637
private val schemaClass: Class<SchemaType>,
3738
) : ILightStubElementType<SchemaContributorStub, SchemaContributor>(name, null) {

core/src/main/kotlin/com/alecstrong/sql/psi/core/SqlFileBase.kt

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,17 @@ import com.intellij.psi.search.GlobalSearchScope
1717
import com.intellij.psi.util.PsiTreeUtil
1818
import kotlin.reflect.KClass
1919

20-
abstract class SqlFileBase(
21-
viewProvider: FileViewProvider,
22-
language: Language,
23-
) : PsiFileBase(viewProvider, language) {
20+
abstract class SqlFileBase(viewProvider: FileViewProvider, language: Language) :
21+
PsiFileBase(viewProvider, language) {
2422
abstract val order: Long?
2523

2624
val sqlStmtList
2725
get() = findChildByClass(SqlStmtList::class.java)
2826

2927
fun tablesAvailable(child: PsiElement) = schema<TableElement>(child).map { it.tableExposed() }
3028

31-
fun triggers(sqlStmtElement: PsiElement?): Collection<SqlCreateTriggerStmt> = schema(sqlStmtElement)
29+
fun triggers(sqlStmtElement: PsiElement?): Collection<SqlCreateTriggerStmt> =
30+
schema(sqlStmtElement)
3231

3332
internal inline fun <reified T : SchemaContributor> schema(
3433
sqlStmtElement: PsiElement? = null,
@@ -62,29 +61,31 @@ abstract class SqlFileBase(
6261
}
6362

6463
/**
65-
* @return Tables this file exposes as LazyQuery.
66-
*
6764
* @param includeAll If true, also return tables that other files expose.
65+
* @return Tables this file exposes as LazyQuery.
6866
*/
6967
fun tables(includeAll: Boolean): Collection<LazyQuery> {
7068
val tables = schema<TableElement>().map { it.tableExposed() }
7169
return if (includeAll) tables else tables.filter { it.tableName.containingFile == this }
7270
}
7371

7472
internal fun viewForName(name: String): SqlCreateViewStmt? {
75-
return schema<TableElement>().filterIsInstance<SqlCreateViewStmt>().singleOrNull { it.name() == name }
73+
return schema<TableElement>().filterIsInstance<SqlCreateViewStmt>().singleOrNull {
74+
it.name() == name
75+
}
7676
}
7777

7878
private fun views(): List<SqlCreateViewStmt> {
79-
return sqlStmtList?.stmtList?.mapNotNull {
80-
it.createViewStmt
81-
}.orEmpty()
79+
return sqlStmtList?.stmtList?.mapNotNull { it.createViewStmt }.orEmpty()
8280
}
8381

8482
private fun tables(): List<TableElement> {
85-
return sqlStmtList?.stmtList?.mapNotNull {
86-
(it.createViewStmt as TableElement?) ?: it.createTableStmt ?: it.createVirtualTableStmt
87-
}.orEmpty()
83+
return sqlStmtList
84+
?.stmtList
85+
?.mapNotNull {
86+
(it.createViewStmt as TableElement?) ?: it.createTableStmt ?: it.createVirtualTableStmt
87+
}
88+
.orEmpty()
8889
}
8990

9091
private inline fun <T : SchemaContributor> iteratePreviousStatements(
@@ -127,17 +128,17 @@ abstract class SqlFileBase(
127128
topContributors.forEach(block)
128129
}
129130

130-
contributors()?.takeWhile { order == null || until == null || it.textOffset <= until.textOffset }
131-
?.forEach {
132-
block(it)
133-
}
131+
contributors()
132+
?.takeWhile { order == null || until == null || it.textOffset <= until.textOffset }
133+
?.forEach { block(it) }
134134
}
135135

136-
private fun contributors() = sqlStmtList?.stmtList?.mapNotNull { it.firstChild as? SchemaContributor }
136+
private fun contributors() =
137+
sqlStmtList?.stmtList?.mapNotNull { it.firstChild as? SchemaContributor }
137138

138139
/**
139-
* Optional files which can be used for extra Schema Contributors that are unindexed.
140-
* The files are added to the schema in the provided order.
140+
* Optional files which can be used for extra Schema Contributors that are unindexed. The files
141+
* are added to the schema in the provided order.
141142
*/
142143
protected open fun baseContributorFiles(): List<SqlFileBase> = emptyList()
143144

core/src/main/kotlin/com/alecstrong/sql/psi/core/SqlParserDefinition.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,20 @@ abstract class SqlParserDefinition : ParserDefinition {
2121
}
2222

2323
override fun createLexer(project: Project): Lexer = SqlLexerAdapter()
24+
2425
override fun getWhitespaceTokens() = WHITE_SPACES
26+
2527
override fun getCommentTokens() = COMMENTS
28+
2629
override fun getStringLiteralElements(): TokenSet = TokenSet.EMPTY
30+
2731
override fun spaceExistenceTypeBetweenTokens(p0: ASTNode, p1: ASTNode) = MAY
32+
2833
override fun createElement(node: ASTNode): PsiElement = SqlParserUtil.createElement(node)
2934

3035
override fun createParser(project: Project) = SqlParser()
3136

3237
abstract override fun createFile(viewProvider: FileViewProvider): SqlFileBase
38+
3339
abstract fun getLanguage(): Language
3440
}

core/src/main/kotlin/com/alecstrong/sql/psi/core/psi/AlterTableApplier.kt

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,30 @@ interface AlterTableApplier : PsiElement {
88
}
99

1010
val AlterTableApplier.alterStmt
11-
get() = PsiTreeUtil.getParentOfType(
12-
this,
13-
SqlAlterTableStmt::class.java,
14-
)!!
11+
get() = PsiTreeUtil.getParentOfType(this, SqlAlterTableStmt::class.java)!!
1512

1613
internal fun LazyQuery.withAlterStatement(
1714
alter: SqlAlterTableStmt,
1815
until: SqlAlterTableRules? = null,
1916
): LazyQuery {
20-
return alter.alterTableRulesList.takeWhile { it != until }.fold(
21-
this,
22-
{ lazyQuery, alterTableRules ->
23-
// Rename table.
24-
alterTableRules.alterTableRenameTable?.let { renameTable ->
25-
return@fold LazyQuery(
26-
tableName = renameTable.newTableName,
27-
query = {
28-
lazyQuery.query.copy(table = renameTable.newTableName)
29-
},
30-
)
31-
}
17+
return alter.alterTableRulesList
18+
.takeWhile { it != until }
19+
.fold(
20+
this,
21+
{ lazyQuery, alterTableRules ->
22+
// Rename table.
23+
alterTableRules.alterTableRenameTable?.let { renameTable ->
24+
return@fold LazyQuery(
25+
tableName = renameTable.newTableName,
26+
query = { lazyQuery.query.copy(table = renameTable.newTableName) },
27+
)
28+
}
3229

33-
(alterTableRules.firstChild as? AlterTableApplier)?.let {
34-
return@fold it.applyTo(lazyQuery)
35-
}
30+
(alterTableRules.firstChild as? AlterTableApplier)?.let {
31+
return@fold it.applyTo(lazyQuery)
32+
}
3633

37-
return@fold lazyQuery
38-
},
39-
)
34+
return@fold lazyQuery
35+
},
36+
)
4037
}

core/src/main/kotlin/com/alecstrong/sql/psi/core/psi/QueryElement.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,21 @@ interface QueryElement : PsiElement {
88
/**
99
* Return all of the results that this query exposes. The select_stmt rule
1010
*
11-
* SELECT *
12-
* FROM a_table;
11+
* ```
12+
* SELECT *
13+
* FROM a_table;
14+
* ```
1315
*
14-
* Would expose [QueryResults(a_table, [all of a_tables columns])]
16+
* Would expose `[QueryResults(a_table, [all of a_tables columns])]`
1517
*
1618
* The join_clause rule
1719
*
18-
* a_table JOIN a_second_table
20+
* ```
21+
* a_table JOIN a_second_table
22+
* ```
1923
*
20-
* Would expose [QueryResult(a_table, [all of a_tables columns]), QueryResult(a_second_table, [all of a_second_tables columns])]
24+
* Would expose `[QueryResult(a_table, [all of a_tables columns]), QueryResult(a_second_table,
25+
* [all of a_second_tables columns])]`
2126
*/
2227
fun queryExposed(): Collection<QueryResult>
2328

@@ -51,8 +56,8 @@ interface QueryElement : PsiElement {
5156
)
5257

5358
/**
54-
* These aren't considered part of the exposed query (ie performing a SELECT * does not return
55-
* the column in the result set) but they can be explicitly referenced.
59+
* These aren't considered part of the exposed query (ie performing a SELECT * does not return the
60+
* column in the result set) but they can be explicitly referenced.
5661
*/
5762
data class SynthesizedColumn(
5863
val table: PsiElement,

0 commit comments

Comments
 (0)