From 6325b9c6ff4436d59613db1578a37e1e2fb4a944 Mon Sep 17 00:00:00 2001 From: Michele Campeotto Date: Mon, 24 Mar 2025 07:15:31 +0100 Subject: [PATCH] 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. --- src/fennel-ls/lint.fnl | 2 +- test/lint.fnl | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/fennel-ls/lint.fnl b/src/fennel-ls/lint.fnl index 3827abe..8ba64e2 100644 --- a/src/fennel-ls/lint.fnl +++ b/src/fennel-ls/lint.fnl @@ -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 diff --git a/test/lint.fnl b/test/lint.fnl index 3faed0e..822e850 100644 --- a/test/lint.fnl +++ b/test/lint.fnl @@ -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 ) --> (set (. )) (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}