LuaLS / LuaLS/lua-language-server

Needs a "don't use truthy types in a conditional/boolean context" diagnostic

オープン
#2,609 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
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:
```lua
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

1. Type the following into a lua file:
```lua
---@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
```
2. 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)

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、提供された Lua スニペットを Visual Studio Code 拡張機能を通じて Lua ファイルで再現し、次に条件分岐とブール式を処理する型チェックおよび診断のエントリーポイントを追跡します。要求されたケースで適切な警告が生成されれば完了です。別個の no-unparameterized-tables リクエストについても、その対象範囲を決める必要があります。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
lua
領域
tooling
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。