Allow underscore in plugin id, fix #263

This commit is contained in:
Him188 2021-02-01 09:13:42 +08:00
parent 0970343bdb
commit 3f98d8ec2a
3 changed files with 30 additions and 4 deletions

View File

@ -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<String> = arrayOf("main", "console", "plugin", "config", "data")
public val FORBIDDEN_ID_NAMES: Array<String> = CheckerConstants.PLUGIN_FORBIDDEN_NAMES
/**
* 依次检查 [PluginDescription] [PluginDescription.id], [PluginDescription.name], [PluginDescription.dependencies] 的合法性

View File

@ -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<String> = arrayOf("main", "console", "plugin", "config", "data")
}

View File

@ -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<String> = arrayOf("main", "console", "plugin", "config", "data")
private val ID_REGEX: Regex = CheckerConstants.PLUGIN_ID_REGEX
private val FORBIDDEN_ID_NAMES: Array<String> = CheckerConstants.PLUGIN_FORBIDDEN_NAMES
private const val syntax = """类似于 "net.mamoe.mirai.example-plugin", 其中 "net.mamoe.mirai" 为 groupId, "example-plugin" 为插件名"""