summaryrefslogtreecommitdiff
path: root/script/core/diagnostics/global-element.lua
diff options
context:
space:
mode:
Diffstat (limited to 'script/core/diagnostics/global-element.lua')
-rw-r--r--script/core/diagnostics/global-element.lua18
1 files changed, 18 insertions, 0 deletions
diff --git a/script/core/diagnostics/global-element.lua b/script/core/diagnostics/global-element.lua
index e9dd46ce..a30ebbc6 100644
--- a/script/core/diagnostics/global-element.lua
+++ b/script/core/diagnostics/global-element.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
+
-- If global elements are discouraged by coding convention, this diagnostic helps with reminding about that
-- Exceptions may be added to Lua.diagnostics.globals
return function (uri, callback)
@@ -26,6 +40,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)
@@ -36,6 +51,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)