Last active
April 25, 2023 09:24
-
-
Save pfitzseb/22493b0214276d3b65833232aa94bf11 to your computer and use it in GitHub Desktop.
Lint a Julia project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using LanguageServer, StaticLint, SymbolServer | |
path = abspath(ARGS[1]) | |
root_file = if length(ARGS) > 1 | |
abspath(ARGS[2]) | |
else | |
joinpath(path, "src", string(basename(path), ".jl")) | |
end | |
s = LanguageServerInstance(Pipe(), stdout, path) | |
_, symbols = SymbolServer.getstore(s.symbol_server, path) | |
s.global_env.symbols = symbols | |
s.global_env.extended_methods = SymbolServer.collect_extended_methods(s.global_env.symbols) | |
s.global_env.project_deps = collect(keys(s.global_env.symbols)) | |
f = StaticLint.loadfile(s, root_file) | |
StaticLint.semantic_pass(LanguageServer.getroot(f)) | |
for doc in LanguageServer.getdocuments_value(s) | |
StaticLint.check_all(LanguageServer.getcst(doc), s.lint_options, LanguageServer.getenv(doc, s)) | |
LanguageServer.mark_errors(doc, doc.diagnostics) | |
foreach(println, doc.diagnostics) | |
end |
$ cat test.jl
function foo(x, y)
z = x
for i in 1
z += i
end
return z
end
$ julia lintme.jl . test.jl
LanguageServer.Diagnostic(LanguageServer.Range(LanguageServer.Position(0, 16), LanguageServer.Position(0, 17)), 4, "UnusedFunctionArgument", missing, "Julia", "An argument is included in a function signature but not used within its body.", [1], missing)
LanguageServer.Diagnostic(LanguageServer.Range(LanguageServer.Position(2, 8), LanguageServer.Position(2, 14)), 3, "IncorrectIterSpec", missing, "Julia", "A loop iterator has been used that will likely error.", missing, missing)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for providing this. Is there an example file I can run this on to see some expected output for something detected?