summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script-beta/core/diagnostics/lowercase-global.lua29
-rw-r--r--test-beta/diagnostics/init.lua5
2 files changed, 28 insertions, 6 deletions
diff --git a/script-beta/core/diagnostics/lowercase-global.lua b/script-beta/core/diagnostics/lowercase-global.lua
index bc48e1e6..c7e459cc 100644
--- a/script-beta/core/diagnostics/lowercase-global.lua
+++ b/script-beta/core/diagnostics/lowercase-global.lua
@@ -4,6 +4,18 @@ local lang = require 'language'
local config = require 'config'
local library = require 'library'
+local function isDocClass(source)
+ if not source.bindDocs then
+ return false
+ end
+ for _, doc in ipairs(source.bindDocs) do
+ if doc.type == 'doc.class' then
+ return true
+ end
+ end
+ return false
+end
+
-- 不允许定义首字母小写的全局变量(很可能是拼错或者漏删)
return function (uri, callback)
local ast = files.getAst(uri)
@@ -28,12 +40,17 @@ return function (uri, callback)
if not first then
return
end
- if first:match '%l' then
- callback {
- start = source.start,
- finish = source.finish,
- message = lang.script.DIAG_LOWERCASE_GLOBAL,
- }
+ if not first:match '%l' then
+ return
+ end
+ -- 如果赋值被标记为 doc.class ,则认为是允许的
+ if isDocClass(source) then
+ return
end
+ callback {
+ start = source.start,
+ finish = source.finish,
+ message = lang.script.DIAG_LOWERCASE_GLOBAL,
+ }
end)
end
diff --git a/test-beta/diagnostics/init.lua b/test-beta/diagnostics/init.lua
index a467276c..eb79b7c1 100644
--- a/test-beta/diagnostics/init.lua
+++ b/test-beta/diagnostics/init.lua
@@ -733,3 +733,8 @@ TEST [[
local f
f()
]]
+
+TEST [[
+---@class c
+c = {}
+]]