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

Add ktlint plugin code styling and formatting #281

Merged
merged 12 commits into from
Oct 21, 2023
1 change: 1 addition & 0 deletions bigbone-rx/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'bigbone.library-conventions'
alias(libs.plugins.ktlint)
}

dependencies {
Expand Down
10 changes: 8 additions & 2 deletions bigbone-rx/src/main/kotlin/social/bigbone/rx/RxAccountMethods.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ class RxAccountMethods(client: MastodonClient) {
): Single<Token> {
return Single.create {
try {
val token = accountMethods.registerAccount(username, email, password,
agreement, locale, reason).execute()
val token = accountMethods.registerAccount(
username,
email,
password,
agreement,
locale,
reason
).execute()
it.onSuccess(token)
} catch (throwable: Throwable) {
it.onErrorIfNotDisposed(throwable)
Expand Down
1 change: 1 addition & 0 deletions bigbone/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'bigbone.library-conventions'
id 'bigbone.integrationtest-conventions'
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.ktlint)
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ import org.junit.platform.suite.api.SuiteDisplayName
V300InstanceMethodsIntegrationTest::class,
V300StatusMethodsIntegrationTest::class
)
class V300TestSuite {
}
class V300TestSuite
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ import org.junit.platform.suite.api.SuiteDisplayName
V402InstanceMethodsIntegrationTest::class,
V402StatusMethodsIntegrationTest::class
)
class V402TestSuite {
}
class V402TestSuite
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class V410StatusMethodsIntegrationTest {
options = listOf("Ja", "Nein"),
expiresIn = "300",
multiple = true,
hideTotals = true,
hideTotals = true
),
visibility = Status.Visibility.Private,
inReplyToId = statusId,
Expand Down Expand Up @@ -260,10 +260,10 @@ class V410StatusMethodsIntegrationTest {
val scheduledPoll = user1Client.statuses.schedulePoll(
status = "Will this poll be posted at $inSixMinutes?",
scheduledAt = inSixMinutes,
pollData = PollData (
pollData = PollData(
options = listOf("Yes", "No"),
expiresIn = "300"
),
)
).execute()

// then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ import org.junit.platform.suite.api.SuiteDisplayName
V410StatusMethodsIntegrationTest::class,
V410MediaMethodsIntegrationTest::class
)
class V410TestSuite {
}
class V410TestSuite
2 changes: 1 addition & 1 deletion bigbone/src/main/kotlin/social/bigbone/JsonSerializer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ internal val JSON_SERIALIZER: Json = Json {
encodeDefaults = true
ignoreUnknownKeys = true
coerceInputValues = true
}
}
5 changes: 4 additions & 1 deletion bigbone/src/main/kotlin/social/bigbone/MastodonClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,10 @@ private constructor(
return client.newCall(
Request.Builder().url(
fullUrl(
scheme, instanceName, port, "api/$versionString/instance"
scheme,
instanceName,
port,
"api/$versionString/instance"
)
).get().build()
).execute()
Expand Down
2 changes: 1 addition & 1 deletion bigbone/src/main/kotlin/social/bigbone/api/Range.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Range @JvmOverloads constructor(
val maxId: String? = null,
val minId: String? = null,
val sinceId: String? = null,
val limit: Int? = null,
val limit: Int? = null
) {
fun toParameters() = Parameters().apply {
maxId?.let { append("max_id", it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ data class Conversation(
* The last status in the conversation.
*/
@SerialName("last_status")
val lastStatus: Status? = null,
val lastStatus: Status? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ data class Filter(
* Do not show this status if it is received.
*/
Hide("hide"),

/**
* Show a warning that identifies the matching filter by title, and allow the user to expand the filtered status.
* This is the default (and unknown values should be treated as equivalent to warn).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ data class Marker(
* The timestamp of when the marker was set (ISO 8601 Datetime).
*/
@SerialName("updated_at")
val updatedAt: String = "",
val updatedAt: String = ""
)
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ data class MastodonList(
* @see [RepliesPolicy]
*/
@SerialName("replies_policy")
val repliesPolicy: String = RepliesPolicy.List.value,
val repliesPolicy: String = RepliesPolicy.List.value
) {
/**
* Specifies the replies policy for a list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ data class MediaAttachment(
* Contains the coordinates to be used for smart thumbnail cropping.
*/
@SerialName("focus")
val focus: Focus? = null,
val focus: Focus? = null
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ data class PreviewCard(
* Usage statistics for given days (typically the past week).
*/
@SerialName("history")
val history: List<History> = emptyList(),
val history: List<History> = emptyList()
) {
/**
* Specifies the type of the preview card.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ data class Report(
* The account that was reported.
*/
@SerialName("target_account")
val targetAccount: Account,
val targetAccount: Account
) {
/**
* Specify the typology of category among spam, violation or other.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ data class StatusEdit(
@Serializable
data class PollRevision(
@SerialName("options")
val options: List<PollOption> = emptyList(),
val options: List<PollOption> = emptyList()
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class AccountMethods(private val client: MastodonClient) {
fun followAccount(accountId: String): MastodonRequest<Relationship> {
return client.getMastodonRequest(
endpoint = "api/v1/accounts/$accountId/follow",
method = MastodonClient.Method.POST,
method = MastodonClient.Method.POST
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,4 @@ class FeaturedTagsMethods(private val client: MastodonClient) {
method = MastodonClient.Method.GET
)
}

}
}
37 changes: 22 additions & 15 deletions bigbone/src/main/kotlin/social/bigbone/api/method/MarkerMethods.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ class MarkerMethods(private val client: MastodonClient) {
endpoint = "api/v1/markers",
method = MastodonClient.Method.GET,
parameters = Parameters().apply {
timeline?.let {
when (timeline) {
Timeline.HOME -> append("timeline[]", "home")
Timeline.NOTIFICATIONS -> append("timeline[]", "notifications")
timeline?.let {
when (timeline) {
Timeline.HOME -> append("timeline[]", "home")
Timeline.NOTIFICATIONS -> append("timeline[]", "notifications")
}
} ?: run {
append("timeline[]", "home")
append("timeline[]", "notifications")
}
} ?: run {
append("timeline[]", "home")
append("timeline[]", "notifications")
}
})
)
}

/**
Expand All @@ -43,14 +44,20 @@ class MarkerMethods(private val client: MastodonClient) {
* @param lastReadId the id of the last read post.
*/
@Throws(BigBoneRequestException::class)
fun updateMarker(timeline: Timeline, lastReadId: Int): MastodonRequest<Marker> {
return client.getMastodonRequest(endpoint = "api/v1/markers", method = MastodonClient.Method.POST, parameters = Parameters().apply {
when (timeline) {
Timeline.HOME -> append("home[last_read_id]", lastReadId)
Timeline.NOTIFICATIONS -> append("notifications[last_read_id]", lastReadId)
fun updateMarker(
timeline: Timeline,
lastReadId: Int
): MastodonRequest<Marker> {
return client.getMastodonRequest(
endpoint = "api/v1/markers",
method = MastodonClient.Method.POST,
parameters = Parameters().apply {
when (timeline) {
Timeline.HOME -> append("home[last_read_id]", lastReadId)
Timeline.NOTIFICATIONS -> append("notifications[last_read_id]", lastReadId)
}
}
})

)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ class ReportMethods(private val client: MastodonClient) {
append("account_id", accountId)
append("forward", forward)
append("category", setCategoryCorrectly(ruleIds, category).name)
if(!statusIds.isNullOrEmpty()) {
if (!statusIds.isNullOrEmpty()) {
append("status_ids", statusIds)
}
if(!comment.isNullOrEmpty() && comment.isNotBlank()) {
if (!comment.isNullOrEmpty() && comment.isNotBlank()) {
append("comment", comment)
}
if(!ruleIds.isNullOrEmpty()) {
if (!ruleIds.isNullOrEmpty()) {
append("ruleIds", ruleIds)
}
}
Expand Down
76 changes: 38 additions & 38 deletions bigbone/src/main/kotlin/social/bigbone/api/method/SearchMethods.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ class SearchMethods(private val client: MastodonClient) {
*/
@JvmOverloads
fun searchContent(
query: String,
type: SearchType? = null,
resolve: Boolean = false,
following: Boolean = false,
excludeUnreviewed: Boolean = false,
accountId: String? = null,
maxId: String? = null,
minId: String? = null,
limit: Int? = null,
offset: Int? = null
): MastodonRequest<Search> {
query: String,
type: SearchType? = null,
resolve: Boolean = false,
following: Boolean = false,
excludeUnreviewed: Boolean = false,
accountId: String? = null,
maxId: String? = null,
minId: String? = null,
limit: Int? = null,
offset: Int? = null
): MastodonRequest<Search> {
return client.getMastodonRequest(
endpoint = "api/v2/search",
method = MastodonClient.Method.GET,
Expand All @@ -66,33 +66,33 @@ class SearchMethods(private val client: MastodonClient) {
limit: Int? = null,
offset: Int? = null
): Parameters {
return Parameters().apply {
append("q", query)
append("offset", offset ?: 0)
if (resolve) {
append("resolve", true)
}
if (following) {
append("following", true)
}
if (excludeUnreviewed) {
append("exclude_unreviewed", true)
}
if (type != null) {
append("type", type.name)
}
if (!accountId.isNullOrEmpty() && accountId.isNotBlank()) {
append("account_id", accountId)
}
if (!maxId.isNullOrEmpty() && maxId.isNotBlank()) {
append("max_id", maxId)
}
if (!minId.isNullOrEmpty() && minId.isNotBlank()) {
append("min_id", minId)
}
if (limit != null) {
append("limit", limit.coerceIn(20, 40))
}
return Parameters().apply {
append("q", query)
append("offset", offset ?: 0)
if (resolve) {
append("resolve", true)
}
if (following) {
append("following", true)
}
if (excludeUnreviewed) {
append("exclude_unreviewed", true)
}
if (type != null) {
append("type", type.name)
}
if (!accountId.isNullOrEmpty() && accountId.isNotBlank()) {
append("account_id", accountId)
}
if (!maxId.isNullOrEmpty() && maxId.isNotBlank()) {
append("max_id", maxId)
}
if (!minId.isNullOrEmpty() && minId.isNotBlank()) {
append("min_id", minId)
}
if (limit != null) {
append("limit", limit.coerceIn(20, 40))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ class StatusMethods(private val client: MastodonClient) {
fun reblogStatus(statusId: String, visibility: Status.Visibility = Status.Visibility.Public): MastodonRequest<Status> {
if (visibility != Status.Visibility.Public &&
visibility != Status.Visibility.Unlisted &&
visibility != Status.Visibility.Private) {
visibility != Status.Visibility.Private
) {
throw BigBoneRequestException("Visibility must be one of: public, unlisted, private when reblogging.")
}
return client.getMastodonRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ object NodeInfoClient {
throw BigBoneRequestException("empty link list in well-known NodeInfo location")
}


// attempt returning URL to schema 2.0 information, but fall back to any - software information exists in all schemas
return nodeInfo.links
.firstOrNull { link -> link.rel == "http://nodeinfo.diaspora.software/ns/schema/2.0" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,4 @@ class FeaturedTagsMethodsTest {
history1[0].uses shouldBeEqualTo "0"
following1.shouldBeNull()
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import org.amshove.kluent.`should not be`
import org.amshove.kluent.shouldBe
import org.amshove.kluent.shouldBeEqualTo
import org.junit.jupiter.api.Test

import social.bigbone.testtool.MockClient

class MarkerMethodsTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class StatusMethodsTest {
mediaIds = null,
sensitive = false,
spoilerText = null,
language = "en",
language = "en"
).execute()
}
}
Expand Down
Loading