diff --git a/src/fennel-ls/lint.fnl b/src/fennel-ls/lint.fnl index 91e96be..8468160 100644 --- a/src/fennel-ls/lint.fnl +++ b/src/fennel-ls/lint.fnl @@ -277,6 +277,33 @@ You can read more about how to add lints in docs/linting.md" :changes [{:range (message.ast->range server file ast) :newText (view (. ast 2))}]}}))}) +(add-lint :empty-do + {:what-it-does + "Warns about `do` with no body." + :why-care? + "Using `do` with no body has no effect." + :example + "```fnl + (do) + ``` + + Instead, use: + ```fnl + ;; nothing + ```" + :since "0.2.2-dev" + :type :special-call + :impl (fn [server file ast] + (case ast + (where [do* & body] + (sym? do* :do) + (not (next body))) + {: ast + :message "remove do with no body" + :fix #{:title "Remove (do)" + :changes [{:range (message.ast->range server file ast) + :newText ""}]}}))}) + (add-lint :redundant-do {:what-it-does "Identifies redundant `do` blocks within implicit do forms like `fn`, `let`, etc." diff --git a/test/lint.fnl b/test/lint.fnl index a4ce73f..9df4b06 100644 --- a/test/lint.fnl +++ b/test/lint.fnl @@ -222,6 +222,17 @@ :end {:character 8 :line 0}}}]) nil) +(fn test-empty-do [] + ;; good do + (assert-ok "(do (print 1) 2)") + ;; unnecessary one + (check "(do (do) 1 2)" + [{:code :empty-do + :message "remove do with no body" + :range {:start {:character 4 :line 0} + :end {:character 8 :line 0}}}]) + nil) + (fn test-redundant-do [] ;; good do (assert-ok "(case 134 x (do (print :x x) 11))") @@ -403,6 +414,7 @@ : test-unnecessary-method : test-unnecessary-tset : test-unnecessary-unary + : test-empty-do : test-redundant-do : test-unset-var : test-match-should-case