Skip to content
This repository has been archived by the owner on Feb 10, 2023. It is now read-only.

Commit

Permalink
Fix semantic version and plugin id regexes
Browse files Browse the repository at this point in the history
  • Loading branch information
Him188 committed Oct 28, 2020
1 parent 14fd301 commit bace377
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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] 中禁止用的完全匹配名称列表.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const val T = "org.example" // 编译期常量
object MyPluginMain : KotlinPlugin(
JvmPluginDescription(
T,
"1.0.0-M4",
"1.0-M4",
) {
name(".")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" 为插件名"""
Expand All @@ -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")
Expand Down

0 comments on commit bace377

Please sign in to comment.