Skip to content

Commit 0c519e1

Browse files
committed
Improve multiline expression wrapping in .editorconfig
This commit disables ktlint's standard multiline expression wrapping rule in the `.editorconfig` file. This allows developers to keep some multiline assignments on the same line, improving code readability in certain cases.
1 parent 3c880c9 commit 0c519e1

File tree

9 files changed

+136
-128
lines changed

9 files changed

+136
-128
lines changed

Fruitties/.editorconfig

+31
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,34 @@
22
# Kotlin style typically requires functions to start with a lowercase letter.
33
# Composable functions should start with a capital letter.
44
ktlint_function_naming_ignore_when_annotated_with = Composable
5+
6+
# ktlint always puts a new line after a multi-line assignment, like this:
7+
# val colors =
8+
# if (darkTheme) {
9+
# darkColorScheme(
10+
# primary = Color(0xFFBB86FC),
11+
# secondary = Color(0xFF03DAC5),
12+
# tertiary = Color(0xFF3700B3),
13+
# )
14+
# } else {
15+
# lightColorScheme(
16+
# primary = Color(0xFF6200EE),
17+
# secondary = Color(0xFF03DAC5),
18+
# tertiary = Color(0xFF3700B3),
19+
# )
20+
# }
21+
# But we actually prefer to keep some multi-line assignments on the same line, like this:
22+
# val colors = if (darkTheme) {
23+
# darkColorScheme(
24+
# primary = Color(0xFFBB86FC),
25+
# secondary = Color(0xFF03DAC5),
26+
# tertiary = Color(0xFF3700B3),
27+
# )
28+
# } else {
29+
# lightColorScheme(
30+
# primary = Color(0xFF6200EE),
31+
# secondary = Color(0xFF03DAC5),
32+
# tertiary = Color(0xFF3700B3),
33+
# )
34+
# }
35+
ktlint_standard_multiline-expression-wrapping = disabled

Fruitties/androidApp/src/main/java/com/example/fruitties/android/MyApplicationTheme.kt

+23-27
Original file line numberDiff line numberDiff line change
@@ -35,35 +35,31 @@ fun MyApplicationTheme(
3535
darkTheme: Boolean = isSystemInDarkTheme(),
3636
content: @Composable () -> Unit,
3737
) {
38-
val colors =
39-
if (darkTheme) {
40-
darkColorScheme(
41-
primary = Color(0xFFBB86FC),
42-
secondary = Color(0xFF03DAC5),
43-
tertiary = Color(0xFF3700B3),
44-
)
45-
} else {
46-
lightColorScheme(
47-
primary = Color(0xFF6200EE),
48-
secondary = Color(0xFF03DAC5),
49-
tertiary = Color(0xFF3700B3),
50-
)
51-
}
52-
val typography =
53-
Typography(
54-
bodyMedium =
55-
TextStyle(
56-
fontFamily = FontFamily.Default,
57-
fontWeight = FontWeight.Normal,
58-
fontSize = 16.sp,
59-
),
38+
val colors = if (darkTheme) {
39+
darkColorScheme(
40+
primary = Color(0xFFBB86FC),
41+
secondary = Color(0xFF03DAC5),
42+
tertiary = Color(0xFF3700B3),
6043
)
61-
val shapes =
62-
Shapes(
63-
small = RoundedCornerShape(4.dp),
64-
medium = RoundedCornerShape(4.dp),
65-
large = RoundedCornerShape(0.dp),
44+
} else {
45+
lightColorScheme(
46+
primary = Color(0xFF6200EE),
47+
secondary = Color(0xFF03DAC5),
48+
tertiary = Color(0xFF3700B3),
6649
)
50+
}
51+
val typography = Typography(
52+
bodyMedium = TextStyle(
53+
fontFamily = FontFamily.Default,
54+
fontWeight = FontWeight.Normal,
55+
fontSize = 16.sp,
56+
),
57+
)
58+
val shapes = Shapes(
59+
small = RoundedCornerShape(4.dp),
60+
medium = RoundedCornerShape(4.dp),
61+
large = RoundedCornerShape(0.dp),
62+
)
6763

6864
MaterialTheme(
6965
colorScheme = colors,

Fruitties/androidApp/src/main/java/com/example/fruitties/android/ui/ListScreen.kt

+43-55
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,14 @@ fun ListScreen() {
7575
// Here we put the KMP-compatible AppContainer into the extras
7676
// so it can be passed to the ViewModel factory.
7777
val app = LocalContext.current.applicationContext as App
78-
val extras =
79-
remember(app) {
80-
val container = app.container
81-
MainViewModel.newCreationExtras(container)
82-
}
83-
val viewModel: MainViewModel =
84-
viewModel(
85-
factory = MainViewModel.Factory,
86-
extras = extras,
87-
)
78+
val extras = remember(app) {
79+
val container = app.container
80+
MainViewModel.newCreationExtras(container)
81+
}
82+
val viewModel: MainViewModel = viewModel(
83+
factory = MainViewModel.Factory,
84+
extras = extras,
85+
)
8886

8987
val uiState by viewModel.homeUiState.collectAsState()
9088
val cartState by viewModel.cartUiState.collectAsState()
@@ -95,29 +93,26 @@ fun ListScreen() {
9593
title = {
9694
Text(text = stringResource(R.string.frutties))
9795
},
98-
colors =
99-
TopAppBarColors(
100-
containerColor = MaterialTheme.colorScheme.primary,
101-
scrolledContainerColor = MaterialTheme.colorScheme.primary,
102-
navigationIconContentColor = MaterialTheme.colorScheme.onPrimary,
103-
titleContentColor = MaterialTheme.colorScheme.onPrimary,
104-
actionIconContentColor = MaterialTheme.colorScheme.onPrimary,
105-
),
96+
colors = TopAppBarColors(
97+
containerColor = MaterialTheme.colorScheme.primary,
98+
scrolledContainerColor = MaterialTheme.colorScheme.primary,
99+
navigationIconContentColor = MaterialTheme.colorScheme.onPrimary,
100+
titleContentColor = MaterialTheme.colorScheme.onPrimary,
101+
actionIconContentColor = MaterialTheme.colorScheme.onPrimary,
102+
),
106103
)
107104
},
108-
contentWindowInsets =
109-
WindowInsets.safeDrawing.only(
110-
// Do not include Bottom so scrolled content is drawn below system bars.
111-
// Include Horizontal because some devices have camera cutouts on the side.
112-
WindowInsetsSides.Top + WindowInsetsSides.Horizontal,
113-
),
105+
contentWindowInsets = WindowInsets.safeDrawing.only(
106+
// Do not include Bottom so scrolled content is drawn below system bars.
107+
// Include Horizontal because some devices have camera cutouts on the side.
108+
WindowInsetsSides.Top + WindowInsetsSides.Horizontal,
109+
),
114110
) { paddingValues ->
115111
Column(
116-
modifier =
117-
Modifier
118-
// Support edge-to-edge (required on Android 15)
119-
// https://developer.android.com/develop/ui/compose/layouts/insets#inset-size
120-
.padding(paddingValues),
112+
modifier = Modifier
113+
// Support edge-to-edge (required on Android 15)
114+
// https://developer.android.com/develop/ui/compose/layouts/insets#inset-size
115+
.padding(paddingValues),
121116
) {
122117
var expanded by remember { mutableStateOf(false) }
123118
Row(modifier = Modifier.padding(16.dp)) {
@@ -166,28 +161,24 @@ fun FruittieItem(
166161
modifier: Modifier = Modifier,
167162
) {
168163
Card(
169-
modifier =
170-
modifier
171-
.padding(horizontal = 16.dp, vertical = 8.dp)
172-
.clip(RoundedCornerShape(8.dp)),
164+
modifier = modifier
165+
.padding(horizontal = 16.dp, vertical = 8.dp)
166+
.clip(RoundedCornerShape(8.dp)),
173167
shape = RoundedCornerShape(8.dp),
174-
colors =
175-
CardDefaults.cardColors(
176-
containerColor = MaterialTheme.colorScheme.surface,
177-
),
178-
elevation =
179-
CardDefaults.cardElevation(
180-
defaultElevation = 8.dp,
181-
),
168+
colors = CardDefaults.cardColors(
169+
containerColor = MaterialTheme.colorScheme.surface,
170+
),
171+
elevation = CardDefaults.cardElevation(
172+
defaultElevation = 8.dp,
173+
),
182174
) {
183175
Row(
184176
modifier = Modifier.fillMaxWidth(),
185177
verticalAlignment = Alignment.CenterVertically,
186178
) {
187179
Column(
188-
modifier =
189-
Modifier
190-
.heightIn(min = 96.dp),
180+
modifier = Modifier
181+
.heightIn(min = 96.dp),
191182
verticalArrangement = Arrangement.Center,
192183
) {
193184
Text(
@@ -196,27 +187,24 @@ fun FruittieItem(
196187
style = MaterialTheme.typography.titleMedium,
197188
maxLines = 1,
198189
overflow = TextOverflow.Ellipsis,
199-
modifier =
200-
Modifier
201-
.padding(horizontal = 16.dp)
202-
.padding(top = 8.dp),
190+
modifier = Modifier
191+
.padding(horizontal = 16.dp)
192+
.padding(top = 8.dp),
203193
)
204194
Text(
205195
text = item.fullName,
206-
modifier =
207-
Modifier
208-
.padding(horizontal = 16.dp)
209-
.padding(bottom = 8.dp),
196+
modifier = Modifier
197+
.padding(horizontal = 16.dp)
198+
.padding(bottom = 8.dp),
210199
color = MaterialTheme.colorScheme.onSurface,
211200
maxLines = 2,
212201
overflow = TextOverflow.Ellipsis,
213202
)
214203
}
215204
Spacer(modifier = Modifier.weight(1f))
216205
Row(
217-
modifier =
218-
Modifier
219-
.padding(horizontal = 16.dp, vertical = 8.dp),
206+
modifier = Modifier
207+
.padding(horizontal = 16.dp, vertical = 8.dp),
220208
verticalAlignment = Alignment.CenterVertically,
221209
) {
222210
Button(onClick = { onAddToCart(item) }) {

Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/DataRepository.kt

+7-8
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,15 @@ class DataRepository(
3434
) {
3535
@OptIn(ExperimentalCoroutinesApi::class)
3636
val cartDetails: Flow<List<CartItemDetails>>
37-
get() =
38-
cartDataStore.cart.mapLatest {
39-
val ids = it.items.map { it.id }
40-
val fruitties = database.fruittieDao().loadMapped(ids)
41-
it.items.mapNotNull {
42-
fruitties[it.id]?.let { fruittie ->
43-
CartItemDetails(fruittie, it.count)
44-
}
37+
get() = cartDataStore.cart.mapLatest {
38+
val ids = it.items.map { it.id }
39+
val fruitties = database.fruittieDao().loadMapped(ids)
40+
it.items.mapNotNull {
41+
fruitties[it.id]?.let { fruittie ->
42+
CartItemDetails(fruittie, it.count)
4543
}
4644
}
45+
}
4746

4847
suspend fun addToCart(fruittie: Fruittie) {
4948
cartDataStore.add(fruittie)

Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/database/CartDataStore.kt

+9-11
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,15 @@ internal object CartJsonSerializer : OkioSerializer<Cart> {
5858
class CartDataStore(
5959
private val produceFilePath: () -> String,
6060
) {
61-
private val db =
62-
DataStoreFactory.create(
63-
storage =
64-
OkioStorage<Cart>(
65-
fileSystem = FileSystem.SYSTEM,
66-
serializer = CartJsonSerializer,
67-
producePath = {
68-
produceFilePath().toPath()
69-
},
70-
),
71-
)
61+
private val db = DataStoreFactory.create(
62+
storage = OkioStorage<Cart>(
63+
fileSystem = FileSystem.SYSTEM,
64+
serializer = CartJsonSerializer,
65+
producePath = {
66+
produceFilePath().toPath()
67+
},
68+
),
69+
)
7270
val cart: Flow<Cart>
7371
get() = db.data
7472

Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/di/Factory.kt

+5-6
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,11 @@ expect class Factory {
3535

3636
internal fun commonCreateApi(): FruittieApi =
3737
FruittieNetworkApi(
38-
client =
39-
HttpClient {
40-
install(ContentNegotiation) {
41-
json(json, contentType = ContentType.Any)
42-
}
43-
},
38+
client = HttpClient {
39+
install(ContentNegotiation) {
40+
json(json, contentType = ContentType.Any)
41+
}
42+
},
4443
apiUrl = "https://android.github.io/kotlin-multiplatform-samples/fruitties-api",
4544
)
4645

Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/viewmodel/MainViewModel.kt

+6-7
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,13 @@ class MainViewModel(
6464
companion object {
6565
val APP_CONTAINER_KEY = CreationExtras.Key<AppContainer>()
6666

67-
val Factory: ViewModelProvider.Factory =
68-
viewModelFactory {
69-
initializer {
70-
val appContainer = this[APP_CONTAINER_KEY] as AppContainer
71-
val repository = appContainer.dataRepository
72-
MainViewModel(repository = repository)
73-
}
67+
val Factory: ViewModelProvider.Factory = viewModelFactory {
68+
initializer {
69+
val appContainer = this[APP_CONTAINER_KEY] as AppContainer
70+
val repository = appContainer.dataRepository
71+
MainViewModel(repository = repository)
7472
}
73+
}
7574

7675
/**
7776
* Helper function to prepare CreationExtras.

Fruitties/shared/src/iosMain/kotlin/com/example/fruitties/di/Factory.native.kt

+7-8
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,13 @@ actual class Factory {
4747

4848
@OptIn(ExperimentalForeignApi::class)
4949
private fun fileDirectory(): String {
50-
val documentDirectory: NSURL? =
51-
NSFileManager.defaultManager.URLForDirectory(
52-
directory = NSDocumentDirectory,
53-
inDomain = NSUserDomainMask,
54-
appropriateForURL = null,
55-
create = false,
56-
error = null,
57-
)
50+
val documentDirectory: NSURL? = NSFileManager.defaultManager.URLForDirectory(
51+
directory = NSDocumentDirectory,
52+
inDomain = NSUserDomainMask,
53+
appropriateForURL = null,
54+
create = false,
55+
error = null,
56+
)
5857
return requireNotNull(documentDirectory).path!!
5958
}
6059

Fruitties/shared/src/iosMain/kotlin/com/example/fruitties/di/viewmodel/IOSViewModelOwner.kt

+5-6
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ class IOSViewModelOwner(
1717
override val viewModelStore: ViewModelStore = ViewModelStore()
1818

1919
// Create an instance of MainViewModel with the CreationExtras.
20-
val mainViewModel: MainViewModel =
21-
ViewModelProvider.create(
22-
owner = this as ViewModelStoreOwner,
23-
factory = MainViewModel.Factory,
24-
extras = MainViewModel.newCreationExtras(appContainer),
25-
)[MainViewModel::class]
20+
val mainViewModel: MainViewModel = ViewModelProvider.create(
21+
owner = this as ViewModelStoreOwner,
22+
factory = MainViewModel.Factory,
23+
extras = MainViewModel.newCreationExtras(appContainer),
24+
)[MainViewModel::class]
2625

2726
// To add more ViewModel types, add new properties for each ViewModel.
2827
// If we need to add a very large number of ViewModel types,

0 commit comments

Comments
 (0)