Support (or table.unpack _G.unpack) pattern without unknown field lint.

Now we are selflint clean! We can enable it in the ci target now.
This commit is contained in:
Phil Hagelberg 2025-03-02 22:05:33 -08:00
parent 356c6bcae7
commit 3a30fc83ed
4 changed files with 19 additions and 2 deletions

View File

@ -91,7 +91,7 @@ check-luarocks:
eval "$$(luarocks path)"; \ eval "$$(luarocks path)"; \
fennel-ls --lint fennel-ls --lint
ci: testall check-deps check-luarocks ci: selflint testall check-deps check-luarocks
clean: clean:
rm -fr $(EXE) old-deps old-fennel build/ rm -fr $(EXE) old-deps old-fennel build/

View File

@ -52,11 +52,19 @@ the `file.diagnostics` field, filling it with diagnostics."
#[{:range (message.ast->range server file symbol) #[{:range (message.ast->range server file symbol)
:newText (.. "_" (tostring symbol))}]))) :newText (.. "_" (tostring symbol))}])))
;; this is way too specific; it's also safe to do this inside an `if` or `case`
(fn in-or? [calls symbol]
(accumulate [in? false call (pairs calls) &until in?]
(and (sym? (. call 1) :or) (utils.find call symbol))))
(fn module-field-helper [server file symbol ?ast stack] (fn module-field-helper [server file symbol ?ast stack]
"if ?ast is a module field that isn't known, return a diagnostic" "if ?ast is a module field that isn't known, return a diagnostic"
(let [opts {} (let [opts {}
item (analyzer.search-ast server file ?ast stack opts)] item (analyzer.search-ast server file ?ast stack opts)]
(if (and (not item) (if (and (not item)
(not (in-or? file.calls symbol))
;; this doesn't necessarily have to come thru require; it works
;; for built-in modules too
opts.searched-through-require-with-stack-size-1) opts.searched-through-require-with-stack-size-1)
(diagnostic (diagnostic
{:range (message.ast->range server file symbol) {:range (message.ast->range server file symbol)

View File

@ -206,6 +206,9 @@ WARNING: this is only used in the test code, not in the real language server"
(: :gsub "/+" "/") (: :gsub "/+" "/")
(->> (pick-values 1)))) (->> (pick-values 1))))
(fn find [t x ?k]
(match (next t ?k) (k x) k (k y_) (find t x k)))
{: uri->path {: uri->path
: path->uri : path->uri
: pos->position : pos->position
@ -220,4 +223,5 @@ WARNING: this is only used in the test code, not in the real language server"
: absolute-path? : absolute-path?
: path-join : path-join
: path-sep : path-sep
: endswith} : endswith
: find}

View File

@ -156,6 +156,11 @@
[{:message "unknown identifier: unpack"} [{:message "unknown identifier: unpack"}
{:message "unknown identifier: warn"}] {:message "unknown identifier: warn"}]
{:lua-version "union"}) {:lua-version "union"})
;; can reference table.unpack in an or
(check "(print (or table.unpack _G.unpack))"
[]
[{:message "unknown field: table.unpack"}]
{:lua-version "intersection"})
;; deprecated functions still work ;; deprecated functions still work
(check "(print (math.atan2 (tonumber (io.read))))" (check "(print (math.atan2 (tonumber (io.read))))"
[] []