summaryrefslogtreecommitdiff
path: root/script/core/diagnostics/lowercase-global.lua
diff options
context:
space:
mode:
Diffstat (limited to 'script/core/diagnostics/lowercase-global.lua')
-rw-r--r--script/core/diagnostics/lowercase-global.lua18
1 files changed, 18 insertions, 0 deletions
diff --git a/script/core/diagnostics/lowercase-global.lua b/script/core/diagnostics/lowercase-global.lua
index 68bec234..c7e9294d 100644
--- a/script/core/diagnostics/lowercase-global.lua
+++ b/script/core/diagnostics/lowercase-global.lua
@@ -17,6 +17,20 @@ local function isDocClass(source)
return false
end
+local function isGlobalRegex(name, definedGlobalRegex)
+ if not definedGlobalRegex then
+ return false
+ end
+
+ for _, pattern in ipairs(definedGlobalRegex) do
+ if name:match(pattern) then
+ return true
+ end
+ end
+
+ return false
+end
+
-- 不允许定义首字母小写的全局变量(很可能是拼错或者漏删)
return function (uri, callback)
local ast = files.getState(uri)
@@ -25,6 +39,7 @@ return function (uri, callback)
end
local definedGlobal = util.arrayToHash(config.get(uri, 'Lua.diagnostics.globals'))
+ local definedGlobalRegex = config.get(uri, 'Lua.diagnostics.globalsRegex')
guide.eachSourceType(ast.ast, 'setglobal', function (source)
local name = guide.getKeyName(source)
@@ -42,6 +57,9 @@ return function (uri, callback)
if isDocClass(source) then
return
end
+ if isGlobalRegex(name, definedGlobalRegex) then
+ return
+ end
if definedGlobal[name] == nil then
definedGlobal[name] = false
local global = vm.getGlobal('variable', name)