Strings beginning with digits can't be rewritten as syms.

Also fix a self-lint.
This commit is contained in:
Phil Hagelberg 2025-01-05 12:25:50 -08:00
parent 25196aeabf
commit 3979ab4c3c
3 changed files with 3 additions and 4 deletions

View File

@ -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"

View File

@ -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]

View File

@ -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)