From d8f0d396a96d63bb79d98e720c171d2a1f67a577 Mon Sep 17 00:00:00 2001 From: XeroOl Date: Fri, 16 Feb 2024 23:00:51 -0600 Subject: [PATCH] fix diagnostics indent --- src/fennel-ls/diagnostics.fnl | 99 +++++++++++++++++------------------ 1 file changed, 49 insertions(+), 50 deletions(-) diff --git a/src/fennel-ls/diagnostics.fnl b/src/fennel-ls/diagnostics.fnl index 7138e66..fd4e7e0 100644 --- a/src/fennel-ls/diagnostics.fnl +++ b/src/fennel-ls/diagnostics.fnl @@ -9,17 +9,17 @@ the `file.diagnostics` field, filling it with diagnostics." (λ unused-definition [self file symbol definition] "local variable that is defined but not used" - (if (and (not= "_" (: (tostring symbol) :sub 1 1)) - (not (accumulate [reference false - _ ref (ipairs definition.referenced-by) - &until reference] - (or (= ref.ref-type :read) - (= ref.ref-type :mutate))))) - {:range (message.ast->range self file symbol) - :message (.. "unused definition: " (tostring symbol)) - :severity message.severity.WARN - :code 301 - :codeDescription "unused-definition"})) + (if (and (not= "_" (: (tostring symbol) :sub 1 1)) + (not (accumulate [reference false + _ ref (ipairs definition.referenced-by) + &until reference] + (or (= ref.ref-type :read) + (= ref.ref-type :mutate))))) + {:range (message.ast->range self file symbol) + :message (.. "unused definition: " (tostring symbol)) + :severity message.severity.WARN + :code 301 + :codeDescription "unused-definition"})) (λ unknown-module-field [self file] "any multisym whose definition can't be found through a (require) call" @@ -36,51 +36,50 @@ the `file.diagnostics` field, filling it with diagnostics." (λ unnecessary-method [self file colon call] "a call to the : builtin that could just be a multisym" - (if (sym? colon ":") - (let [receiver (. call 2) - method (. call 3)] - (if (and (sym? receiver) - (. file.lexical call) - (= :string (type method)) - (not (method:find "^[0-9]")) - (not (method:find "[^!$%*+-/0-9<=>?A-Z\\^_a-z|\128-\255]"))) - (case (message.ast->range self file call) - range {: range - :message (.. "unnecessary : call: use (" (tostring receiver) ":" method ")") - :severity message.severity.WARN - :code 303 - :codeDescription "unnecessary-method"}))))) + (if (and (sym? colon ":") + (sym? (. call 2)) + (. file.lexical call)) + (let [method (. call 3)] + (if (and (= :string (type method)) + (not (method:find "^[0-9]")) + (not (method:find "[^!$%*+-/0-9<=>?A-Z\\^_a-z|\128-\255]"))) + (case (message.ast->range self file call) + range {: range + :message (.. "unnecessary : call: use (" (tostring (. call 2)) ":" method ")") + :severity message.severity.WARN + :code 303 + :codeDescription "unnecessary-method"}))))) (local ops {"+" 1 "-" 1 "*" 1 "/" 1 "//" 1 "%" 1 ".." 1 "and" 1 "or" 1}) (λ bad-unpack [self file op call] "an unpack call leading into an operator" - (if (and (sym? op) - (. ops (tostring op)) - ;; last item is an unpack call - (list? (. call (length call))) - (or (sym? (. call (length call) 1) :unpack) - (sym? (. call (length call) 1) :_G.unpack) - (sym? (. call (length call) 1) :table.unpack)) - ;; Only the unpack call needs to be present in the original file. - (. file.lexical (. call (length call)))) - (case (message.ast->range self file (. call (length call))) - range {: range - :message (.. "faulty unpack call: " (tostring op) " isn't variadic at runtime." - (if (sym? op "..") - (let [unpackme (view (. call (length call) 2))] - (.. " Use (table.concat " unpackme ") instead of (.. (unpack " unpackme "))")) - (.. " Use a loop when you have a dynamic number of arguments to (" (tostring op) ")"))) - :severity message.severity.WARN - :code 304 - :codeDescription "bad-unpack"}))) + (if (and (sym? op) + (. ops (tostring op)) + ;; last item is an unpack call + (list? (. call (length call))) + (or (sym? (. call (length call) 1) :unpack) + (sym? (. call (length call) 1) :_G.unpack) + (sym? (. call (length call) 1) :table.unpack)) + ;; Only the unpack call needs to be present in the original file. + (. file.lexical (. call (length call)))) + (case (message.ast->range self file (. call (length call))) + range {: range + :message (.. "faulty unpack call: " (tostring op) " isn't variadic at runtime." + (if (sym? op "..") + (let [unpackme (view (. call (length call) 2))] + (.. " Use (table.concat " unpackme ") instead of (.. (unpack " unpackme "))")) + (.. " Use a loop when you have a dynamic number of arguments to (" (tostring op) ")"))) + :severity message.severity.WARN + :code 304 + :codeDescription "bad-unpack"}))) (λ var-never-set [self file symbol definition] - (if (and definition.var? (not definition.var-set)) - {:range (message.ast->range self file symbol) - :message (.. "var is never set: " (tostring symbol) " Consider using (local) instead of (var)") - :severity message.severity.WARN - :code 305 - :codeDescription "var-never-set"})) + (if (and definition.var? (not definition.var-set)) + {:range (message.ast->range self file symbol) + :message (.. "var is never set: " (tostring symbol) " Consider using (local) instead of (var)") + :severity message.severity.WARN + :code 305 + :codeDescription "var-never-set"})) (λ check [self file] "fill up the file.diagnostics table with linting things"