Skip to content

Commit 1c02832

Browse files
authored
Merge pull request #3128 from ribru17/unnecessary_assert
Diagnostics for unnecessary assert
2 parents 61e6fa9 + fa8cb8f commit 1c02832

File tree

16 files changed

+135
-0
lines changed

16 files changed

+135
-0
lines changed

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44
<!-- Add all new changes here. They will be moved under a version at release -->
5+
`2025-3-13`
6+
* `NEW` `unnecessary-assert` diagnostic warns when asserting values that are always truthy
57
* `NEW` locale `es-419`, thanks [Felipe Lema](https://codeberg.org/FelipeLema)
68

79
## 3.13.9

locale/en-us/script.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ DIAG_OVER_MAX_ARGS =
3636
'This function expects a maximum of {:d} argument(s) but instead it is receiving {:d}.'
3737
DIAG_MISS_ARGS =
3838
'This function requires {:d} argument(s) but instead it is receiving {:d}.'
39+
DIAG_UNNECESSARY_ASSERT =
40+
'Unnecessary assert: this expression is always truthy.'
3941
DIAG_OVER_MAX_VALUES =
4042
'Only has {} variables, but you set {} values.'
4143
DIAG_AMBIGUITY_1 =

locale/en-us/setting.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,8 @@ config.diagnostics['missing-return-value'] =
406406
'Enable diagnostics for return statements without values although the containing function declares returns.'
407407
config.diagnostics['need-check-nil'] =
408408
'Enable diagnostics for variable usages if `nil` or an optional (potentially `nil`) value was assigned to the variable before.'
409+
config.diagnostics['unnecessary-assert'] =
410+
'Enable diagnostics for redundant assertions on truthy values.'
409411
config.diagnostics['no-unknown'] =
410412
'Enable diagnostics for cases in which the type cannot be inferred.'
411413
config.diagnostics['not-yieldable'] =

locale/ja-jp/script.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ DIAG_OVER_MAX_ARGS =
3636
'この関数は最大で {:d} 個の引数を受け取りますが、{:d} 個の引数が渡されています。'
3737
DIAG_MISS_ARGS =
3838
'この関数は少なくとも {:d} 個の引数を必要としますが、{:d} 個しか渡されていません。'
39+
DIAG_UNNECESSARY_ASSERT =
40+
'不要なアサーション: この式は常に真です。'
3941
DIAG_OVER_MAX_VALUES =
4042
'変数は {} 個しかありませんが、{} 個の値が設定されています。'
4143
DIAG_AMBIGUITY_1 =

locale/ja-jp/setting.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,8 @@ config.diagnostics['missing-return-value'] = -- TODO: need translate!
406406
'Enable diagnostics for return statements without values although the containing function declares returns.'
407407
config.diagnostics['need-check-nil'] = -- TODO: need translate!
408408
'Enable diagnostics for variable usages if `nil` or an optional (potentially `nil`) value was assigned to the variable before.'
409+
config.diagnostics['unnecessary-assert'] = -- TODO: need translate!
410+
'Enable diagnostics for redundant assertions on truthy values.'
409411
config.diagnostics['no-unknown'] = -- TODO: need translate!
410412
'Enable diagnostics for cases in which the type cannot be inferred.'
411413
config.diagnostics['not-yieldable'] = -- TODO: need translate!

locale/pt-br/script.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ DIAG_OVER_MAX_ARGS =
3636
'A função aceita apenas os parâmetros {:d}, mas você passou {:d}.'
3737
DIAG_MISS_ARGS =
3838
'A função recebe pelo menos {:d} argumentos, mas há {:d}.'
39+
DIAG_UNNECESSARY_ASSERT =
40+
'Asserção desnecessária: esta expressão é sempre verdadeira.'
3941
DIAG_OVER_MAX_VALUES =
4042
'Apenas há {} variáveis, mas você declarou {} valores.'
4143
DIAG_AMBIGUITY_1 =

locale/pt-br/setting.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,8 @@ config.diagnostics['missing-return-value'] = -- TODO: need translate!
406406
'Enable diagnostics for return statements without values although the containing function declares returns.'
407407
config.diagnostics['need-check-nil'] = -- TODO: need translate!
408408
'Enable diagnostics for variable usages if `nil` or an optional (potentially `nil`) value was assigned to the variable before.'
409+
config.diagnostics['unnecessary-assert'] = -- TODO: need translate!
410+
'Enable diagnostics for redundant assertions on truthy values.'
409411
config.diagnostics['no-unknown'] = -- TODO: need translate!
410412
'Enable diagnostics for cases in which the type cannot be inferred.'
411413
config.diagnostics['not-yieldable'] = -- TODO: need translate!

locale/zh-cn/script.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ DIAG_OVER_MAX_ARGS =
3636
'函数最多接收 {:d} 个参数,但获得了 {:d} 个。'
3737
DIAG_MISS_ARGS =
3838
'函数最少接收 {:d} 个参数,但获得了 {:d} 个。'
39+
DIAG_UNNECESSARY_ASSERT =
40+
'不必要的断言:此表达式始终为真值。'
3941
DIAG_OVER_MAX_VALUES =
4042
'只有 {} 个变量,但你设置了 {} 个值。'
4143
DIAG_AMBIGUITY_1 =

locale/zh-cn/setting.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ config.diagnostics['missing-return-value'] =
404404
'函数无值返回但函数使用`@return`标记了返回值'
405405
config.diagnostics['need-check-nil'] =
406406
'变量之前被赋值为`nil`或可选值(可能为 `nil`)'
407+
config.diagnostics['unnecessary-assert'] =
408+
'启用对冗余断言(针对始终为真值的表达式)的诊断'
407409
config.diagnostics['no-unknown'] =
408410
'变量的未知类型无法推断'
409411
config.diagnostics['not-yieldable'] =

locale/zh-tw/script.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ DIAG_OVER_MAX_ARGS =
3636
'函式最多接收 {:d} 個引數,但獲得了 {:d} 個。'
3737
DIAG_MISS_ARGS =
3838
'函式最少接收 {:d} 個引數,但獲得了 {:d} 個。'
39+
DIAG_UNNECESSARY_ASSERT =
40+
'不必要的斷言:此表達式始終為真值。'
3941
DIAG_OVER_MAX_VALUES =
4042
'只有 {} 個變數,但你設定了 {} 個值。'
4143
DIAG_AMBIGUITY_1 =

0 commit comments

Comments
 (0)