Skip to content

Commit 460cadf

Browse files
authored
Merge pull request #13081 from TeamNewPipe/ktlint
Fix and enable multiple ktlint rules
2 parents 675dbd3 + 2fd2822 commit 460cadf

File tree

83 files changed

+759
-473
lines changed

Some content is hidden

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

83 files changed

+759
-473
lines changed

.editorconfig

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,13 @@
66
root = true
77

88
[*.{kt,kts}]
9-
ktlint_standard_annotation = disabled
10-
ktlint_standard_argument-list-wrapping = disabled
11-
ktlint_standard_backing-property-naming = disabled
12-
ktlint_standard_blank-line-before-declaration = disabled
13-
ktlint_standard_blank-line-between-when-conditions = disabled
14-
ktlint_standard_chain-method-continuation = disabled
9+
ktlint_code_style = android_studio
10+
# https://pinterest.github.io/ktlint/latest/rules/standard/#function-naming
11+
ktlint_function_naming_ignore_when_annotated_with = Composable
12+
1513
ktlint_standard_class-signature = disabled
16-
ktlint_standard_comment-wrapping = disabled
17-
ktlint_standard_enum-wrapping = disabled
1814
ktlint_standard_function-expression-body = disabled
19-
ktlint_standard_function-literal = disabled
20-
ktlint_standard_function-signature = disabled
21-
ktlint_standard_indent = disabled
22-
ktlint_standard_kdoc = disabled
2315
ktlint_standard_max-line-length = disabled
2416
ktlint_standard_mixed-condition-operators = disabled
25-
ktlint_standard_multiline-expression-wrapping = disabled
26-
ktlint_standard_multiline-if-else = disabled
27-
ktlint_standard_no-blank-line-in-list = disabled
28-
ktlint_standard_no-consecutive-comments = disabled
29-
ktlint_standard_no-empty-first-line-in-class-body = disabled
30-
ktlint_standard_no-empty-first-line-in-method-block = disabled
31-
ktlint_standard_no-line-break-after-else = disabled
32-
ktlint_standard_no-semi = disabled
33-
ktlint_standard_no-single-line-block-comment = disabled
3417
ktlint_standard_package-name = disabled
35-
ktlint_standard_parameter-list-wrapping = disabled
3618
ktlint_standard_property-naming = disabled
37-
ktlint_standard_spacing-between-declarations-with-annotations = disabled
38-
ktlint_standard_spacing-between-declarations-with-comments = disabled
39-
ktlint_standard_statement-wrapping = disabled
40-
ktlint_standard_string-template-indent = disabled
41-
ktlint_standard_trailing-comma-on-call-site = disabled
42-
ktlint_standard_trailing-comma-on-declaration-site = disabled
43-
ktlint_standard_try-catch-finally-spacing = disabled
44-
ktlint_standard_when-entry-bracing = disabled

app/src/androidTest/java/org/schabi/newpipe/database/DatabaseMigrationTest.kt

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -176,28 +176,32 @@ class DatabaseMigrationTest {
176176

177177
databaseInV7.run {
178178
insert(
179-
"search_history", SQLiteDatabase.CONFLICT_FAIL,
179+
"search_history",
180+
SQLiteDatabase.CONFLICT_FAIL,
180181
ContentValues().apply {
181182
put("service_id", serviceId)
182183
put("search", defaultSearch1)
183184
}
184185
)
185186
insert(
186-
"search_history", SQLiteDatabase.CONFLICT_FAIL,
187+
"search_history",
188+
SQLiteDatabase.CONFLICT_FAIL,
187189
ContentValues().apply {
188190
put("service_id", serviceId)
189191
put("search", defaultSearch2)
190192
}
191193
)
192194
insert(
193-
"search_history", SQLiteDatabase.CONFLICT_FAIL,
195+
"search_history",
196+
SQLiteDatabase.CONFLICT_FAIL,
194197
ContentValues().apply {
195198
put("service_id", otherServiceId)
196199
put("search", defaultSearch1)
197200
}
198201
)
199202
insert(
200-
"search_history", SQLiteDatabase.CONFLICT_FAIL,
203+
"search_history",
204+
SQLiteDatabase.CONFLICT_FAIL,
201205
ContentValues().apply {
202206
put("service_id", otherServiceId)
203207
put("search", defaultSearch2)
@@ -207,13 +211,17 @@ class DatabaseMigrationTest {
207211
}
208212

209213
testHelper.runMigrationsAndValidate(
210-
AppDatabase.DATABASE_NAME, Migrations.DB_VER_8,
211-
true, Migrations.MIGRATION_7_8
214+
AppDatabase.DATABASE_NAME,
215+
Migrations.DB_VER_8,
216+
true,
217+
Migrations.MIGRATION_7_8
212218
)
213219

214220
testHelper.runMigrationsAndValidate(
215-
AppDatabase.DATABASE_NAME, Migrations.DB_VER_9,
216-
true, Migrations.MIGRATION_8_9
221+
AppDatabase.DATABASE_NAME,
222+
Migrations.DB_VER_9,
223+
true,
224+
Migrations.MIGRATION_8_9
217225
)
218226

219227
val migratedDatabaseV8 = getMigratedDatabase()
@@ -235,41 +243,47 @@ class DatabaseMigrationTest {
235243
val remoteUid2: Long
236244
databaseInV8.run {
237245
localUid1 = insert(
238-
"playlists", SQLiteDatabase.CONFLICT_FAIL,
246+
"playlists",
247+
SQLiteDatabase.CONFLICT_FAIL,
239248
ContentValues().apply {
240249
put("name", DEFAULT_NAME + "1")
241250
put("is_thumbnail_permanent", false)
242251
put("thumbnail_stream_id", -1)
243252
}
244253
)
245254
localUid2 = insert(
246-
"playlists", SQLiteDatabase.CONFLICT_FAIL,
255+
"playlists",
256+
SQLiteDatabase.CONFLICT_FAIL,
247257
ContentValues().apply {
248258
put("name", DEFAULT_NAME + "2")
249259
put("is_thumbnail_permanent", false)
250260
put("thumbnail_stream_id", -1)
251261
}
252262
)
253263
delete(
254-
"playlists", "uid = ?",
264+
"playlists",
265+
"uid = ?",
255266
Array(1) { localUid1 }
256267
)
257268
remoteUid1 = insert(
258-
"remote_playlists", SQLiteDatabase.CONFLICT_FAIL,
269+
"remote_playlists",
270+
SQLiteDatabase.CONFLICT_FAIL,
259271
ContentValues().apply {
260272
put("service_id", DEFAULT_SERVICE_ID)
261273
put("url", DEFAULT_URL)
262274
}
263275
)
264276
remoteUid2 = insert(
265-
"remote_playlists", SQLiteDatabase.CONFLICT_FAIL,
277+
"remote_playlists",
278+
SQLiteDatabase.CONFLICT_FAIL,
266279
ContentValues().apply {
267280
put("service_id", DEFAULT_SECOND_SERVICE_ID)
268281
put("url", DEFAULT_SECOND_URL)
269282
}
270283
)
271284
delete(
272-
"remote_playlists", "uid = ?",
285+
"remote_playlists",
286+
"uid = ?",
273287
Array(1) { remoteUid2 }
274288
)
275289
close()

app/src/androidTest/java/org/schabi/newpipe/database/FeedDAOTest.kt

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import android.content.Context
44
import androidx.room.Room
55
import androidx.test.core.app.ApplicationProvider
66
import io.reactivex.rxjava3.core.Single
7+
import java.io.IOException
8+
import java.time.OffsetDateTime
79
import org.junit.After
810
import org.junit.Assert.assertEquals
911
import org.junit.Assert.assertNotNull
@@ -20,8 +22,6 @@ import org.schabi.newpipe.database.subscription.SubscriptionEntity
2022
import org.schabi.newpipe.extractor.ServiceList
2123
import org.schabi.newpipe.extractor.channel.ChannelInfo
2224
import org.schabi.newpipe.extractor.stream.StreamType
23-
import java.io.IOException
24-
import java.time.OffsetDateTime
2525

2626
class FeedDAOTest {
2727
private lateinit var db: AppDatabase
@@ -40,14 +40,21 @@ class FeedDAOTest {
4040
private val stream7 = StreamEntity(7, serviceId, "https://youtube.com/watch?v=7", "stream 7", StreamType.VIDEO_STREAM, 1000, "channel-4", "https://youtube.com/channel/4", "https://i.ytimg.com/vi/1/hqdefault.jpg", 100, "2023-08-10", OffsetDateTime.parse("2023-08-10T00:00:00Z"))
4141

4242
private val allStreams = listOf(
43-
stream1, stream2, stream3, stream4, stream5, stream6, stream7
43+
stream1,
44+
stream2,
45+
stream3,
46+
stream4,
47+
stream5,
48+
stream6,
49+
stream7
4450
)
4551

4652
@Before
4753
fun createDb() {
4854
val context = ApplicationProvider.getApplicationContext<Context>()
4955
db = Room.inMemoryDatabaseBuilder(
50-
context, AppDatabase::class.java
56+
context,
57+
AppDatabase::class.java
5158
).build()
5259
feedDAO = db.feedDAO()
5360
streamDAO = db.streamDAO()
@@ -64,7 +71,10 @@ class FeedDAOTest {
6471
fun testUnlinkStreamsOlderThan_KeepOne() {
6572
setupUnlinkDelete("2023-08-15T00:00:00Z")
6673
val streams = feedDAO.getStreams(
67-
FeedGroupEntity.GROUP_ALL_ID, includePlayed = true, includePartiallyPlayed = true, null
74+
FeedGroupEntity.GROUP_ALL_ID,
75+
includePlayed = true,
76+
includePartiallyPlayed = true,
77+
null
6878
)
6979
.blockingGet()
7080
val allowedStreams = listOf(stream3, stream5, stream6, stream7)
@@ -75,7 +85,10 @@ class FeedDAOTest {
7585
fun testUnlinkStreamsOlderThan_KeepMultiple() {
7686
setupUnlinkDelete("2023-08-01T00:00:00Z")
7787
val streams = feedDAO.getStreams(
78-
FeedGroupEntity.GROUP_ALL_ID, includePlayed = true, includePartiallyPlayed = true, null
88+
FeedGroupEntity.GROUP_ALL_ID,
89+
includePlayed = true,
90+
includePartiallyPlayed = true,
91+
null
7992
)
8093
.blockingGet()
8194
val allowedStreams = listOf(stream3, stream4, stream5, stream6, stream7)
@@ -111,7 +124,7 @@ class FeedDAOTest {
111124
SubscriptionEntity.from(ChannelInfo(serviceId, "1", "https://youtube.com/channel/1", "https://youtube.com/channel/1", "channel-1")),
112125
SubscriptionEntity.from(ChannelInfo(serviceId, "2", "https://youtube.com/channel/2", "https://youtube.com/channel/2", "channel-2")),
113126
SubscriptionEntity.from(ChannelInfo(serviceId, "3", "https://youtube.com/channel/3", "https://youtube.com/channel/3", "channel-3")),
114-
SubscriptionEntity.from(ChannelInfo(serviceId, "4", "https://youtube.com/channel/4", "https://youtube.com/channel/4", "channel-4")),
127+
SubscriptionEntity.from(ChannelInfo(serviceId, "4", "https://youtube.com/channel/4", "https://youtube.com/channel/4", "channel-4"))
115128
)
116129
)
117130
feedDAO.insertAll(
@@ -122,7 +135,7 @@ class FeedDAOTest {
122135
FeedEntity(4, 2),
123136
FeedEntity(5, 2),
124137
FeedEntity(6, 3),
125-
FeedEntity(7, 4),
138+
FeedEntity(7, 4)
126139
)
127140
)
128141
}

app/src/androidTest/java/org/schabi/newpipe/local/history/HistoryRecordManagerTest.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package org.schabi.newpipe.local.history
22

33
import androidx.test.core.app.ApplicationProvider
4+
import java.time.LocalDateTime
5+
import java.time.OffsetDateTime
6+
import java.time.ZoneOffset
47
import org.assertj.core.api.Assertions.assertThat
58
import org.junit.After
69
import org.junit.Assert.assertEquals
@@ -11,9 +14,6 @@ import org.schabi.newpipe.database.AppDatabase
1114
import org.schabi.newpipe.database.history.model.SearchHistoryEntry
1215
import org.schabi.newpipe.testUtil.TestDatabase
1316
import org.schabi.newpipe.testUtil.TrampolineSchedulerRule
14-
import java.time.LocalDateTime
15-
import java.time.OffsetDateTime
16-
import java.time.ZoneOffset
1717

1818
class HistoryRecordManagerTest {
1919

@@ -54,7 +54,7 @@ class HistoryRecordManagerTest {
5454
SearchHistoryEntry(creationDate = time.minusSeconds(1), serviceId = 0, search = "A"),
5555
SearchHistoryEntry(creationDate = time.minusSeconds(2), serviceId = 2, search = "A"),
5656
SearchHistoryEntry(creationDate = time.minusSeconds(3), serviceId = 1, search = "B"),
57-
SearchHistoryEntry(creationDate = time.minusSeconds(4), serviceId = 0, search = "B"),
57+
SearchHistoryEntry(creationDate = time.minusSeconds(4), serviceId = 0, search = "B")
5858
)
5959

6060
// make sure all 4 were inserted
@@ -85,7 +85,7 @@ class HistoryRecordManagerTest {
8585
val entries = listOf(
8686
SearchHistoryEntry(creationDate = time.minusSeconds(1), serviceId = 1, search = "A"),
8787
SearchHistoryEntry(creationDate = time.minusSeconds(2), serviceId = 2, search = "B"),
88-
SearchHistoryEntry(creationDate = time.minusSeconds(3), serviceId = 0, search = "C"),
88+
SearchHistoryEntry(creationDate = time.minusSeconds(3), serviceId = 0, search = "C")
8989
)
9090

9191
// make sure all 3 were inserted
@@ -98,7 +98,6 @@ class HistoryRecordManagerTest {
9898
}
9999

100100
private fun insertShuffledRelatedSearches(relatedSearches: Collection<SearchHistoryEntry>) {
101-
102101
// shuffle to make sure the order of items returned by queries depends only on
103102
// SearchHistoryEntry.creationDate, not on the actual insertion time, so that we can
104103
// verify that the `ORDER BY` clause does its job
@@ -121,7 +120,7 @@ class HistoryRecordManagerTest {
121120
RELATED_SEARCHES_ENTRIES[6].search, // A (even if in two places)
122121
RELATED_SEARCHES_ENTRIES[4].search, // B
123122
RELATED_SEARCHES_ENTRIES[5].search, // AA
124-
RELATED_SEARCHES_ENTRIES[2].search, // BA
123+
RELATED_SEARCHES_ENTRIES[2].search // BA
125124
)
126125
}
127126

@@ -136,7 +135,7 @@ class HistoryRecordManagerTest {
136135
SearchHistoryEntry(creationDate = time.minusSeconds(4), serviceId = 3, search = "A"),
137136
SearchHistoryEntry(creationDate = time.minusSeconds(3), serviceId = 3, search = "A"),
138137
SearchHistoryEntry(creationDate = time.minusSeconds(2), serviceId = 0, search = "A"),
139-
SearchHistoryEntry(creationDate = time.minusSeconds(1), serviceId = 2, search = "AA"),
138+
SearchHistoryEntry(creationDate = time.minusSeconds(1), serviceId = 2, search = "AA")
140139
)
141140
insertShuffledRelatedSearches(relatedSearches)
142141

@@ -153,7 +152,7 @@ class HistoryRecordManagerTest {
153152
assertThat(searches).containsExactly(
154153
RELATED_SEARCHES_ENTRIES[6].search, // A (even if in two places)
155154
RELATED_SEARCHES_ENTRIES[5].search, // AA
156-
RELATED_SEARCHES_ENTRIES[1].search, // BA
155+
RELATED_SEARCHES_ENTRIES[1].search // BA
157156
)
158157

159158
// also make sure that the string comparison is case insensitive
@@ -171,7 +170,7 @@ class HistoryRecordManagerTest {
171170
SearchHistoryEntry(creationDate = time.minusSeconds(4), serviceId = 3, search = "A"),
172171
SearchHistoryEntry(creationDate = time.minusSeconds(2), serviceId = 0, search = "B"),
173172
SearchHistoryEntry(creationDate = time.minusSeconds(3), serviceId = 2, search = "AA"),
174-
SearchHistoryEntry(creationDate = time.minusSeconds(1), serviceId = 1, search = "A"),
173+
SearchHistoryEntry(creationDate = time.minusSeconds(1), serviceId = 1, search = "A")
175174
)
176175
}
177176
}

app/src/androidTest/java/org/schabi/newpipe/local/playlist/LocalPlaylistManagerTest.kt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ class LocalPlaylistManagerTest {
3333
fun createPlaylist() {
3434
val NEWPIPE_URL = "https://newpipe.net/"
3535
val stream = StreamEntity(
36-
serviceId = 1, url = NEWPIPE_URL, title = "title",
37-
streamType = StreamType.VIDEO_STREAM, duration = 1, uploader = "uploader",
36+
serviceId = 1,
37+
url = NEWPIPE_URL,
38+
title = "title",
39+
streamType = StreamType.VIDEO_STREAM,
40+
duration = 1,
41+
uploader = "uploader",
3842
uploaderUrl = NEWPIPE_URL
3943
)
4044

@@ -58,14 +62,22 @@ class LocalPlaylistManagerTest {
5862
@Test()
5963
fun createPlaylist_nonExistentStreamsAreUpserted() {
6064
val stream = StreamEntity(
61-
serviceId = 1, url = "https://newpipe.net/", title = "title",
62-
streamType = StreamType.VIDEO_STREAM, duration = 1, uploader = "uploader",
65+
serviceId = 1,
66+
url = "https://newpipe.net/",
67+
title = "title",
68+
streamType = StreamType.VIDEO_STREAM,
69+
duration = 1,
70+
uploader = "uploader",
6371
uploaderUrl = "https://newpipe.net/"
6472
)
6573
database.streamDAO().insert(stream)
6674
val upserted = StreamEntity(
67-
serviceId = 1, url = "https://newpipe.net/2", title = "title2",
68-
streamType = StreamType.VIDEO_STREAM, duration = 1, uploader = "uploader",
75+
serviceId = 1,
76+
url = "https://newpipe.net/2",
77+
title = "title2",
78+
streamType = StreamType.VIDEO_STREAM,
79+
duration = 1,
80+
uploader = "uploader",
6981
uploaderUrl = "https://newpipe.net/"
7082
)
7183

app/src/androidTest/java/org/schabi/newpipe/testUtil/TrampolineSchedulerRule.kt

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,20 @@ class TrampolineSchedulerRule : TestRule {
1717

1818
private val scheduler = Schedulers.trampoline()
1919

20-
override fun apply(base: Statement, description: Description): Statement =
21-
object : Statement() {
22-
override fun evaluate() {
23-
try {
24-
RxJavaPlugins.setComputationSchedulerHandler { scheduler }
25-
RxJavaPlugins.setIoSchedulerHandler { scheduler }
26-
RxJavaPlugins.setNewThreadSchedulerHandler { scheduler }
27-
RxJavaPlugins.setSingleSchedulerHandler { scheduler }
28-
RxAndroidPlugins.setInitMainThreadSchedulerHandler { scheduler }
20+
override fun apply(base: Statement, description: Description): Statement = object : Statement() {
21+
override fun evaluate() {
22+
try {
23+
RxJavaPlugins.setComputationSchedulerHandler { scheduler }
24+
RxJavaPlugins.setIoSchedulerHandler { scheduler }
25+
RxJavaPlugins.setNewThreadSchedulerHandler { scheduler }
26+
RxJavaPlugins.setSingleSchedulerHandler { scheduler }
27+
RxAndroidPlugins.setInitMainThreadSchedulerHandler { scheduler }
2928

30-
base.evaluate()
31-
} finally {
32-
RxJavaPlugins.reset()
33-
RxAndroidPlugins.reset()
34-
}
29+
base.evaluate()
30+
} finally {
31+
RxJavaPlugins.reset()
32+
RxAndroidPlugins.reset()
3533
}
3634
}
35+
}
3736
}

0 commit comments

Comments
 (0)