Refactoring diagnostics

This commit is contained in:
XeroOl 2024-02-17 23:51:34 -06:00
parent 33a412e299
commit bc31279f41

View File

@ -9,8 +9,8 @@ the `file.diagnostics` field, filling it with diagnostics."
(λ unused-definition [self file symbol definition] (λ unused-definition [self file symbol definition]
"local variable that is defined but not used" "local variable that is defined but not used"
(if (and (not= "_" (: (tostring symbol) :sub 1 1)) (if (not (or (= "_" (: (tostring symbol) :sub 1 1))
(not (accumulate [reference false (accumulate [reference false
_ ref (ipairs definition.referenced-by) _ ref (ipairs definition.referenced-by)
&until reference] &until reference]
(or (= ref.ref-type :read) (or (= ref.ref-type :read)
@ -43,12 +43,11 @@ the `file.diagnostics` field, filling it with diagnostics."
(if (and (= :string (type method)) (if (and (= :string (type method))
(not (method:find "^[0-9]")) (not (method:find "^[0-9]"))
(not (method:find "[^!$%*+-/0-9<=>?A-Z\\^_a-z|\128-\255]"))) (not (method:find "[^!$%*+-/0-9<=>?A-Z\\^_a-z|\128-\255]")))
(case (message.ast->range self file call) {:range (message.ast->range self file call)
range {: range
:message (.. "unnecessary : call: use (" (tostring (. call 2)) ":" method ")") :message (.. "unnecessary : call: use (" (tostring (. call 2)) ":" method ")")
:severity message.severity.WARN :severity message.severity.WARN
:code 303 :code 303
:codeDescription "unnecessary-method"}))))) :codeDescription "unnecessary-method"}))))
(local ops {"+" 1 "-" 1 "*" 1 "/" 1 "//" 1 "%" 1 ".." 1 "and" 1 "or" 1 "band" 1 "bor" 1 "bxor" 1}) (local ops {"+" 1 "-" 1 "*" 1 "/" 1 "//" 1 "%" 1 ".." 1 "and" 1 "or" 1 "band" 1 "bor" 1 "bxor" 1})
(λ bad-unpack [self file op call] (λ bad-unpack [self file op call]
@ -63,8 +62,7 @@ the `file.diagnostics` field, filling it with diagnostics."
(sym? (. last-item 1) :table.unpack)) (sym? (. last-item 1) :table.unpack))
(. file.lexical last-item) (. file.lexical last-item)
(. file.lexical call)) (. file.lexical call))
(case (message.ast->range self file last-item) {:range (message.ast->range self file last-item)
range {: range
:message (.. "faulty unpack call: " (tostring op) " isn't variadic at runtime." :message (.. "faulty unpack call: " (tostring op) " isn't variadic at runtime."
(if (sym? op "..") (if (sym? op "..")
(let [unpackme (view (. last-item 2))] (let [unpackme (view (. last-item 2))]
@ -72,21 +70,7 @@ the `file.diagnostics` field, filling it with diagnostics."
(.. " Use a loop when you have a dynamic number of arguments to (" (tostring op) ")"))) (.. " Use a loop when you have a dynamic number of arguments to (" (tostring op) ")")))
:severity message.severity.WARN :severity message.severity.WARN
:code 304 :code 304
:codeDescription "bad-unpack"})))) :codeDescription "bad-unpack"})))
(local op-identity-value {:+ 0 :* 1 :and true :or false :band -1 :bor 0 :.. ""})
(λ op-with-no-arguments [self file op call]
(if (and (sym? op)
(. ops (tostring op))
(not (. call 2))
(. file.lexical call)
(not= nil (. op-identity-value (tostring op))))
(case (message.ast->range self file call)
range {: range
:message (.. "write " (view (. op-identity-value (tostring op))) " instead of (" (tostring op) ")")
:severity message.severity.WARN
:case 306
:codeDescription "op-with-no-arguments"})))
(λ var-never-set [self file symbol definition] (λ var-never-set [self file symbol definition]
(if (and definition.var? (not definition.var-set)) (if (and definition.var? (not definition.var-set))
@ -96,6 +80,19 @@ the `file.diagnostics` field, filling it with diagnostics."
:code 305 :code 305
:codeDescription "var-never-set"})) :codeDescription "var-never-set"}))
(local op-identity-value {:+ 0 :* 1 :and true :or false :band -1 :bor 0 :.. ""})
(λ op-with-no-arguments [self file op call]
(if (and (sym? op)
(. ops (tostring op))
(not (. call 2))
(. file.lexical call)
(not= nil (. op-identity-value (tostring op))))
{:range (message.ast->range self file call)
:message (.. "write " (view (. op-identity-value (tostring op))) " instead of (" (tostring op) ")")
:severity message.severity.WARN
:case 306
:codeDescription "op-with-no-arguments"}))
(λ check [self file] (λ check [self file]
"fill up the file.diagnostics table with linting things" "fill up the file.diagnostics table with linting things"
(let [checks self.configuration.checks (let [checks self.configuration.checks