LuaLS / LuaLS/lua-language-server
Needs a "don't use truthy types in a conditional/boolean context" diagnostic
还没有人认领这个 Issue。
- 主要语言
- Lua
- 星标
- 4.4k
- 派生
- 442
- PR 合并指标
- 30 天内没有已合并 PR
描述
How are you using the lua-language-server?
Visual Studio Code Extension (sumneko.lua)
Which OS are you using?
Windows
What is the issue affecting?
Type Checking, Diagnostics/Syntax Checking
Expected Behaviour
When variable a has a truthy type (e.g. any type that does not contain boolean or nil), then the following lines should all give warnings, since (assuming the type annotations are correct and Weak Nil Check is off) a cannot be nil or false, and thus can never resolve to false in a boolean context, and so the operations are pointless:
if a then print("1") end -- will always print 1
if not a then print("2") end -- will never print 2
local b = a or "3" -- equivalent to b = a
local c = a and "4" or "5" -- equivalent to c = "4"
Actual Behaviour
None of those lines warn you about anything under the current diagnostics
Reproduction steps
- Type the following into a lua file:
---@param a number (or string, table, etc.)
function A(a)
if a then print("1") end
if not a then print("2") end
local b = a or "3"
local c = a and "4" or "5"
end
- Observe the lack of diagnostic warnings on each line inside the function
(I would also like a "no-unparameterized-tables" diagnostic where plain table without any <> does not count as a valid type)
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先,通过 Visual Studio Code 扩展在 Lua 文件中复现所提供的 Lua 代码片段,然后追踪处理条件语句和布尔表达式的类型检查与诊断入口点。完成的标准是所请求的情况能够产生适当的警告;此外,还需要确定单独的 no-unparameterized-tables 请求的范围。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- lua
- 领域
- tooling
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100