From 3979ab4c3c7b1fe401543d220087a3b2d9dc8272 Mon Sep 17 00:00:00 2001 From: Phil Hagelberg Date: Sun, 5 Jan 2025 12:25:50 -0800 Subject: [PATCH] Strings beginning with digits can't be rewritten as syms. Also fix a self-lint. --- src/fennel-ls/analyzer.fnl | 3 +-- src/fennel-ls/lint.fnl | 2 +- test/lint.fnl | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/fennel-ls/analyzer.fnl b/src/fennel-ls/analyzer.fnl index be1f8b4..10c2cf6 100644 --- a/src/fennel-ls/analyzer.fnl +++ b/src/fennel-ls/analyzer.fnl @@ -73,8 +73,7 @@ find the definition `10`, but if `opts.stop-early?` is set, it would find (. document.fields (. stack (length stack)))) (search-document server (. document.fields (table.remove stack)) stack opts) (not document.fields) - (do - (set opts.searched-through-require-indeterminate true)))) + (set opts.searched-through-require-indeterminate true))) (λ search-val [server file ?ast stack opts] "searches for the definition of the ast, adjusted to 1 value" diff --git a/src/fennel-ls/lint.fnl b/src/fennel-ls/lint.fnl index 7602064..0efde9a 100644 --- a/src/fennel-ls/lint.fnl +++ b/src/fennel-ls/lint.fnl @@ -26,7 +26,7 @@ the `file.diagnostics` field, filling it with diagnostics." item)) (fn could-be-rewritten-as-sym? [str] - (and (= :string (type str)) + (and (= :string (type str)) (not (str:find "^%d")) (not (str:find "[^!$%*+/0-9<=>?A-Z\\^_a-z|\128-\255-]")))) (λ unused-definition [server file symbol definition] diff --git a/test/lint.fnl b/test/lint.fnl index b82ebbc..50aebdf 100644 --- a/test/lint.fnl +++ b/test/lint.fnl @@ -179,7 +179,7 @@ :end {:character 32 :line 0}}}]) ;; Lint only triggers on keys that can be written as a sym (check "(local tbl {}) (tset tbl \"hello-world\" 249)" [{:code 309}]) - (check "(local tbl {}) (tset tbl \"01234567\" 249)" [{:code 309}]) + (assert-ok "(local tbl {}) (tset tbl \"01234567\" 249)") (assert-ok "(local tbl {}) (tset tbl \"hello world\" 1)") (assert-ok "(local tbl {}) (tset tbl \"0123.4567\" 1)") nil)