diff --git a/backend/mirai-console/src/plugin/description/PluginDescription.kt b/backend/mirai-console/src/plugin/description/PluginDescription.kt index 7c0053bae..5e164d4f9 100644 --- a/backend/mirai-console/src/plugin/description/PluginDescription.kt +++ b/backend/mirai-console/src/plugin/description/PluginDescription.kt @@ -9,6 +9,7 @@ package net.mamoe.mirai.console.plugin.description +import net.mamoe.mirai.console.compiler.common.CheckerConstants import net.mamoe.mirai.console.compiler.common.ResolveContext import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.* import net.mamoe.mirai.console.plugin.Plugin @@ -114,16 +115,20 @@ public interface PluginDescription { * - Group 1: 域名 * - Group 2: 名称 * + * ```regex + * ([a-zA-Z]\w*(?:\.[a-zA-Z]\w*)*)\.([a-zA-Z]\w*(?:-\w+)*) + * ``` + * * @see PluginDescription.id */ - 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]+)*)""") + public val ID_REGEX: Regex = CheckerConstants.PLUGIN_ID_REGEX /** * 在 [PluginDescription.id] 和 [PluginDescription.name] 中禁止用的完全匹配名称列表. * * @see PluginDescription.id */ - public val FORBIDDEN_ID_NAMES: Array = arrayOf("main", "console", "plugin", "config", "data") + public val FORBIDDEN_ID_NAMES: Array = CheckerConstants.PLUGIN_FORBIDDEN_NAMES /** * 依次检查 [PluginDescription] 的 [PluginDescription.id], [PluginDescription.name], [PluginDescription.dependencies] 的合法性 diff --git a/tools/compiler-annotations/src/CheckerConstants.kt b/tools/compiler-annotations/src/CheckerConstants.kt new file mode 100644 index 000000000..a45f7f2b8 --- /dev/null +++ b/tools/compiler-annotations/src/CheckerConstants.kt @@ -0,0 +1,20 @@ +/* + * Copyright 2020 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + */ + +package net.mamoe.mirai.console.compiler.common + +/** + * @suppress 这是内部 API. 可能在任意时刻变动 + */ +public object CheckerConstants { + @JvmField + public val PLUGIN_ID_REGEX: Regex = Regex("""([a-zA-Z]\w*(?:\.[a-zA-Z]\w*)*)\.([a-zA-Z]\w*(?:-\w+)*)""") + @JvmField + public val PLUGIN_FORBIDDEN_NAMES: Array = arrayOf("main", "console", "plugin", "config", "data") +} \ No newline at end of file diff --git a/tools/intellij-plugin/src/diagnostics/ContextualParametersChecker.kt b/tools/intellij-plugin/src/diagnostics/ContextualParametersChecker.kt index dc5f0e68b..8cf5b11ba 100644 --- a/tools/intellij-plugin/src/diagnostics/ContextualParametersChecker.kt +++ b/tools/intellij-plugin/src/diagnostics/ContextualParametersChecker.kt @@ -9,6 +9,7 @@ package net.mamoe.mirai.console.intellij.diagnostics +import net.mamoe.mirai.console.compiler.common.CheckerConstants import net.mamoe.mirai.console.compiler.common.diagnostics.MiraiConsoleErrors.ILLEGAL_COMMAND_NAME import net.mamoe.mirai.console.compiler.common.diagnostics.MiraiConsoleErrors.ILLEGAL_PERMISSION_ID import net.mamoe.mirai.console.compiler.common.diagnostics.MiraiConsoleErrors.ILLEGAL_PERMISSION_NAME @@ -76,8 +77,8 @@ 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]*)*)\.([a-zA-Z][a-zA-Z0-9]*(?:-[a-zA-Z0-9]+)*)""") - private val FORBIDDEN_ID_NAMES: Array = arrayOf("main", "console", "plugin", "config", "data") + private val ID_REGEX: Regex = CheckerConstants.PLUGIN_ID_REGEX + private val FORBIDDEN_ID_NAMES: Array = CheckerConstants.PLUGIN_FORBIDDEN_NAMES private const val syntax = """类似于 "net.mamoe.mirai.example-plugin", 其中 "net.mamoe.mirai" 为 groupId, "example-plugin" 为插件名"""