Skip to content

Commit 3d61523

Browse files
committed
lint
1 parent 7309431 commit 3d61523

35 files changed

+380
-306
lines changed

inspector/src/main/kotlin/eu/kanade/tachiyomi/App.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import uy.kohesive.injekt.api.InjektScope
1515
import uy.kohesive.injekt.registry.default.DefaultRegistrar
1616

1717
open class App : Application() {
18-
1918
override fun onCreate() {
2019
super.onCreate()
2120
Injekt = InjektScope(DefaultRegistrar())

inspector/src/main/kotlin/eu/kanade/tachiyomi/AppInfo.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ package eu.kanade.tachiyomi
77
*/
88
object AppInfo {
99
fun getVersionCode() = BuildConfig.VERSION_CODE
10+
1011
fun getVersionName() = BuildConfig.VERSION_NAME
1112
}

inspector/src/main/kotlin/eu/kanade/tachiyomi/AppModule.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ import uy.kohesive.injekt.api.InjektRegistrar
1717
import uy.kohesive.injekt.api.addSingleton
1818
import uy.kohesive.injekt.api.addSingletonFactory
1919

20-
class AppModule(val app: Application) : InjektModule {
21-
20+
class AppModule(
21+
val app: Application,
22+
) : InjektModule {
2223
override fun InjektRegistrar.registerInjectables() {
2324
addSingleton(app)
2425

inspector/src/main/kotlin/eu/kanade/tachiyomi/BuildConfig.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package eu.kanade.tachiyomi
33
class BuildConfig {
44
companion object {
55
const val VERSION_NAME = inspector.BuildConfig.NAME
6-
val VERSION_CODE = inspector.BuildConfig.REVISION.trimStart('r').toInt()
6+
val VERSION_CODE =
7+
inspector.BuildConfig.REVISION
8+
.trimStart('r')
9+
.toInt()
710
}
811
}

inspector/src/main/kotlin/eu/kanade/tachiyomi/network/JavaScriptEngine.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import eu.kanade.tachiyomi.util.lang.withIOContext
77
/**
88
* Util for evaluating JavaScript in sources.
99
*/
10-
class JavaScriptEngine(context: Context) {
11-
10+
class JavaScriptEngine(
11+
context: Context,
12+
) {
1213
/**
1314
* Evaluate arbitrary JavaScript code and get the result as a primtive type
1415
* (e.g., String, Int).
@@ -18,9 +19,10 @@ class JavaScriptEngine(context: Context) {
1819
* @return Result of JavaScript code as a primitive type.
1920
*/
2021
@Suppress("UNUSED", "UNCHECKED_CAST")
21-
suspend fun <T> evaluate(script: String): T = withIOContext {
22-
QuickJs.create().use {
23-
it.evaluate(script) as T
22+
suspend fun <T> evaluate(script: String): T =
23+
withIOContext {
24+
QuickJs.create().use {
25+
it.evaluate(script) as T
26+
}
2427
}
25-
}
2628
}

inspector/src/main/kotlin/eu/kanade/tachiyomi/network/MemoryCookieJar.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ class MemoryCookieJar : CookieJar {
3434
}
3535

3636
@Synchronized
37-
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {
37+
override fun saveFromResponse(
38+
url: HttpUrl,
39+
cookies: List<Cookie>,
40+
) {
3841
val cookiesToAdd = cookies.map { WrappedCookie.wrap(it) }
3942

4043
cache.removeAll(cookiesToAdd)
@@ -47,7 +50,9 @@ class MemoryCookieJar : CookieJar {
4750
}
4851
}
4952

50-
class WrappedCookie private constructor(val cookie: Cookie) {
53+
class WrappedCookie private constructor(
54+
val cookie: Cookie,
55+
) {
5156
fun unwrap() = cookie
5257

5358
fun isExpired() = cookie.expiresAt < System.currentTimeMillis()

inspector/src/main/kotlin/eu/kanade/tachiyomi/network/NetworkHelper.kt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,25 @@ import eu.kanade.tachiyomi.network.interceptor.CloudflareInterceptor
1313
import okhttp3.OkHttpClient
1414
import java.util.concurrent.TimeUnit
1515

16-
class NetworkHelper(context: Context) {
17-
16+
class NetworkHelper(
17+
context: Context,
18+
) {
1819
val cookieManager = MemoryCookieJar()
1920

2021
val client by lazy {
21-
val builder = OkHttpClient.Builder()
22-
.cookieJar(cookieManager)
23-
.connectTimeout(30, TimeUnit.SECONDS)
24-
.readTimeout(5, TimeUnit.MINUTES)
25-
.writeTimeout(5, TimeUnit.MINUTES)
22+
val builder =
23+
OkHttpClient
24+
.Builder()
25+
.cookieJar(cookieManager)
26+
.connectTimeout(30, TimeUnit.SECONDS)
27+
.readTimeout(5, TimeUnit.MINUTES)
28+
.writeTimeout(5, TimeUnit.MINUTES)
2629
builder.build()
2730
}
2831

2932
val cloudflareClient by lazy {
30-
client.newBuilder()
33+
client
34+
.newBuilder()
3135
.addInterceptor(CloudflareInterceptor())
3236
.build()
3337
}

inspector/src/main/kotlin/eu/kanade/tachiyomi/network/OkHttpExtensions.kt

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ suspend fun Call.await(): Response {
1919
return suspendCancellableCoroutine { continuation ->
2020
enqueue(
2121
object : Callback {
22-
override fun onResponse(call: Call, response: Response) {
22+
override fun onResponse(
23+
call: Call,
24+
response: Response,
25+
) {
2326
if (!response.isSuccessful) {
2427
continuation.resumeWithException(HttpException(response.code))
2528
return
@@ -30,12 +33,15 @@ suspend fun Call.await(): Response {
3033
}
3134
}
3235

33-
override fun onFailure(call: Call, e: IOException) {
36+
override fun onFailure(
37+
call: Call,
38+
e: IOException,
39+
) {
3440
// Don't bother with resuming the continuation if it is already cancelled.
3541
if (continuation.isCancelled) return
3642
continuation.resumeWithException(e)
3743
}
38-
}
44+
},
3945
)
4046

4147
continuation.invokeOnCancellation {
@@ -54,51 +60,55 @@ fun Call.asObservable(): Observable<Response> {
5460
val call = clone()
5561

5662
// Wrap the call in a helper which handles both unsubscription and backpressure.
57-
val requestArbiter = object : AtomicBoolean(), Producer, Subscription {
58-
override fun request(n: Long) {
59-
if (n == 0L || !compareAndSet(false, true)) return
63+
val requestArbiter =
64+
object : AtomicBoolean(), Producer, Subscription {
65+
override fun request(n: Long) {
66+
if (n == 0L || !compareAndSet(false, true)) return
6067

61-
try {
62-
val response = call.execute()
63-
if (!subscriber.isUnsubscribed) {
64-
subscriber.onNext(response)
65-
subscriber.onCompleted()
66-
}
67-
} catch (error: Exception) {
68-
if (!subscriber.isUnsubscribed) {
69-
subscriber.onError(error)
68+
try {
69+
val response = call.execute()
70+
if (!subscriber.isUnsubscribed) {
71+
subscriber.onNext(response)
72+
subscriber.onCompleted()
73+
}
74+
} catch (error: Exception) {
75+
if (!subscriber.isUnsubscribed) {
76+
subscriber.onError(error)
77+
}
7078
}
7179
}
72-
}
7380

74-
override fun unsubscribe() {
75-
// call.cancel()
76-
}
81+
override fun unsubscribe() {
82+
// call.cancel()
83+
}
7784

78-
override fun isUnsubscribed(): Boolean {
79-
return call.isCanceled()
85+
override fun isUnsubscribed(): Boolean = call.isCanceled()
8086
}
81-
}
8287

8388
subscriber.add(requestArbiter)
8489
subscriber.setProducer(requestArbiter)
8590
}
8691
}
8792

88-
fun Call.asObservableSuccess(): Observable<Response> {
89-
return asObservable().doOnNext { response ->
93+
fun Call.asObservableSuccess(): Observable<Response> =
94+
asObservable().doOnNext { response ->
9095
if (!response.isSuccessful) {
9196
response.close()
9297
throw HttpException(response.code)
9398
}
9499
}
95-
}
96100

97-
fun OkHttpClient.newCallWithProgress(request: Request, listener: ProgressListener): Call {
98-
val progressClient = newBuilder()
99-
.build()
101+
fun OkHttpClient.newCallWithProgress(
102+
request: Request,
103+
listener: ProgressListener,
104+
): Call {
105+
val progressClient =
106+
newBuilder()
107+
.build()
100108

101109
return progressClient.newCall(request)
102110
}
103111

104-
class HttpException(val code: Int) : IllegalStateException("HTTP error $code")
112+
class HttpException(
113+
val code: Int,
114+
) : IllegalStateException("HTTP error $code")
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package eu.kanade.tachiyomi.network
22

33
interface ProgressListener {
4-
fun update(bytesRead: Long, contentLength: Long, done: Boolean)
4+
fun update(
5+
bytesRead: Long,
6+
contentLength: Long,
7+
done: Boolean,
8+
)
59
}

inspector/src/main/kotlin/eu/kanade/tachiyomi/network/Requests.kt

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@file:Suppress("ktlint:standard:function-naming")
2+
13
package eu.kanade.tachiyomi.network
24

35
import okhttp3.CacheControl
@@ -15,14 +17,14 @@ private val DEFAULT_BODY: RequestBody = FormBody.Builder().build()
1517
fun GET(
1618
url: String,
1719
headers: Headers = DEFAULT_HEADERS,
18-
cache: CacheControl = DEFAULT_CACHE_CONTROL
19-
): Request {
20-
return Request.Builder()
20+
cache: CacheControl = DEFAULT_CACHE_CONTROL,
21+
): Request =
22+
Request
23+
.Builder()
2124
.url(url)
2225
.headers(headers)
2326
.cacheControl(cache)
2427
.build()
25-
}
2628

2729
/**
2830
* @since extensions-lib 1.4
@@ -31,24 +33,24 @@ fun GET(
3133
url: HttpUrl,
3234
headers: Headers = DEFAULT_HEADERS,
3335
cache: CacheControl = DEFAULT_CACHE_CONTROL,
34-
): Request {
35-
return Request.Builder()
36+
): Request =
37+
Request
38+
.Builder()
3639
.url(url)
3740
.headers(headers)
3841
.cacheControl(cache)
3942
.build()
40-
}
4143

4244
fun POST(
4345
url: String,
4446
headers: Headers = DEFAULT_HEADERS,
4547
body: RequestBody = DEFAULT_BODY,
46-
cache: CacheControl = DEFAULT_CACHE_CONTROL
47-
): Request {
48-
return Request.Builder()
48+
cache: CacheControl = DEFAULT_CACHE_CONTROL,
49+
): Request =
50+
Request
51+
.Builder()
4952
.url(url)
5053
.post(body)
5154
.headers(headers)
5255
.cacheControl(cache)
5356
.build()
54-
}

0 commit comments

Comments
 (0)