LuaLS / LuaLS/lua-language-server
Needs a "don't use truthy types in a conditional/boolean context" diagnostic
Personne n'a encore pris cette issue.
- Langage dominant
- Lua
- Étoiles
- 4.4k
- Forks
- 442
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
### 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)
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par reproduire l’extrait Lua fourni dans un fichier Lua via l’extension Visual Studio Code, puis suivez les points d’entrée de la vérification des types et des diagnostics qui gèrent les conditions et les expressions booléennes. Le travail est terminé lorsque les cas demandés produisent les avertissements appropriés ; la portée de la demande séparée no-unparameterized-tables doit également être définie.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- lua
- Domaine
- tooling
- Type d'issue
- Fonctionnalité
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 38/100