mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-23 13:50:12 +08:00
Fix semantic version and plugin id regexes
This commit is contained in:
parent
14fd3015b9
commit
bace377d1e
@ -90,7 +90,7 @@ public interface PluginDescription {
|
||||
* - `v1.0` (不允许 "v")
|
||||
* - `V1.0` (不允许 "V")
|
||||
*
|
||||
* @see Semver 语义化版本. 允许 [宽松][Semver.SemverType.LOOSE] 类型版本.
|
||||
* @see SemVersion 语义化版本.
|
||||
*/
|
||||
@ResolveContext(SEMANTIC_VERSION)
|
||||
public val version: SemVersion
|
||||
@ -116,7 +116,7 @@ public interface PluginDescription {
|
||||
*
|
||||
* @see PluginDescription.id
|
||||
*/
|
||||
public val ID_REGEX: Regex = Regex("""([a-zA-Z]+(?:\.[a-zA-Z0-9]+)*)\.([a-zA-Z]+(?:-[a-zA-Z0-9]+)*)""")
|
||||
public val ID_REGEX: Regex = Regex("""([a-zA-Z][a-zA-Z0-9]*(?:\.[a-zA-Z][a-zA-Z0-9]*)*)\.([a-zA-Z][a-zA-Z0-9]*(?:-[a-zA-Z0-9]+)*)""")
|
||||
|
||||
/**
|
||||
* 在 [PluginDescription.id] 和 [PluginDescription.name] 中禁止用的完全匹配名称列表.
|
||||
|
@ -13,7 +13,7 @@ const val T = "org.example" // 编译期常量
|
||||
object MyPluginMain : KotlinPlugin(
|
||||
JvmPluginDescription(
|
||||
T,
|
||||
"1.0.0-M4",
|
||||
"1.0-M4",
|
||||
) {
|
||||
name(".")
|
||||
}
|
||||
|
@ -24,11 +24,11 @@ import org.jetbrains.kotlin.resolve.checkers.DeclarationCheckerContext
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Checks paramters with [ResolveContextKind]
|
||||
* Checks parameters with [ResolveContextKind]
|
||||
*/
|
||||
class ContextualParametersChecker : DeclarationChecker {
|
||||
companion object {
|
||||
private val ID_REGEX: Regex = Regex("""([a-zA-Z]+(?:\.[a-zA-Z0-9]+)*)\.([a-zA-Z]+(?:-[a-zA-Z0-9]+)*)""")
|
||||
private val ID_REGEX: Regex = Regex("""([a-zA-Z][a-zA-Z0-9]*(?:\.[a-zA-Z][a-zA-Z0-9]*)*)\.([a-zA-Z][a-zA-Z0-9]*(?:-[a-zA-Z0-9]+)*)""")
|
||||
private val FORBIDDEN_ID_NAMES: Array<String> = arrayOf("main", "console", "plugin", "config", "data")
|
||||
|
||||
private const val syntax = """类似于 "net.mamoe.mirai.example-plugin", 其中 "net.mamoe.mirai" 为 groupId, "example-plugin" 为插件名"""
|
||||
@ -37,7 +37,7 @@ class ContextualParametersChecker : DeclarationChecker {
|
||||
* https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
|
||||
*/
|
||||
private val SEMANTIC_VERSIONING_REGEX =
|
||||
Regex("""^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?${'$'}""")
|
||||
Regex("""^(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?${'$'}""")
|
||||
|
||||
fun checkPluginId(inspectionTarget: PsiElement, value: String): Diagnostic? {
|
||||
if (value.isBlank()) return ILLEGAL_PLUGIN_DESCRIPTION.on(inspectionTarget, "插件 Id 不能为空. \n插件 Id$syntax")
|
||||
|
Loading…
Reference in New Issue
Block a user