Skip to content

Commit

Permalink
lint-fix: Apply linting rules to project files
Browse files Browse the repository at this point in the history
  • Loading branch information
Handiwork committed Apr 12, 2024
1 parent ad66224 commit 938f401
Show file tree
Hide file tree
Showing 142 changed files with 1,033 additions and 1,197 deletions.
42 changes: 42 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# https://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
max_line_length = 140

end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{java,kt,kts,scala,rs,xml,kt.spec,kts.spec}]
indent_size = 4

[*.{kt,kts}]
ktlint_code_style = intellij_idea
ktlint_ignore_back_ticked_identifier = true

ktlint_standard = enabled

# Experimental rules run by default run on the ktlint code base itself. Experimental rules should not be released if
# we are not pleased ourselves with the results on the ktlint code base.
ktlint_experimental = disabled

# Don't allow any wildcard imports
ij_kotlin_packages_to_use_import_on_demand = unset

# Prevent wildcard imports
ij_kotlin_name_count_to_use_star_import = 99
ij_kotlin_name_count_to_use_star_import_for_members = 99

[*.md]
trim_trailing_whitespace = false
max_line_length = unset

[gradle/verification-metadata.xml]
indent_size = 3

[*.yml]
ij_yaml_spaces_within_brackets = false
70 changes: 42 additions & 28 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import org.hidetake.gradle.swagger.generator.GenerateSwaggerCode
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType

plugins {
java
Expand All @@ -13,6 +14,8 @@ plugins {
kotlin("jvm") version "1.9.22"
kotlin("plugin.spring") version "1.9.22"
kotlin("kapt") version "1.9.22"

id("org.jlleitschuh.gradle.ktlint") version "12.1.0"
}

group = "plus.maa"
Expand All @@ -28,7 +31,6 @@ repositories {
mavenCentral()
}


dependencies {
val hutoolVersion = "5.8.26"
val mapstructVersion = "1.5.5.Final"
Expand Down Expand Up @@ -68,8 +70,8 @@ dependencies {
implementation("cn.hutool:hutool-dfa:$hutoolVersion")

// mapstruct
implementation("org.mapstruct:mapstruct:${mapstructVersion}")
kapt("org.mapstruct:mapstruct-processor:${mapstructVersion}")
implementation("org.mapstruct:mapstruct:$mapstructVersion")
kapt("org.mapstruct:mapstruct-processor:$mapstructVersion")

implementation("org.eclipse.jgit:org.eclipse.jgit:6.8.0.202311291450-r")
implementation("org.eclipse.jgit:org.eclipse.jgit.ssh.apache.agent:6.8.0.202311291450-r")
Expand All @@ -84,7 +86,6 @@ dependencies {
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")

swaggerCodegen("org.openapitools:openapi-generator-cli:7.2.0")

}

kapt {
Expand All @@ -102,11 +103,9 @@ tasks.withType<Test> {
useJUnitPlatform()
}


val swaggerOutputDir = layout.buildDirectory.dir("docs")
val swaggerOutputName = "swagger.json"


openApi {
apiDocsUrl = "http://localhost:8848/v3/api-docs"
outputDir = swaggerOutputDir
Expand All @@ -119,38 +118,46 @@ swaggerSources {
val swaggerOutputFile = swaggerOutputDir.get().file(swaggerOutputName)
create("TsFetch") {
setInputFile(file(swaggerOutputFile))
code(closureOf<GenerateSwaggerCode> {
language = "typescript-fetch"
configFile = file("client-config/ts-fetch.json")
code(
closureOf<GenerateSwaggerCode> {
language = "typescript-fetch"
configFile = file("client-config/ts-fetch.json")
// templateDir = file('client-config/typescript-fetch')
rawOptions = listOf("-e", "mustache")
outputDir = file(clientDir.dir("ts-fetch-client"))
})
rawOptions = listOf("-e", "mustache")
outputDir = file(clientDir.dir("ts-fetch-client"))
},
)
}
create("CSharp") {
setInputFile(file(swaggerOutputFile))
code(closureOf<GenerateSwaggerCode> {
language = "csharp"
configFile = file("client-config/csharp-netcore.json")
outputDir = file(clientDir.dir("csharp-client"))
code(
closureOf<GenerateSwaggerCode> {
language = "csharp"
configFile = file("client-config/csharp-netcore.json")
outputDir = file(clientDir.dir("csharp-client"))
// rawOptions = listOf("--type-mappings", "binary=System.IO.Stream")
})
},
)
}
create("Cpp") {
setInputFile(file(swaggerOutputFile))
code(closureOf<GenerateSwaggerCode> {
language = "cpp-restsdk"
configFile = file("client-config/cpp.json")
outputDir = file(clientDir.dir("cpp-client"))
})
code(
closureOf<GenerateSwaggerCode> {
language = "cpp-restsdk"
configFile = file("client-config/cpp.json")
outputDir = file(clientDir.dir("cpp-client"))
},
)
}
create("Rust") {
setInputFile(file(swaggerOutputFile))
code(closureOf<GenerateSwaggerCode> {
language = "rust"
configFile = file("client-config/rust.json")
outputDir = file(clientDir.dir("rust-client"))
})
code(
closureOf<GenerateSwaggerCode> {
language = "rust"
configFile = file("client-config/rust.json")
outputDir = file(clientDir.dir("rust-client"))
},
)
}
}

Expand All @@ -160,8 +167,15 @@ tasks {
}
}


gitProperties {
failOnNoGitDirectory = false
keys = listOf("git.branch", "git.commit.id", "git.commit.id.abbrev", "git.commit.time")
}

ktlint {
ignoreFailures = false

reporters {
reporter(ReporterType.PLAIN)
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://mirrors.huaweicloud.com/gradle/gradle-8.6-bin.zip
distributionUrl=https://mirrors.huaweicloud.com/gradle/gradle-8.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/plus/maa/backend/common/MaaStatusCode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package plus.maa.backend.common
/**
* @author AnselYuki
*/
enum class MaaStatusCode(val code:Int,val message:String) {
enum class MaaStatusCode(
val code: Int,
val message: String,
) {
/**
* MAA自定义状态码
*/
Expand All @@ -12,5 +15,4 @@ enum class MaaStatusCode(val code:Int,val message:String) {
MAA_USER_NOT_ENABLED(10003, "用户未启用"),
MAA_USER_EXISTS(10004, "用户已存在"),
MAA_REGISTRATION_CODE_NOT_FOUND(10011, "注册验证码错误"),

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ annotation class SensitiveWordDetection(
/**
* SpEL 表达式
*/
vararg val value: String = []
vararg val value: String = [],
)
9 changes: 4 additions & 5 deletions src/main/kotlin/plus/maa/backend/common/aop/JsonSchemaAop.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private val log = KotlinLogging.logger { }
@Component
@Aspect
class JsonSchemaAop(
private val mapper: ObjectMapper
private val mapper: ObjectMapper,
) {
@Pointcut("@annotation(plus.maa.backend.common.annotation.JsonSchema)")
fun pt() {
Expand All @@ -46,7 +46,7 @@ class JsonSchemaAop(
fun before(joinPoint: JoinPoint, jsonSchema: JsonSchema?) {
var schemaJson: String? = null
var content: String? = null
//判断是验证的是Copilot还是Rating
// 判断是验证的是Copilot还是Rating
for (arg in joinPoint.args) {
if (arg is CopilotCUDRequest) {
content = arg.content
Expand All @@ -63,8 +63,7 @@ class JsonSchemaAop(
}
if (schemaJson == null || content == null) return


//获取json schema json路径并验证
// 获取json schema json路径并验证
try {
ClassPathResource(schemaJson).inputStream.use { inputStream ->
val json = JSONObject(content)
Expand All @@ -84,4 +83,4 @@ class JsonSchemaAop(
private const val COPILOT_SCHEMA_JSON = "static/templates/maa-copilot-schema.json"
private const val RATING_SCHEMA_JSON = "static/templates/maa-rating-schema.json"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ import plus.maa.backend.controller.response.MaaResultException
class SensitiveWordAop(
// 敏感词库
private val wordTree: WordTree,
private val objectMapper: ObjectMapper
private val objectMapper: ObjectMapper,
) {

// SpEL 表达式解析器
private val parser = SpelExpressionParser()

Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/plus/maa/backend/common/utils/ArkLevelUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package plus.maa.backend.common.utils
import java.util.regex.Pattern

object ArkLevelUtil {
private val NOT_KEY_INFO: Pattern = Pattern.compile( // level_、各种难度前缀、season_、前导零、以-或者_划分的后缀
"^level_|^easy_|^hard_|^tough_|^main_|season_|(?<!\\d)0+(?=\\d)|[-_]+[^-_]+($|[-_]+\\D+$)"
private val NOT_KEY_INFO: Pattern = Pattern.compile(
// level_、各种难度前缀、season_、前导零、以-或者_划分的后缀
"^level_|^easy_|^hard_|^tough_|^main_|season_|(?<!\\d)0+(?=\\d)|[-_]+[^-_]+($|[-_]+\\D+$)",
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import plus.maa.backend.controller.response.MaaResultException
import java.io.IOException
import java.io.StringWriter
import java.nio.charset.StandardCharsets
import java.util.*
import java.util.Locale

/**
* @author dragove
Expand Down
15 changes: 7 additions & 8 deletions src/main/kotlin/plus/maa/backend/common/utils/IdComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ private val log = KotlinLogging.logger { }

@Component
class IdComponent(
private val mongoTemplate: MongoTemplate
private val mongoTemplate: MongoTemplate,
) {
private val currentIdMap: MutableMap<String, AtomicLong> = ConcurrentHashMap()

Expand Down Expand Up @@ -41,11 +41,10 @@ class IdComponent(
return v.incrementAndGet()
}

private fun <T> getMax(entityClass: Class<T>, idGetter: (T) -> Long, fieldName: String) =
mongoTemplate.findOne(
Query().with(Sort.by(fieldName).descending()).limit(1),
entityClass
)
?.let(idGetter)
?: 20000L
private fun <T> getMax(entityClass: Class<T>, idGetter: (T) -> Long, fieldName: String) = mongoTemplate.findOne(
Query().with(Sort.by(fieldName).descending()).limit(1),
entityClass,
)
?.let(idGetter)
?: 20000L
}
6 changes: 3 additions & 3 deletions src/main/kotlin/plus/maa/backend/common/utils/IpUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ object IpUtil {
if (ip.isNullOrEmpty() || "unknown".equals(ip, ignoreCase = true)) {
ip = request.getHeader("Proxy-Client-IP")
}
if (ip.isNullOrEmpty()|| "unknown".equals(ip, ignoreCase = true)) {
if (ip.isNullOrEmpty() || "unknown".equals(ip, ignoreCase = true)) {
ip = request.getHeader("WL-Proxy-Client-IP")
}
if (ip.isNullOrEmpty()|| "unknown".equals(ip, ignoreCase = true)) {
if (ip.isNullOrEmpty() || "unknown".equals(ip, ignoreCase = true)) {
ip = request.remoteAddr
if (ip == "127.0.0.1") {
//根据网卡取本机配置的IP
// 根据网卡取本机配置的IP
val inet: InetAddress?
try {
inet = InetAddress.getLocalHost()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package plus.maa.backend.common.utils


inline fun <T> T?.requireNotNull(lazyMessage: () -> Any): T = requireNotNull(this, lazyMessage)
inline fun <T> T?.requireNotNull(lazyMessage: () -> Any): T = requireNotNull(this, lazyMessage)
13 changes: 6 additions & 7 deletions src/main/kotlin/plus/maa/backend/common/utils/OkHttpUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ class OkHttpUtils {
* @return OkHttpClient
*/
@Bean
fun defaultOkHttpClient(): OkHttpClient {
return OkHttpClient().newBuilder()
.connectTimeout(5, TimeUnit.SECONDS)
.readTimeout(5, TimeUnit.SECONDS)
.connectionPool(ConnectionPool(10, 5, TimeUnit.MINUTES))
.build()
}
fun defaultOkHttpClient(): OkHttpClient = OkHttpClient()
.newBuilder()
.connectTimeout(5, TimeUnit.SECONDS)
.readTimeout(5, TimeUnit.SECONDS)
.connectionPool(ConnectionPool(10, 5, TimeUnit.MINUTES))
.build()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package plus.maa.backend.common.utils.converter

import org.mapstruct.*
import org.mapstruct.BeanMapping
import org.mapstruct.Mapper
import org.mapstruct.Mapping
import org.mapstruct.MappingTarget
import org.mapstruct.NullValuePropertyMappingStrategy
import plus.maa.backend.controller.request.copilot.CopilotDTO
import plus.maa.backend.controller.response.copilot.CopilotInfo
import plus.maa.backend.repository.entity.Copilot
Expand Down Expand Up @@ -48,13 +52,7 @@ interface CopilotConverter {
@Mapping(target = "uploadTime", source = "now")
@Mapping(target = "firstUploadTime", source = "now")
@Mapping(target = "uploaderId", source = "userId")
fun toCopilot(
copilotDto: CopilotDTO,
copilotId: Long,
userId: String,
now: LocalDateTime,
content: String?
): Copilot
fun toCopilot(copilotDto: CopilotDTO, copilotId: Long, userId: String, now: LocalDateTime, content: String?): Copilot

@Mapping(target = "ratingType", ignore = true)
@Mapping(target = "ratingRatio", ignore = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import java.time.LocalDateTime
* create on 2024-01-01
*/
@Mapper(
componentModel = "spring", imports = [LocalDateTime::class]
componentModel = "spring",
imports = [LocalDateTime::class],
)
interface CopilotSetConverter {
@Mapping(target = "delete", ignore = true)
Expand Down
Loading

0 comments on commit 938f401

Please sign in to comment.