fix diagnostics indent
This commit is contained in:
parent
ea89ecad9f
commit
d8f0d396a9
@ -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"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user