Unknown field lint only triggers at stack size 1
This is probably not a good commit message, but basically, if you require a module foo, and then look for foo.bar.baz, it won't trigger, but foo.bar will trigger it.
This commit is contained in:
parent
3f5984df06
commit
e0067880d1
@ -65,17 +65,18 @@ find the definition `10`, but if `opts.stop-early?` is set, it would find
|
|||||||
(stack-add-split! stack (utils.multi-sym-split symbol)))
|
(stack-add-split! stack (utils.multi-sym-split symbol)))
|
||||||
|
|
||||||
(λ search-document [self document stack opts]
|
(λ search-document [self document stack opts]
|
||||||
(when (not= (tostring (?. document :binding)) :_G)
|
(when (and (not= (tostring (?. document :binding)) :_G)
|
||||||
(set opts.searched-through-require true))
|
(= (length stack) 1))
|
||||||
|
(set opts.searched-through-require-with-stack-size-1 true))
|
||||||
(if (= 0 (length stack))
|
(if (= 0 (length stack))
|
||||||
document
|
document
|
||||||
(and document.fields
|
(and document.fields
|
||||||
(. document.fields (. stack (length stack))))
|
(. document.fields (. stack (length stack))))
|
||||||
(search-document self (. document.fields (table.remove stack)) stack opts)))
|
(search-document self (. document.fields (table.remove stack)) stack opts)))
|
||||||
|
|
||||||
(λ search-val [self file ast stack opts]
|
(λ search-val [self file ?ast stack opts]
|
||||||
"searches for the definition of the ast, adjusted to 1 value"
|
"searches for the definition of the ast, adjusted to 1 value"
|
||||||
(search-multival self file ast stack 1 opts))
|
(search-multival self file ?ast stack 1 opts))
|
||||||
|
|
||||||
(λ search-assignment [self file assignment stack opts]
|
(λ search-assignment [self file assignment stack opts]
|
||||||
(let [{:target {:binding _
|
(let [{:target {:binding _
|
||||||
@ -130,7 +131,9 @@ find the definition `10`, but if `opts.stop-early?` is set, it would find
|
|||||||
(let [newfile (state.get-by-module self mod)]
|
(let [newfile (state.get-by-module self mod)]
|
||||||
(when newfile
|
(when newfile
|
||||||
(let [newitem (. newfile.ast (length newfile.ast))]
|
(let [newitem (. newfile.ast (length newfile.ast))]
|
||||||
(search-val self newfile newitem stack (doto opts (tset :searched-through-require true)))))))))
|
(when (= (length stack) 1)
|
||||||
|
(set opts.searched-through-require-with-stack-size-1 true))
|
||||||
|
(search-val self newfile newitem stack opts)))))))
|
||||||
"."
|
"."
|
||||||
(if (= multival 1)
|
(if (= multival 1)
|
||||||
(let [[_ & rest] call]
|
(let [[_ & rest] call]
|
||||||
@ -149,7 +152,8 @@ find the definition `10`, but if `opts.stop-early?` is set, it would find
|
|||||||
{:definition call : file}))))) ;; BASE CASE!!
|
{:definition call : file}))))) ;; BASE CASE!!
|
||||||
|
|
||||||
(set search-multival
|
(set search-multival
|
||||||
(λ [self file ast stack multival opts]
|
(λ [self file ?ast stack multival opts]
|
||||||
|
(let [ast ?ast] ;; it was a bad idea to use λ because ast may be nil
|
||||||
(if (list? ast) (search-list self file ast stack multival opts)
|
(if (list? ast) (search-list self file ast stack multival opts)
|
||||||
(varg? ast) nil ;; TODO function-args
|
(varg? ast) nil ;; TODO function-args
|
||||||
(= 1 multival)
|
(= 1 multival)
|
||||||
@ -157,7 +161,7 @@ find the definition `10`, but if `opts.stop-early?` is set, it would find
|
|||||||
(= 0 (length stack)) {:definition ast : file} ;; BASE CASE !!
|
(= 0 (length stack)) {:definition ast : file} ;; BASE CASE !!
|
||||||
(= :table (type ast)) (search-table self file ast stack opts)
|
(= :table (type ast)) (search-table self file ast stack opts)
|
||||||
(= :string (type ast)) (search-document self (docs.get-global self :string) stack opts))
|
(= :string (type ast)) (search-document self (docs.get-global self :string) stack opts))
|
||||||
nil)))
|
nil))))
|
||||||
|
|
||||||
|
|
||||||
;; the options thing is getting out of hand
|
;; the options thing is getting out of hand
|
||||||
|
|||||||
@ -47,7 +47,7 @@ the `file.diagnostics` field, filling it with diagnostics."
|
|||||||
(if (. (utils.multi-sym-split symbol) 2)
|
(if (. (utils.multi-sym-split symbol) 2)
|
||||||
(let [opts {}
|
(let [opts {}
|
||||||
item (language.search-ast self file symbol [] opts)]
|
item (language.search-ast self file symbol [] opts)]
|
||||||
(if (and (not item) opts.searched-through-require)
|
(if (and (not item) opts.searched-through-require-with-stack-size-1)
|
||||||
{:range (message.ast->range self file symbol)
|
{:range (message.ast->range self file symbol)
|
||||||
:message (.. "unknown field: " (tostring symbol))
|
:message (.. "unknown field: " (tostring symbol))
|
||||||
:severity message.severity.WARN
|
:severity message.severity.WARN
|
||||||
|
|||||||
@ -98,6 +98,12 @@
|
|||||||
(check "_G.insert2"
|
(check "_G.insert2"
|
||||||
[]
|
[]
|
||||||
[{:code 302}])
|
[{:code 302}])
|
||||||
|
;; we don't care about nested
|
||||||
|
(check {:requireme.fnl "{:field []}"
|
||||||
|
:main.fnl "(local {: field} (require :requireme))
|
||||||
|
field.unknown"}
|
||||||
|
[]
|
||||||
|
[{:code 302}])
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
(fn test-unnecessary-colon []
|
(fn test-unnecessary-colon []
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user