Skip to content

Commit

Permalink
🔨 調整 ktlint 和新增 git hook (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
frankvicky committed Jun 29, 2023
1 parent 2bb0fa5 commit 145c997
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package tw.waterballsa.gaas.application.extension

import tw.waterballsa.gaas.domain.Room
import tw.waterballsa.gaas.domain.User
import tw.waterballsa.gaas.domain.Room.Player
import tw.waterballsa.gaas.domain.User

internal fun User.toRoomPlayer(): Player =
Player(Player.Id(id!!.value), nickname)
Player(Player.Id(id!!.value), nickname)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ package tw.waterballsa.gaas.application.model
class Pagination<T>(
val page: Int,
val offset: Int,
val data: List<T> = emptyList()
val data: List<T> = emptyList(),
)

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CreateUserUseCase(
fun execute(request: Request) {
val user = userRepository.findByEmail(request.email)

with (request) {
with(request) {
when {
user == null -> createUser()
!user.hasIdentity(identityProviderId) -> user.addUserIdentity(identityProviderId)
Expand All @@ -42,7 +42,7 @@ class CreateUserUseCase(
private fun Request.toUser(): User = User(
email = email,
nickname = "user_${randomUUID()}",
identities = mutableListOf(identityProviderId)
identities = mutableListOf(identityProviderId),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class GetRoomsUseCase(
class Request(
val status: Room.Status,
val page: Int,
val offset: Int
val offset: Int,
)

interface GetRoomsPresenter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import javax.inject.Named
class JoinRoomUsecase(
private val roomRepository: RoomRepository,
private val userRepository: UserRepository,
private val eventBus: EventBus
){
private val eventBus: EventBus,
) {

fun execute(request: Request) {
with(request) {
Expand All @@ -30,7 +30,7 @@ class JoinRoomUsecase(
?: throw notFound(Room::class).id(roomId)

private fun Room.validateRoomPassword(password: String?) {
if(isLocked && !isPasswordCorrect(password)){
if (isLocked && !isPasswordCorrect(password)) {
throw PlatformException("wrong password")
}
}
Expand All @@ -51,4 +51,4 @@ class JoinRoomUsecase(
val userId: String,
val password: String? = null,
)
}
}
4 changes: 2 additions & 2 deletions domain/src/main/kotlin/tw/waterballsa/gaas/domain/Room.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class Room(
val isLocked: Boolean
get() = !password.isNullOrEmpty()

fun addPlayer(player: Player){
fun addPlayer(player: Player) {
players.add(player)
}

fun isPasswordCorrect(password: String?): Boolean{
fun isPasswordCorrect(password: String?): Boolean {
return this.password.equals(password)
}

Expand Down
2 changes: 1 addition & 1 deletion domain/src/main/kotlin/tw/waterballsa/gaas/domain/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class User(
val id: Id? = null,
val email: String = "",
val nickname: String = "",
val identities: MutableList<String> = mutableListOf()
val identities: MutableList<String> = mutableListOf(),
) {
@JvmInline
value class Id(val value: String)
Expand Down
24 changes: 2 additions & 22 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,33 +84,13 @@
<version>1.16.0</version>
<executions>
<execution>
<id>format-and-check</id>
<id>lint</id>
<goals>
<goal>format</goal>
<goal>check</goal>
<goal>ktlint</goal>
</goals>
</execution>
<execution>
<id>reporter</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<failOnViolation>false</failOnViolation>
<reporters>
<reporter>
<name>plain</name>
<output>${project.build.directory}/ktlint.txt</output>
<properties>
<property>
<name>group_by_file</name>
<value>true</value>
</property>
</properties>
</reporter>
</reporters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Expand Down
17 changes: 17 additions & 0 deletions pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

echo "Running Maven verify..."
mvn verify

# 檢查 Maven 命令的執行結果,如果驗證失敗,則禁止提交(commit)
if [ $? -ne 0 ]; then
echo "Maven verify failed. Commit aborted."
exit 1
fi

# 添加已變更的檔案到暫存區
git add .

exit 0


0 comments on commit 145c997

Please sign in to comment.