mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-04 16:22:25 +08:00
Allow underscore in plugin id, fix #263
This commit is contained in:
parent
0970343bdb
commit
3f98d8ec2a
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
package net.mamoe.mirai.console.plugin.description
|
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
|
||||||
import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.*
|
import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.*
|
||||||
import net.mamoe.mirai.console.plugin.Plugin
|
import net.mamoe.mirai.console.plugin.Plugin
|
||||||
@ -114,16 +115,20 @@ public interface PluginDescription {
|
|||||||
* - Group 1: 域名
|
* - Group 1: 域名
|
||||||
* - Group 2: 名称
|
* - Group 2: 名称
|
||||||
*
|
*
|
||||||
|
* ```regex
|
||||||
|
* ([a-zA-Z]\w*(?:\.[a-zA-Z]\w*)*)\.([a-zA-Z]\w*(?:-\w+)*)
|
||||||
|
* ```
|
||||||
|
*
|
||||||
* @see PluginDescription.id
|
* @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] 中禁止用的完全匹配名称列表.
|
* 在 [PluginDescription.id] 和 [PluginDescription.name] 中禁止用的完全匹配名称列表.
|
||||||
*
|
*
|
||||||
* @see PluginDescription.id
|
* @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] 的合法性
|
* 依次检查 [PluginDescription] 的 [PluginDescription.id], [PluginDescription.name], [PluginDescription.dependencies] 的合法性
|
||||||
|
20
tools/compiler-annotations/src/CheckerConstants.kt
Normal file
20
tools/compiler-annotations/src/CheckerConstants.kt
Normal 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")
|
||||||
|
}
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
package net.mamoe.mirai.console.intellij.diagnostics
|
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_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_ID
|
||||||
import net.mamoe.mirai.console.compiler.common.diagnostics.MiraiConsoleErrors.ILLEGAL_PERMISSION_NAME
|
import net.mamoe.mirai.console.compiler.common.diagnostics.MiraiConsoleErrors.ILLEGAL_PERMISSION_NAME
|
||||||
@ -76,8 +77,8 @@ class ContextualParametersChecker : DeclarationChecker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
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 ID_REGEX: Regex = CheckerConstants.PLUGIN_ID_REGEX
|
||||||
private val FORBIDDEN_ID_NAMES: Array<String> = arrayOf("main", "console", "plugin", "config", "data")
|
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" 为插件名"""
|
private const val syntax = """类似于 "net.mamoe.mirai.example-plugin", 其中 "net.mamoe.mirai" 为 groupId, "example-plugin" 为插件名"""
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user