clean up some documentation and code
This commit is contained in:
parent
5a2e6ef091
commit
ea826576e3
@ -112,5 +112,8 @@ The return value should have these fields:
|
|||||||
add a "fix" field with the code to generate a quickfix. See the other lints
|
add a "fix" field with the code to generate a quickfix. See the other lints
|
||||||
for examples.
|
for examples.
|
||||||
|
|
||||||
### Testing:
|
### Other places:
|
||||||
I will think about this later. :) For now see examples in `test/lint.fnl`.
|
At some point I want to add doc-testing of the :example documentation, but for
|
||||||
|
now, you have to add your tests manually to `test/lint.fnl`.
|
||||||
|
|
||||||
|
If you add a lint, also add it to changelog.md.
|
||||||
|
|||||||
@ -116,8 +116,8 @@ find the definition `10`, but if `opts.stop-early?` is set, it would find
|
|||||||
(if (= 0 (length stack))
|
(if (= 0 (length stack))
|
||||||
{:definition symbol : file}
|
{:definition symbol : file}
|
||||||
nil)
|
nil)
|
||||||
(if (. file.references symbol)
|
(. file.references symbol)
|
||||||
(search-reference server file (. file.references symbol) (stack-add-multisym! stack symbol) opts))))
|
(search-reference server file (. file.references symbol) (stack-add-multisym! stack symbol) opts)))
|
||||||
|
|
||||||
(λ search-table [server file tbl stack opts]
|
(λ search-table [server file tbl stack opts]
|
||||||
(if (. tbl (. stack (length stack)))
|
(if (. tbl (. stack (length stack)))
|
||||||
@ -304,8 +304,8 @@ returns the called symbol and the number of the argument closest to byte"
|
|||||||
(λ find-list [[call & parents]]
|
(λ find-list [[call & parents]]
|
||||||
(if (. file.calls call)
|
(if (. file.calls call)
|
||||||
call
|
call
|
||||||
(if (next parents)
|
(next parents)
|
||||||
(find-list parents))))
|
(find-list parents)))
|
||||||
|
|
||||||
(λ arg-index [call byte]
|
(λ arg-index [call byte]
|
||||||
;; TODO: special handling for binding forms so we can point to the
|
;; TODO: special handling for binding forms so we can point to the
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
"Diagnostics
|
"Lint
|
||||||
Provides the function (check server file), which goes through a file and mutates
|
Provides the function (add-lint-diagnostics server file), which goes through
|
||||||
the `file.diagnostics` field, filling it with diagnostics."
|
a file and fills the `file.diagnostics` field with diagnostics.
|
||||||
|
|
||||||
|
You can read more about how to add lints in docs/linting.md"
|
||||||
|
|
||||||
(local {: sym? : list? : table? : varg? : view
|
(local {: sym? : list? : table? : varg? : view
|
||||||
: sym : list &as fennel} (require :fennel))
|
: sym : list &as fennel} (require :fennel))
|
||||||
@ -23,8 +25,6 @@ the `file.diagnostics` field, filling it with diagnostics."
|
|||||||
|
|
||||||
(fn add-lint [name lint ...]
|
(fn add-lint [name lint ...]
|
||||||
(when (= nil lint.type) (error (.. name " needs a type. available types: " (view (icollect [k (pairs lints)] k)))))
|
(when (= nil lint.type) (error (.. name " needs a type. available types: " (view (icollect [k (pairs lints)] k)))))
|
||||||
;; lint.limitations is optional
|
|
||||||
|
|
||||||
(table.insert all-lints lint)
|
(table.insert all-lints lint)
|
||||||
(for [i 1 (select :# lint ...)]
|
(for [i 1 (select :# lint ...)]
|
||||||
(let [lint (select i lint ...)]
|
(let [lint (select i lint ...)]
|
||||||
@ -265,7 +265,7 @@ the `file.diagnostics` field, filling it with diagnostics."
|
|||||||
:newText (view (. ast 2))}]}}))})
|
:newText (view (. ast 2))}]}}))})
|
||||||
|
|
||||||
(local implicit-do-forms (collect [form {: body-form?} (pairs (fennel.syntax))]
|
(local implicit-do-forms (collect [form {: body-form?} (pairs (fennel.syntax))]
|
||||||
(values form body-form?)))
|
form body-form?))
|
||||||
|
|
||||||
(add-lint :redundant-do
|
(add-lint :redundant-do
|
||||||
{:what-it-does
|
{:what-it-does
|
||||||
@ -629,6 +629,8 @@ the `file.diagnostics` field, filling it with diagnostics."
|
|||||||
0 ; method call; the head counts as an argument
|
0 ; method call; the head counts as an argument
|
||||||
1)) ; function call; the head doesn't count as an argument
|
1)) ; function call; the head doesn't count as an argument
|
||||||
passes-extra-args (and (not= 1 (length ast))
|
passes-extra-args (and (not= 1 (length ast))
|
||||||
|
(not (special? (. ast 1)))
|
||||||
|
(not (. file.macro-calls ast))
|
||||||
(possibly-multival? (. ast (length ast))))
|
(possibly-multival? (. ast (length ast))))
|
||||||
min-params (accumulate [last-required-argument nil
|
min-params (accumulate [last-required-argument nil
|
||||||
i arg (ipairs signature)
|
i arg (ipairs signature)
|
||||||
@ -646,6 +648,7 @@ the `file.diagnostics` field, filling it with diagnostics."
|
|||||||
;; TODO Fennel 1.5.4+ has `fn`'s arglist fixed
|
;; TODO Fennel 1.5.4+ has `fn`'s arglist fixed
|
||||||
;; exception: fn only needs one argument
|
;; exception: fn only needs one argument
|
||||||
(= result (docs.get-builtin server :fn)) 1
|
(= result (docs.get-builtin server :fn)) 1
|
||||||
|
(= result (docs.get-builtin server :collect)) 2
|
||||||
(or min-params 0))]
|
(or min-params 0))]
|
||||||
(if (and (< number-of-args min-params)
|
(if (and (< number-of-args min-params)
|
||||||
(not passes-extra-args))
|
(not passes-extra-args))
|
||||||
@ -797,9 +800,8 @@ the `file.diagnostics` field, filling it with diagnostics."
|
|||||||
(table.insert file.diagnostics
|
(table.insert file.diagnostics
|
||||||
(wrap (doto diagnostic
|
(wrap (doto diagnostic
|
||||||
(tset :code lint.name))))))))
|
(tset :code lint.name))))))))
|
||||||
(each [diagnostic (coroutine.wrap #(run lints.other server file))]
|
(icollect [diagnostic (coroutine.wrap #(run lints.other server file)) &into file.diagnostics]
|
||||||
(table.insert file.diagnostics
|
(wrap diagnostic))
|
||||||
(wrap diagnostic)))
|
|
||||||
(each [symbol definition (pairs file.definitions)]
|
(each [symbol definition (pairs file.definitions)]
|
||||||
(when (. file.lexical symbol)
|
(when (. file.lexical symbol)
|
||||||
(run lints.definition server file symbol definition)))
|
(run lints.definition server file symbol definition)))
|
||||||
|
|||||||
@ -14,15 +14,15 @@ I suspect this file may be gone after a bit of refactoring."
|
|||||||
(let [result []]
|
(let [result []]
|
||||||
(each [path (path:gmatch "[^;]+")]
|
(each [path (path:gmatch "[^;]+")]
|
||||||
(if (absolute-path? path)
|
(if (absolute-path? path)
|
||||||
(table.insert result path)
|
(table.insert result path)
|
||||||
(each [_ workspace (ipairs (or ?workspaces []))]
|
(icollect [_ workspace (ipairs (or ?workspaces [])) &into result]
|
||||||
(table.insert result (path-join (uri->path workspace) path)))))
|
(path-join (uri->path workspace) path))))
|
||||||
(table.concat result ";")))
|
(table.concat result ";")))
|
||||||
|
|
||||||
(fn file-exists? [server uri]
|
(fn file-exists? [server uri]
|
||||||
(or (?. server.preload uri)
|
(or (?. server.preload uri)
|
||||||
(case (io.open (uri->path uri))
|
(case (io.open (uri->path uri))
|
||||||
f (do (f:close) true))))
|
f (do (f:close) true))))
|
||||||
|
|
||||||
(λ lookup [{:configuration {: fennel-path : macro-path} :root-uri ?root-uri &as server} mod macro?]
|
(λ lookup [{:configuration {: fennel-path : macro-path} :root-uri ?root-uri &as server} mod macro?]
|
||||||
"Use the configured path to find a file on disk"
|
"Use the configured path to find a file on disk"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user