Fix operator with no arguments lint incorrect report.

Operator with no arguments check failed when the first argument to the
operator was falsy. We might want to have a new lint to check for
"always false/true" expressions but this report was incorrect and the
quickfix replaced incorrect code.
This commit is contained in:
Michele Campeotto 2025-03-24 07:15:31 +01:00 committed by Phil Hagelberg
parent b0ba117232
commit 6325b9c6ff
2 changed files with 14 additions and 3 deletions

View File

@ -181,7 +181,7 @@ the `file.diagnostics` field, filling it with diagnostics."
"A call like (+) that could be replaced with a literal"
(let [identity (. op-identity-value (tostring op))]
(if (and (op? op)
(not (. call 2))
(= 1 (length call))
(. file.lexical call)
(not= nil identity))
(diagnostic

View File

@ -252,6 +252,17 @@
:end {:character 6 :line 0}}}])
nil)
(fn test-op-with-no-arguments []
(assert-ok "(and 1)")
(assert-ok "(and false 1)")
(assert-ok "(and nil 1)")
(check "(and)"
{:message "write true instead of (and)"
:code :op-with-no-arguments
:range {:start {:characer 0 :line 0}
:end {:character 5 :line 0}}})
nil)
;; TODO lints:
;; duplicate keys in kv table
;; (tset <sym> <any>) --> (set (. <sym> <any>)) (might be wanted for compat?)
@ -274,5 +285,5 @@
: test-unset-var
: test-match-should-case
: test-unpack-into-op
: test-unpack-in-middle}
: test-unpack-in-middle
: test-op-with-no-arguments}