Skip to content

Commit 9eac7b0

Browse files
Merge pull request #116 from touchlab/ks/UpdatingKtLint
Adding KtLint
2 parents 6ae0eb1 + fd41921 commit 9eac7b0

File tree

67 files changed

+358
-392
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

+358
-392
lines changed

.editorconfig

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# .editorconfig
2+
root = true
3+
4+
[*.{kt,kts}]
5+
end_of_line = lf
6+
ij_kotlin_packages_to_use_import_on_demand = true
7+
ij_kotlin_allow_trailing_comma = true
8+
ij_kotlin_allow_trailing_comma_on_call_site = true
9+
ij_kotlin_imports_layout = *
10+
ij_kotlin_indent_before_arrow_on_new_line = false
11+
ij_kotlin_line_break_after_multiline_when_entry = true
12+
indent_size = 4
13+
indent_style = space
14+
insert_final_newline = true
15+
ktlint_argument_list_wrapping_ignore_when_parameter_count_greater_or_equal_than = 8
16+
ktlint_chain_method_rule_force_multiline_when_chain_operator_count_greater_or_equal_than = 4
17+
ktlint_code_style = android_studio
18+
ktlint_enum_entry_name_casing = upper_or_camel_cases
19+
ktlint_function_naming_ignore_when_annotated_with = Composable
20+
ktlint_function_signature_body_expression_wrapping = default
21+
ktlint_ignore_back_ticked_identifier = false
22+
max_line_length = 140
23+
parameter-list-wrapping = true

.github/workflows/build.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
deploy:
11-
runs-on: macos-latest
11+
runs-on: macos-13
1212
steps:
1313
- name: Checkout the repo
1414
uses: actions/checkout@v3
@@ -20,15 +20,15 @@ jobs:
2020
- name: Validate Gradle Wrapper
2121
uses: gradle/wrapper-validation-action@v1
2222
- name: Cache gradle
23-
uses: actions/cache@v2
23+
uses: actions/cache@v4
2424
with:
2525
path: ~/.gradle/caches
2626
key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }}
2727
restore-keys: |
2828
${{ runner.os }}-gradle-
2929
3030
- name: Cache konan
31-
uses: actions/cache@v2
31+
uses: actions/cache@v4
3232
with:
3333
path: ~/.konan
3434
key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }}
@@ -47,7 +47,7 @@ jobs:
4747

4848
- name: Upload Stately Collections Build Results
4949
if: always()
50-
uses: actions/upload-artifact@v2
50+
uses: actions/upload-artifact@v4
5151
with:
5252
name: deprecated-test-results
5353
path: deprecated/**/build/reports/tests/

.github/workflows/deploy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ jobs:
1515
- name: Validate Gradle Wrapper
1616
uses: gradle/wrapper-validation-action@v1
1717
- name: Cache gradle
18-
uses: actions/cache@v2
18+
uses: actions/cache@v4
1919
with:
2020
path: ~/.gradle/caches
2121
key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }}
2222
restore-keys: |
2323
${{ runner.os }}-gradle-
2424
2525
- name: Cache konan
26-
uses: actions/cache@v2
26+
uses: actions/cache@v4
2727
with:
2828
path: ~/.konan
2929
key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }}

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ jobs:
2424
- name: Validate Gradle Wrapper
2525
uses: gradle/wrapper-validation-action@v1
2626
- name: Cache gradle
27-
uses: actions/cache@v2
27+
uses: actions/cache@v4
2828
with:
2929
path: ~/.gradle/caches
3030
key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }}
3131
restore-keys: |
3232
${{ runner.os }}-gradle-
3333
3434
- name: Cache konan
35-
uses: actions/cache@v2
35+
uses: actions/cache@v4
3636
with:
3737
path: ~/.konan
3838
key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }}

.idea/codeStyles/Project.xml

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle.kts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ plugins {
66
alias(libs.plugins.dokka) apply false
77
alias(libs.plugins.touchlab.docusaurusosstemplate)
88
alias(libs.plugins.mavenPublish) apply false
9+
alias(libs.plugins.ktlint) apply false
910
}
1011

1112
apiValidation {
@@ -26,4 +27,23 @@ val VERSION_NAME: String by project
2627
allprojects {
2728
group = GROUP
2829
version = VERSION_NAME
29-
}
30+
}
31+
32+
subprojects {
33+
apply(plugin = "org.jlleitschuh.gradle.ktlint")
34+
35+
configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
36+
version.set("1.4.0")
37+
enableExperimentalRules.set(true)
38+
verbose.set(true)
39+
filter {
40+
exclude { it.file.path.contains("build/") }
41+
}
42+
}
43+
44+
afterEvaluate {
45+
tasks.named("check") {
46+
dependsOn(tasks.getByName("ktlintCheck"))
47+
}
48+
}
49+
}

deprecated/stately-collections/src/commonMain/kotlin/co/touchlab/stately/collections/Functions.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ expect fun <T> frozenCopyOnWriteList(collection: Collection<T>? = null): Mutable
2727
message = "Replacing Atomic collections with isolated state collections (modele `stately-iso-collections`)",
2828
replaceWith = ReplaceWith(
2929
"sharedMutableListOf()",
30-
"co.touchlab.stately.collections.sharedMutableListOf"
31-
)
30+
"co.touchlab.stately.collections.sharedMutableListOf",
31+
),
3232
)
3333
fun <T> frozenLinkedList(stableIterator: Boolean = false): MutableList<T> = if (stableIterator) {
3434
CopyOnIterateLinkedList()
@@ -40,8 +40,8 @@ fun <T> frozenLinkedList(stableIterator: Boolean = false): MutableList<T> = if (
4040
message = "Replacing Atomic collections with isolated state collections (modele `stately-iso-collections`)",
4141
replaceWith = ReplaceWith(
4242
"sharedMutableMapOf()",
43-
"co.touchlab.stately.collections.sharedMutableMapOf"
44-
)
43+
"co.touchlab.stately.collections.sharedMutableMapOf",
44+
),
4545
)
4646
fun <K, V> frozenHashMap(initialCapacity: Int = 16, loadFactor: Float = 0.75.toFloat()): MutableMap<K, V> =
4747
SharedHashMap(initialCapacity, loadFactor)
@@ -50,8 +50,8 @@ fun <K, V> frozenHashMap(initialCapacity: Int = 16, loadFactor: Float = 0.75.toF
5050
message = "Replacing Atomic collections with isolated state collections (modele `stately-iso-collections`)",
5151
replaceWith = ReplaceWith(
5252
"sharedMutableSetOf()",
53-
"co.touchlab.stately.collections.sharedMutableSetOf"
54-
)
53+
"co.touchlab.stately.collections.sharedMutableSetOf",
54+
),
5555
)
5656
fun <T> frozenHashSet(): MutableSet<T> = SharedSet()
5757

deprecated/stately-collections/src/commonMain/kotlin/co/touchlab/stately/collections/ObjectPool.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ import co.touchlab.stately.concurrency.value
77
import co.touchlab.stately.concurrency.withLock
88
import co.touchlab.stately.freeze
99

10-
class ObjectPool<T>(
11-
private val maxSize: Int,
12-
private val createBlock: () -> T,
13-
private val cleanupBlock: ((t: T) -> Unit)? = null
14-
) {
10+
class ObjectPool<T>(private val maxSize: Int, private val createBlock: () -> T, private val cleanupBlock: ((t: T) -> Unit)? = null) {
1511
init {
1612
if (maxSize < 0) {
1713
throw IllegalArgumentException("maxSize cannot be negative")

deprecated/stately-collections/src/commonMain/kotlin/co/touchlab/stately/collections/SharedHashMap.kt

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ class SharedHashMap<K, V>(initialCapacity: Int = 16, val loadFactor: Float = 0.7
3535
override val value: V
3636
get() = v
3737

38-
override fun setValue(newValue: V): V {
39-
throw UnsupportedOperationException()
40-
}
38+
override fun setValue(newValue: V): V = throw UnsupportedOperationException()
4139
}
4240

4341
private var lock: Lock = Lock()
@@ -56,22 +54,21 @@ class SharedHashMap<K, V>(initialCapacity: Int = 16, val loadFactor: Float = 0.7
5654

5755
init {
5856
var capacity = 1
59-
while (capacity < initialCapacity)
57+
while (capacity < initialCapacity) {
6058
capacity = capacity shl 1
59+
}
6160

6261
threshold = AtomicInt((capacity.toFloat() * loadFactor).toInt())
6362
buckets = AtomicReference(makeBuckets(capacity))
6463

6564
freeze()
6665
}
6766

68-
private fun makeBuckets(capacity: Int): Array<AtomicReference<SharedLinkedList<Entry<K, V>>>> {
69-
return (
70-
Array(capacity) {
71-
AtomicReference(SharedLinkedList<Entry<K, V>>(1).freeze())
72-
}
73-
).freeze()
74-
}
67+
private fun makeBuckets(capacity: Int): Array<AtomicReference<SharedLinkedList<Entry<K, V>>>> = (
68+
Array(capacity) {
69+
AtomicReference(SharedLinkedList<Entry<K, V>>(1).freeze())
70+
}
71+
).freeze()
7572

7673
private inline fun iterInternal(proc: (Entry<K, V>) -> Unit) {
7774
buckets.value.forEach {
@@ -115,31 +112,19 @@ class SharedHashMap<K, V>(initialCapacity: Int = 16, val loadFactor: Float = 0.7
115112
}
116113

117114
private class NotReallyMutableSet<T>(private val delegate: MutableCollection<T>) : MutableSet<T> {
118-
override fun add(element: T): Boolean {
119-
throw UnsupportedOperationException()
120-
}
115+
override fun add(element: T): Boolean = throw UnsupportedOperationException()
121116

122-
override fun addAll(elements: Collection<T>): Boolean {
123-
throw UnsupportedOperationException()
124-
}
117+
override fun addAll(elements: Collection<T>): Boolean = throw UnsupportedOperationException()
125118

126-
override fun clear() {
127-
throw UnsupportedOperationException()
128-
}
119+
override fun clear(): Unit = throw UnsupportedOperationException()
129120

130121
override fun iterator(): MutableIterator<T> = delegate.iterator()
131122

132-
override fun remove(element: T): Boolean {
133-
throw UnsupportedOperationException()
134-
}
123+
override fun remove(element: T): Boolean = throw UnsupportedOperationException()
135124

136-
override fun removeAll(elements: Collection<T>): Boolean {
137-
throw UnsupportedOperationException()
138-
}
125+
override fun removeAll(elements: Collection<T>): Boolean = throw UnsupportedOperationException()
139126

140-
override fun retainAll(elements: Collection<T>): Boolean {
141-
throw UnsupportedOperationException()
142-
}
127+
override fun retainAll(elements: Collection<T>): Boolean = throw UnsupportedOperationException()
143128

144129
override val size: Int
145130
get() = delegate.size
@@ -201,10 +186,7 @@ class SharedHashMap<K, V>(initialCapacity: Int = 16, val loadFactor: Float = 0.7
201186
return result
202187
}
203188

204-
private fun internalRemoveByKey(
205-
entryList: SharedLinkedList<Entry<K, V>>,
206-
key: K
207-
): V? {
189+
private fun internalRemoveByKey(entryList: SharedLinkedList<Entry<K, V>>, key: K): V? {
208190
var result: AbstractSharedLinkedList.Node<Entry<K, V>>? = null
209191
val iter = entryList.nodeIterator()
210192
while (iter.hasNext()) {
@@ -250,7 +232,7 @@ class SharedHashMap<K, V>(initialCapacity: Int = 16, val loadFactor: Float = 0.7
250232

251233
private fun transfer(
252234
newTable: Array<AtomicReference<SharedLinkedList<Entry<K, V>>>>,
253-
oldTable: Array<AtomicReference<SharedLinkedList<Entry<K, V>>>>
235+
oldTable: Array<AtomicReference<SharedLinkedList<Entry<K, V>>>>,
254236
) {
255237
oldTable.forEach {
256238
it.value.iterator().forEach {
@@ -262,9 +244,7 @@ class SharedHashMap<K, V>(initialCapacity: Int = 16, val loadFactor: Float = 0.7
262244

263245
internal fun currentBucketSize(): Int = buckets.value.size
264246

265-
private fun indexFor(h: Int, length: Int): Int {
266-
return h and length - 1
267-
}
247+
private fun indexFor(h: Int, length: Int): Int = h and length - 1
268248

269249
internal fun rehash(initHash: Int): Int {
270250
var h = initHash
@@ -275,10 +255,7 @@ class SharedHashMap<K, V>(initialCapacity: Int = 16, val loadFactor: Float = 0.7
275255
return h xor h.ushr(7) xor h.ushr(4)
276256
}
277257

278-
private fun findEntryList(
279-
bucketArray: Array<AtomicReference<SharedLinkedList<Entry<K, V>>>>,
280-
key: K
281-
): SharedLinkedList<Entry<K, V>> {
258+
private fun findEntryList(bucketArray: Array<AtomicReference<SharedLinkedList<Entry<K, V>>>>, key: K): SharedLinkedList<Entry<K, V>> {
282259
val hash = rehash(key.hashCode())
283260
val entryList = bucketArray.get(indexFor(hash, bucketArray.size)).value
284261
return entryList

0 commit comments

Comments
 (0)