Skip to content

Fixes spotless checks for Jetcaster #1566

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Jetcaster/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# When authoring changes in .editorconfig, run ./gradlew spotlessApply --no-daemon
# Reference: https://github.com/diffplug/spotless/issues/1924
[*.{kt,kts}]
ktlint_code_style = android_studio
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true
max_line_length = 140 # ktlint official
ktlint_function_naming_ignore_when_annotated_with = Composable, Test
ktlint_standard_filename = disabled
ktlint_standard_package-name = disabled
ktlint_standard_property-naming = disabled
ktlint_standard_backing-property-naming = disabled
ktlint_standard_argument-list-wrapping = disabled
ktlint_standard_parameter-list-wrapping = disabled
ktlint_standard_double-colon-spacing = disabled
ktlint_standard_enum-entry-name-case = disabled
ktlint_standard_multiline-if-else = disabled
ktlint_standard_no-empty-first-line-in-method-block = disabled
ktlint_standard_package-name = disabled

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It seems ktlint_standard_package-name = disabled is duplicated. This line also appears on line 10. Could you please remove this redundant entry to keep the configuration clean?

ktlint_standard_trailing-comma = disabled
ktlint_standard_spacing-around-angle-brackets = disabled
ktlint_standard_spacing-between-declarations-with-annotations = disabled
ktlint_standard_spacing-between-declarations-with-comments = disabled
ktlint_standard_unary-op-spacing = disabled
ktlint_standard_function-expression-body = disabled
ktlint_standard_value-parameter-comment = disabled
37 changes: 5 additions & 32 deletions Jetcaster/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,45 +32,18 @@ apply("${project.rootDir}/buildscripts/toml-updater-config.gradle")
subprojects {
apply(plugin = "com.diffplug.spotless")
configure<com.diffplug.gradle.spotless.SpotlessExtension> {
ratchetFrom = "origin/main"
kotlin {
target("**/*.kt")
targetExclude("**/build/**/*.kt")
ktlint().editorConfigOverride(
mapOf(
"ktlint_code_style" to "android_studio",
"ij_kotlin_allow_trailing_comma" to true,
"ktlint_function_naming_ignore_when_annotated_with" to "Composable",
// These rules were introduced in ktlint 0.46.0 and should not be
// enabled without further discussion. They are disabled for now.
// See: https://github.com/pinterest/ktlint/releases/tag/0.46.0
"disabled_rules" to
"filename," +
"annotation,annotation-spacing," +
"argument-list-wrapping," +
"double-colon-spacing," +
"enum-entry-name-case," +
"multiline-if-else," +
"no-empty-first-line-in-method-block," +
"package-name," +
"trailing-comma," +
"spacing-around-angle-brackets," +
"spacing-between-declarations-with-annotations," +
"spacing-between-declarations-with-comments," +
"unary-op-spacing"
)
)
targetExclude("${layout.buildDirectory}/**/*.kt")
ktlint()
licenseHeaderFile(rootProject.file("spotless/copyright.kt"))
}
format("kts") {
target("**/*.kts")
targetExclude("**/build/**/*.kts")
// Look for the first line that doesn't have a block comment (assumed to be the license)
licenseHeaderFile(rootProject.file("spotless/copyright.kt"), "(^(?![\\/ ]\\*).*$)")
}
kotlinGradle {
target("*.gradle.kts")
targetExclude("${layout.buildDirectory}/**/*.kt")
ktlint()
// Look for the first line that doesn't have a block comment (assumed to be the license)
licenseHeaderFile(rootProject.file("spotless/copyright.kt"), "(^(?![\\/ ]\\*).*$)")
}
}
}
29 changes: 26 additions & 3 deletions Jetcaster/core/data-testing/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
/*
* Copyright 2025 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
}

android {
namespace = "com.example.jetcaster.core.data.testing"
compileSdk = libs.versions.compileSdk.get().toInt()
compileSdk =
libs.versions.compileSdk
.get()
.toInt()

defaultConfig {
minSdk = libs.versions.minSdk.get().toInt()
minSdk =
libs.versions.minSdk
.get()
.toInt()

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
Expand All @@ -19,7 +42,7 @@ android {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
"proguard-rules.pro",
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,14 @@ class TestCategoryStore : CategoryStore {
private val episodesFromPodcasts =
MutableStateFlow<Map<Long, List<EpisodeToPodcast>>>(emptyMap())

override fun categoriesSortedByPodcastCount(limit: Int): Flow<List<Category>> =
categoryFlow
override fun categoriesSortedByPodcastCount(limit: Int): Flow<List<Category>> = categoryFlow

override fun podcastsInCategorySortedByPodcastCount(
categoryId: Long,
limit: Int
): Flow<List<PodcastWithExtraInfo>> = podcastsInCategoryFlow.map {
it[categoryId]?.take(limit) ?: emptyList()
}
override fun podcastsInCategorySortedByPodcastCount(categoryId: Long, limit: Int): Flow<List<PodcastWithExtraInfo>> =
podcastsInCategoryFlow.map {
it[categoryId]?.take(limit) ?: emptyList()
}

override fun episodesFromPodcastsInCategory(
categoryId: Long,
limit: Int
): Flow<List<EpisodeToPodcast>> = episodesFromPodcasts.map {
override fun episodesFromPodcastsInCategory(categoryId: Long, limit: Int): Flow<List<EpisodeToPodcast>> = episodesFromPodcasts.map {
it[categoryId]?.take(limit) ?: emptyList()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,57 +29,47 @@ import kotlinx.coroutines.flow.update
class TestEpisodeStore : EpisodeStore {

private val episodesFlow = MutableStateFlow<List<Episode>>(listOf())
override fun episodeWithUri(episodeUri: String): Flow<Episode> =
episodesFlow.map { episodes ->
episodes.first { it.uri == episodeUri }
override fun episodeWithUri(episodeUri: String): Flow<Episode> = episodesFlow.map { episodes ->
episodes.first { it.uri == episodeUri }
}

override fun episodeAndPodcastWithUri(episodeUri: String): Flow<EpisodeToPodcast> = episodesFlow.map { episodes ->
val e = episodes.first {
it.uri == episodeUri
}
EpisodeToPodcast().apply {
episode = e
_podcasts = emptyList()
}
}

override fun episodeAndPodcastWithUri(episodeUri: String): Flow<EpisodeToPodcast> =
episodesFlow.map { episodes ->
val e = episodes.first {
it.uri == episodeUri
}
override fun episodesInPodcast(podcastUri: String, limit: Int): Flow<List<EpisodeToPodcast>> = episodesFlow.map { episodes ->
episodes.filter {
it.podcastUri == podcastUri
}.map { e ->
EpisodeToPodcast().apply {
episode = e
_podcasts = emptyList()
}
}
}

override fun episodesInPodcast(podcastUri: String, limit: Int): Flow<List<EpisodeToPodcast>> =
episodesFlow.map { episodes ->
episodes.filter {
it.podcastUri == podcastUri
}.map { e ->
EpisodeToPodcast().apply {
episode = e
}
}
}

override fun episodesInPodcasts(
podcastUris: List<String>,
limit: Int
): Flow<List<EpisodeToPodcast>> =
episodesFlow.map { episodes ->
episodes.filter {
podcastUris.contains(it.podcastUri)
}.map { ep ->
EpisodeToPodcast().apply {
episode = ep
}
override fun episodesInPodcasts(podcastUris: List<String>, limit: Int): Flow<List<EpisodeToPodcast>> = episodesFlow.map { episodes ->
episodes.filter {
podcastUris.contains(it.podcastUri)
}.map { ep ->
EpisodeToPodcast().apply {
episode = ep
}
}
}

override suspend fun addEpisodes(episodes: Collection<Episode>) =
episodesFlow.update {
it + episodes
}
override suspend fun addEpisodes(episodes: Collection<Episode>) = episodesFlow.update {
it + episodes
}

override suspend fun deleteEpisode(episode: Episode) =
episodesFlow.update {
it - episode
}
override suspend fun deleteEpisode(episode: Episode) = episodesFlow.update {
it - episode
}

override suspend fun isEmpty(): Boolean =
episodesFlow.first().isEmpty()
override suspend fun isEmpty(): Boolean = episodesFlow.first().isEmpty()
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,71 +31,62 @@ class TestPodcastStore : PodcastStore {

private val podcastFlow = MutableStateFlow<List<Podcast>>(listOf())
private val followedPodcasts = mutableSetOf<String>()
override fun podcastWithUri(uri: String): Flow<Podcast> =
podcastFlow.map { podcasts ->
podcasts.first { it.uri == uri }
}
override fun podcastWithUri(uri: String): Flow<Podcast> = podcastFlow.map { podcasts ->
podcasts.first { it.uri == uri }
}

override fun podcastWithExtraInfo(podcastUri: String): Flow<PodcastWithExtraInfo> =
podcastFlow.map { podcasts ->
val podcast = podcasts.first { it.uri == podcastUri }
PodcastWithExtraInfo().apply {
this.podcast = podcast
}
override fun podcastWithExtraInfo(podcastUri: String): Flow<PodcastWithExtraInfo> = podcastFlow.map { podcasts ->
val podcast = podcasts.first { it.uri == podcastUri }
PodcastWithExtraInfo().apply {
this.podcast = podcast
}
}

override fun podcastsSortedByLastEpisode(limit: Int): Flow<List<PodcastWithExtraInfo>> =
podcastFlow.map { podcasts ->
podcasts.map { p ->
PodcastWithExtraInfo().apply {
podcast = p
isFollowed = followedPodcasts.contains(p.uri)
}
override fun podcastsSortedByLastEpisode(limit: Int): Flow<List<PodcastWithExtraInfo>> = podcastFlow.map { podcasts ->
podcasts.map { p ->
PodcastWithExtraInfo().apply {
podcast = p
isFollowed = followedPodcasts.contains(p.uri)
}
}
}

override fun followedPodcastsSortedByLastEpisode(limit: Int): Flow<List<PodcastWithExtraInfo>> =
podcastFlow.map { podcasts ->
podcasts.filter {
followedPodcasts.contains(it.uri)
}.map { p ->
PodcastWithExtraInfo().apply {
podcast = p
isFollowed = true
}
override fun followedPodcastsSortedByLastEpisode(limit: Int): Flow<List<PodcastWithExtraInfo>> = podcastFlow.map { podcasts ->
podcasts.filter {
followedPodcasts.contains(it.uri)
}.map { p ->
PodcastWithExtraInfo().apply {
podcast = p
isFollowed = true
}
}
}

override fun searchPodcastByTitle(
keyword: String,
limit: Int
): Flow<List<PodcastWithExtraInfo>> =
podcastFlow.map { podcastList ->
podcastList.filter {
it.title.contains(keyword)
}.map { p ->
PodcastWithExtraInfo().apply {
podcast = p
isFollowed = true
}
override fun searchPodcastByTitle(keyword: String, limit: Int): Flow<List<PodcastWithExtraInfo>> = podcastFlow.map { podcastList ->
podcastList.filter {
it.title.contains(keyword)
}.map { p ->
PodcastWithExtraInfo().apply {
podcast = p
isFollowed = true
}
}
}

override fun searchPodcastByTitleAndCategories(
keyword: String,
categories: List<Category>,
limit: Int
): Flow<List<PodcastWithExtraInfo>> =
podcastFlow.map { podcastList ->
podcastList.filter {
it.title.contains(keyword)
}.map { p ->
PodcastWithExtraInfo().apply {
podcast = p
isFollowed = true
}
limit: Int,
): Flow<List<PodcastWithExtraInfo>> = podcastFlow.map { podcastList ->
podcastList.filter {
it.title.contains(keyword)
}.map { p ->
PodcastWithExtraInfo().apply {
podcast = p
isFollowed = true
}
}
}

override suspend fun togglePodcastFollowed(podcastUri: String) {
if (podcastUri in followedPodcasts) {
Expand All @@ -113,9 +104,7 @@ class TestPodcastStore : PodcastStore {
followedPodcasts.remove(podcastUri)
}

override suspend fun addPodcast(podcast: Podcast) =
podcastFlow.update { it + podcast }
override suspend fun addPodcast(podcast: Podcast) = podcastFlow.update { it + podcast }

override suspend fun isEmpty(): Boolean =
podcastFlow.first().isEmpty()
override suspend fun isEmpty(): Boolean = podcastFlow.first().isEmpty()
}
Loading
Loading