Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Spotless and Ktlint and remove code convention violations #1094

Merged
merged 9 commits into from
Dec 21, 2023
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
[*.{kt,kts}]
ij_kotlin_allow_trailing_comma=true
ij_kotlin_allow_trailing_comma_on_call_site=true
ktlint_function_naming_ignore_when_annotated_with=Composable, Test
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class MainActivity : ComponentActivity() {
To see quick turnaround of the ProfileVerifier, we recommend using `speed-profile`.
If you don't do either of these steps, you might only see the profile status reported as
"enqueued for compilation" when running the sample locally.
*/
*/
withContext(Dispatchers.IO) {
val status = ProfileVerifier.getCompilationStatusAsync().await()
Log.d(TAG, "ProfileInstaller status code: ${status.profileInstallResultCode}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.compose.NavHost
import com.google.samples.apps.nowinandroid.feature.bookmarks.navigation.bookmarksScreen
import com.google.samples.apps.nowinandroid.feature.foryou.navigation.forYouNavigationRoute
import com.google.samples.apps.nowinandroid.feature.foryou.navigation.FOR_YOU_ROUTE
import com.google.samples.apps.nowinandroid.feature.foryou.navigation.forYouScreen
import com.google.samples.apps.nowinandroid.feature.interests.navigation.interestsGraph
import com.google.samples.apps.nowinandroid.feature.search.navigation.searchScreen
Expand All @@ -41,7 +41,7 @@ fun NiaNavHost(
appState: NiaAppState,
onShowSnackbar: suspend (String, String?) -> Boolean,
modifier: Modifier = Modifier,
startDestination: String = forYouNavigationRoute,
startDestination: String = FOR_YOU_ROUTE,
) {
val navController = appState.navController
NavHost(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ import androidx.tracing.trace
import com.google.samples.apps.nowinandroid.core.data.repository.UserNewsResourceRepository
import com.google.samples.apps.nowinandroid.core.data.util.NetworkMonitor
import com.google.samples.apps.nowinandroid.core.ui.TrackDisposableJank
import com.google.samples.apps.nowinandroid.feature.bookmarks.navigation.bookmarksRoute
import com.google.samples.apps.nowinandroid.feature.bookmarks.navigation.BOOKMARKS_ROUTE
import com.google.samples.apps.nowinandroid.feature.bookmarks.navigation.navigateToBookmarks
import com.google.samples.apps.nowinandroid.feature.foryou.navigation.forYouNavigationRoute
import com.google.samples.apps.nowinandroid.feature.foryou.navigation.FOR_YOU_ROUTE
import com.google.samples.apps.nowinandroid.feature.foryou.navigation.navigateToForYou
import com.google.samples.apps.nowinandroid.feature.interests.navigation.interestsRoute
import com.google.samples.apps.nowinandroid.feature.interests.navigation.INTERESTS_ROUTE
import com.google.samples.apps.nowinandroid.feature.interests.navigation.navigateToInterestsGraph
import com.google.samples.apps.nowinandroid.feature.search.navigation.navigateToSearch
import com.google.samples.apps.nowinandroid.navigation.TopLevelDestination
Expand Down Expand Up @@ -91,9 +91,9 @@ class NiaAppState(

val currentTopLevelDestination: TopLevelDestination?
@Composable get() = when (currentDestination?.route) {
forYouNavigationRoute -> FOR_YOU
bookmarksRoute -> BOOKMARKS
interestsRoute -> INTERESTS
FOR_YOU_ROUTE -> FOR_YOU
BOOKMARKS_ROUTE -> BOOKMARKS
INTERESTS_ROUTE -> INTERESTS
else -> null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ class StartupBenchmark {
packageName = PACKAGE_NAME,
metrics = listOf(StartupTimingMetric()),
compilationMode = compilationMode,
iterations = 20, // More iterations result in higher statistical significance.
// More iterations result in higher statistical significance.
dturner marked this conversation as resolved.
Show resolved Hide resolved
iterations = 20,
startupMode = COLD,
setupBlock = {
pressHome()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ abstract class AnalyticsModule {
companion object {
@Provides
@Singleton
fun provideFirebaseAnalytics(): FirebaseAnalytics { return Firebase.analytics }
fun provideFirebaseAnalytics(): FirebaseAnalytics {
return Firebase.analytics
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fun NiaOutlinedButton(
MaterialTheme.colorScheme.outline
} else {
MaterialTheme.colorScheme.onSurface.copy(
alpha = NiaButtonDefaults.DisabledOutlinedButtonBorderAlpha,
alpha = NiaButtonDefaults.DISABLED_OUTLINED_BUTTON_BORDER_ALPHA,
)
},
),
Expand Down Expand Up @@ -278,7 +278,7 @@ fun NiaButtonPreview() {
@ThemePreviews
@Composable
fun NiaOutlinedButtonPreview() {
NiaTheme() {
NiaTheme {
NiaBackground(modifier = Modifier.size(150.dp, 50.dp)) {
NiaOutlinedButton(onClick = {}, text = { Text("Test button") })
}
Expand Down Expand Up @@ -315,7 +315,7 @@ fun NiaButtonLeadingIconPreview() {
object NiaButtonDefaults {
// TODO: File bug
// OutlinedButton border color doesn't respect disabled state by default
const val DisabledOutlinedButtonBorderAlpha = 0.12f
const val DISABLED_OUTLINED_BUTTON_BORDER_ALPHA = 0.12f

// TODO: File bug
// OutlinedButton default border width isn't exposed via ButtonDefaults
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ fun NiaFilterChip(
borderColor = MaterialTheme.colorScheme.onBackground,
selectedBorderColor = MaterialTheme.colorScheme.onBackground,
disabledBorderColor = MaterialTheme.colorScheme.onBackground.copy(
alpha = NiaChipDefaults.DisabledChipContentAlpha,
alpha = NiaChipDefaults.DISABLED_CHIP_CONTENT_ALPHA,
),
disabledSelectedBorderColor = MaterialTheme.colorScheme.onBackground.copy(
alpha = NiaChipDefaults.DisabledChipContentAlpha,
alpha = NiaChipDefaults.DISABLED_CHIP_CONTENT_ALPHA,
),
selectedBorderWidth = NiaChipDefaults.ChipBorderWidth,
),
Expand All @@ -88,16 +88,16 @@ fun NiaFilterChip(
iconColor = MaterialTheme.colorScheme.onBackground,
disabledContainerColor = if (selected) {
MaterialTheme.colorScheme.onBackground.copy(
alpha = NiaChipDefaults.DisabledChipContainerAlpha,
alpha = NiaChipDefaults.DISABLED_CHIP_CONTAINER_ALPHA,
)
} else {
Color.Transparent
},
disabledLabelColor = MaterialTheme.colorScheme.onBackground.copy(
alpha = NiaChipDefaults.DisabledChipContentAlpha,
alpha = NiaChipDefaults.DISABLED_CHIP_CONTENT_ALPHA,
),
disabledLeadingIconColor = MaterialTheme.colorScheme.onBackground.copy(
alpha = NiaChipDefaults.DisabledChipContentAlpha,
alpha = NiaChipDefaults.DISABLED_CHIP_CONTENT_ALPHA,
),
selectedContainerColor = MaterialTheme.colorScheme.primaryContainer,
selectedLabelColor = MaterialTheme.colorScheme.onBackground,
Expand All @@ -124,7 +124,7 @@ fun ChipPreview() {
object NiaChipDefaults {
// TODO: File bug
// FilterChip default values aren't exposed via FilterChipDefaults
const val DisabledChipContainerAlpha = 0.12f
const val DisabledChipContentAlpha = 0.38f
const val DISABLED_CHIP_CONTAINER_ALPHA = 0.12f
const val DISABLED_CHIP_CONTENT_ALPHA = 0.38f
val ChipBorderWidth = 1.dp
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fun NiaIconToggleButton(
checkedContentColor = MaterialTheme.colorScheme.onPrimaryContainer,
disabledContainerColor = if (checked) {
MaterialTheme.colorScheme.onBackground.copy(
alpha = NiaIconButtonDefaults.DisabledIconButtonContainerAlpha,
alpha = NiaIconButtonDefaults.DISABLED_ICON_BUTTON_CONTAINER_ALPHA,
)
} else {
Color.Transparent
Expand Down Expand Up @@ -123,5 +123,5 @@ fun IconButtonPreviewUnchecked() {
object NiaIconButtonDefaults {
// TODO: File bug
// IconToggleButton disabled container alpha not exposed by IconButtonDefaults
const val DisabledIconButtonContainerAlpha = 0.12f
const val DISABLED_ICON_BUTTON_CONTAINER_ALPHA = 0.12f
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fun NiaTopicTag(
MaterialTheme.colorScheme.primaryContainer
} else {
MaterialTheme.colorScheme.surfaceVariant.copy(
alpha = NiaTagDefaults.UnfollowedTopicTagContainerAlpha,
alpha = NiaTagDefaults.UNFOLLOWED_TOPIC_TAG_CONTAINER_ALPHA,
)
}
TextButton(
Expand All @@ -50,7 +50,7 @@ fun NiaTopicTag(
containerColor = containerColor,
contentColor = contentColorFor(backgroundColor = containerColor),
disabledContainerColor = MaterialTheme.colorScheme.onSurface.copy(
alpha = NiaTagDefaults.DisabledTopicTagContainerAlpha,
alpha = NiaTagDefaults.DISABLED_TOPIC_TAG_CONTAINER_ALPHA,
),
),
) {
Expand All @@ -75,9 +75,9 @@ fun TagPreview() {
* Now in Android tag default values.
*/
object NiaTagDefaults {
const val UnfollowedTopicTagContainerAlpha = 0.5f
const val UNFOLLOWED_TOPIC_TAG_CONTAINER_ALPHA = 0.5f

// TODO: File bug
// Button disabled container alpha value not exposed by ButtonDefaults
const val DisabledTopicTagContainerAlpha = 0.12f
const val DISABLED_TOPIC_TAG_CONTAINER_ALPHA = 0.12f
}
Original file line number Diff line number Diff line change
Expand Up @@ -251,5 +251,7 @@ private fun scrollbarThumbColor(
}

private enum class ThumbState {
Active, Inactive, Dormant
Active,
Inactive,
Dormant,
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class LoadingWheelScreenshotTests() {
fun loadingWheelAnimation() {
composeTestRule.mainClock.autoAdvance = false
composeTestRule.setContent {
NiaTheme() {
NiaTheme {
NiaLoadingWheel(contentDesc = "")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@
package com.google.samples.apps.nowinandroid.core.model.data

enum class DarkThemeConfig {
FOLLOW_SYSTEM, LIGHT, DARK
FOLLOW_SYSTEM,
LIGHT,
DARK,
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ package com.google.samples.apps.nowinandroid.core.model.data
/**
* A [topic] with the additional information for whether or not it is followed.
*/
data class FollowableTopic( // TODO consider changing to UserTopic and flattening
// TODO consider changing to UserTopic and flattening
data class FollowableTopic(
val topic: Topic,
val isFollowed: Boolean,
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
package com.google.samples.apps.nowinandroid.core.model.data

enum class ThemeBrand {
DEFAULT, ANDROID
DEFAULT,
ANDROID,
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ class FakeNiaNetworkDataSourceTest {
)
}

@Suppress("ktlint:standard:max-line-length")
@Test
fun testDeserializationOfTopics() = runTest(testDispatcher) {
assertEquals(
/* ktlint-disable max-line-length */
NetworkTopic(
id = "1",
name = "Headlines",
Expand All @@ -56,15 +56,14 @@ class FakeNiaNetworkDataSourceTest {
url = "",
imageUrl = "https://firebasestorage.googleapis.com/v0/b/now-in-android.appspot.com/o/img%2Fic_topic_Headlines.svg?alt=media&token=506faab0-617a-4668-9e63-4a2fb996603f",
),
/* ktlint-enable max-line-length */
subject.getTopics().first(),
)
}

@Suppress("ktlint:standard:max-line-length")
@Test
fun testDeserializationOfNewsResources() = runTest(testDispatcher) {
assertEquals(
/* ktlint-disable max-line-length */
NetworkNewsResource(
id = "125",
title = "Android Basics with Compose",
Expand All @@ -83,7 +82,6 @@ class FakeNiaNetworkDataSourceTest {
type = "Codelab",
topics = listOf("2", "3", "10"),
),
/* ktlint-enable max-line-length */
subject.getNewsResources().find { it.id == "125" },
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* limitations under the License.
*/

@file:Suppress("ktlint:standard:max-line-length")

package com.google.samples.apps.nowinandroid.core.testing.data

import com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic
import com.google.samples.apps.nowinandroid.core.model.data.Topic

/* ktlint-disable max-line-length */
val followableTopicTestData: List<FollowableTopic> = listOf(
FollowableTopic(
topic = Topic(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* limitations under the License.
*/

@file:Suppress("ktlint:standard:max-line-length")

package com.google.samples.apps.nowinandroid.core.testing.data

import com.google.samples.apps.nowinandroid.core.model.data.NewsResource
import kotlinx.datetime.Instant

/* ktlint-disable max-line-length */
val newsResourcesTestData: List<NewsResource> = listOf(
NewsResource(
id = "1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
* limitations under the License.
*/

@file:Suppress("ktlint:standard:max-line-length")

package com.google.samples.apps.nowinandroid.core.testing.data

import com.google.samples.apps.nowinandroid.core.model.data.Topic

/* ktlint-disable max-line-length */
val topicsTestData: List<Topic> = listOf(
Topic(
id = "2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

@file:Suppress("ktlint:standard:max-line-length")

package com.google.samples.apps.nowinandroid.core.testing.data

import com.google.samples.apps.nowinandroid.core.model.data.DarkThemeConfig
Expand All @@ -26,7 +28,6 @@ import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toInstant

/* ktlint-disable max-line-length */
val userNewsResourcesTestData: List<UserNewsResource> = UserData(
bookmarkedNewsResources = setOf("1", "4"),
viewedNewsResources = setOf("1", "2", "4"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ import org.robolectric.RuntimeEnvironment

val DefaultRoborazziOptions =
RoborazziOptions(
compareOptions = CompareOptions(changeThreshold = 0f), // Pixel-perfect matching
recordOptions = RecordOptions(resizeScale = 0.5), // Reduce the size of the PNGs
// Pixel-perfect matching
compareOptions = CompareOptions(changeThreshold = 0f),
// Reduce the size of the PNGs
recordOptions = RecordOptions(resizeScale = 0.5),
)

enum class DefaultTestDevices(val description: String, val spec: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
* limitations under the License.
*/

@file:Suppress("ktlint:standard:max-line-length")

package com.google.samples.apps.nowinandroid.core.ui

import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic
import com.google.samples.apps.nowinandroid.core.model.data.Topic

/* ktlint-disable max-line-length */
/**
* This [PreviewParameterProvider](https://developer.android.com/reference/kotlin/androidx/compose/ui/tooling/preview/PreviewParameterProvider)
* provides list of [FollowableTopic] for Composable previews.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ fun NewsResourceHeaderImage(
painterResource(drawable.ic_placeholder_default)
},
// TODO b/226661685: Investigate using alt text of image to populate content description
contentDescription = null, // decorative image,
// decorative image,
contentDescription = null,
)
}
}
Expand Down Expand Up @@ -295,7 +296,8 @@ fun NewsResourceTopics(
modifier: Modifier = Modifier,
) {
Row(
modifier = modifier.horizontalScroll(rememberScrollState()), // causes narrow chips
// causes narrow chips
modifier = modifier.horizontalScroll(rememberScrollState()),
horizontalArrangement = Arrangement.spacedBy(4.dp),
) {
for (followableTopic in topics) {
Expand Down
Loading