nixos/lua-lsp/script/core/diagnostics/empty-block.lua

55 lines
1.5 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local files = require 'files'
local guide = require 'parser.guide'
local lang = require 'language'
local define = require 'proto.define'
local await = require 'await'
-- 检查空代码块
-- 但是排除忙等待repeat/while)
---@async
return function (uri, callback)
local ast = files.getState(uri)
if not ast then
return
end
await.delay()
guide.eachSourceType(ast.ast, 'if', function (source)
for _, block in ipairs(source) do
if #block > 0 then
return
end
end
callback {
start = source.start,
finish = source.finish,
tags = { define.DiagnosticTag.Unnecessary },
message = lang.script.DIAG_EMPTY_BLOCK,
}
end)
await.delay()
guide.eachSourceType(ast.ast, 'loop', function (source)
if #source > 0 then
return
end
callback {
start = source.start,
finish = source.finish,
tags = { define.DiagnosticTag.Unnecessary },
message = lang.script.DIAG_EMPTY_BLOCK,
}
end)
await.delay()
guide.eachSourceType(ast.ast, 'in', function (source)
if #source > 0 then
return
end
callback {
start = source.start,
finish = source.finish,
tags = { define.DiagnosticTag.Unnecessary },
message = lang.script.DIAG_EMPTY_BLOCK,
}
end)
end