summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-06-27 01:16:01 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-06-27 01:16:01 +0800
commit24f2bab098c176acdd58a5dc82ec037b2ded8eeb (patch)
tree1d58183a931aa69e3231de6fcec5b85f19b06224
parent92b2a185af2d31dd353ef8a7d57469ee9d584cb7 (diff)
downloadlua-language-server-24f2bab098c176acdd58a5dc82ec037b2ded8eeb.zip
disable `unused-local` for empty function
-rw-r--r--script/core/diagnostics/unused-local.lua18
-rw-r--r--test/diagnostics/common.lua20
2 files changed, 14 insertions, 24 deletions
diff --git a/script/core/diagnostics/unused-local.lua b/script/core/diagnostics/unused-local.lua
index d12ceb2b..a637f427 100644
--- a/script/core/diagnostics/unused-local.lua
+++ b/script/core/diagnostics/unused-local.lua
@@ -63,18 +63,16 @@ local function isDocClass(source)
return false
end
-local function isDocParam(source)
- if not source.bindDocs then
+---@param source parser.object
+local function isDeclareFunctionParam(source)
+ if source.parent.type ~= 'funcargs' then
return false
end
- for _, doc in ipairs(source.bindDocs) do
- if doc.type == 'doc.param' then
- if doc.param[1] == source[1] then
- return true
- end
- end
+ local func = source.parent.parent
+ if #func > 0 then
+ return false
end
- return false
+ return true
end
return function (uri, callback)
@@ -94,7 +92,7 @@ return function (uri, callback)
if isDocClass(source) then
return
end
- if vm.isMetaFile(uri) and isDocParam(source) then
+ if isDeclareFunctionParam(source) then
return
end
local data = hasGet(source)
diff --git a/test/diagnostics/common.lua b/test/diagnostics/common.lua
index 1f8a782d..759039a6 100644
--- a/test/diagnostics/common.lua
+++ b/test/diagnostics/common.lua
@@ -439,12 +439,14 @@ local <!x!> = {}
TEST [[
local function f(<!self!>)
+ return 'something'
end
f()
]]
TEST [[
local function f(<!...!>)
+ return 'something'
end
f()
]]
@@ -1047,20 +1049,6 @@ end
]]
TEST [[
----@param a number
-return function (<!a!>)
-end
-]]
-
-TEST [[
----@meta
-
----@param a number
-return function (a)
-end
-]]
-
-TEST [[
local m = {}
function <!m:fff!>()
@@ -1703,3 +1691,7 @@ function t:init() end
<!t.init()!>
]]
+
+TEST [[
+return function f(x, y, z) end
+]]