Syntax Reference

Main

StaticLint.followincludeMethod
followinclude(x, state)

Checks whether the arguments of a call to include can be resolved to a path. If successful it checks whether a file with that path is loaded on the server or a file exists on the disc that can be loaded. If this is successful it traverses the code associated with the loaded file.

source
StaticLint.get_pathMethod
get_path(x::EXPR)

Usually called on the argument to include calls, and attempts to determine the path of the file to be included. Has limited support for joinpath calls.

source
StaticLint.semantic_passFunction
semantic_pass(file, modified_expr=nothing)

Performs a semantic pass across a project from the entry point file. A first pass traverses the top-level scope after which secondary passes handle delayed scopes (e.g. functions). These secondary passes can be, optionally, very light and only seek to resovle references (e.g. link symbols to bindings). This can be done by supplying a list of expressions on which the full secondary pass should be made (modified_expr), all others will receive the light-touch version.

source
StaticLint.traverseMethod
traverse(x, state)

Iterates across the child nodes of an EXPR in execution order (rather than storage order) calling state on each node.

source
StaticLint.BindingType

Bindings indicate that an EXPR may introduce a new name into the current scope/namespace. Struct fields:

  • name: the EXPR that defines the unqualifed name of the binding.
  • val: what the binding points to, either a Binding (indicating ..), EXPR (this is generally the expression that defines the value) or SymStore.
  • type: the type of the binding, either a Binding, EXPR, or SymStore.
  • refs: a list containing all references that have been made to the binding.
source
StaticLint.add_bindingFunction
add_binding(x, state, scope=state.scope)

Add the binding of x to the current scope. Special handling is required for:

  • macros: to prefix the @
  • functions: These are added to the top-level scope unless this syntax is used to define a closure within a function. If a function with the same name already exists in the scope then it is not replaced. This enables the refs list of the Binding of that 'root method' to hold a method table, the name of the new function will resolve to the binding of the root method (to get a list of actual methods -[get_method(ref) for ref in binding.refs if get_method(ref) !== nothing]). For example
[1] f() = 1
[2] f(x) = 2

[1] is the root method and the name of [2] resolves to the binding of [1]. Functions declared with qualified names require special handling, there are comments in the source.

Some simple type inference is run.

source
StaticLint.mark_bindings!Method
mark_bindings!(x::EXPR, state)

Checks whether the expression x should introduce new names and marks them as needed. Generally this marks expressions that would introdce names to the current scope (i.e. that x sits in) but in cases marks expressions that will add names to lower scopes. This is done when it is not knowable that a child node of x will introduce a new name without the context of where it sits in x -for example the arguments of the signature of a function definition.

source
StaticLint.lint_fileFunction
lint_file(rootpath, server)

Read a file from disc, parse and run a semantic pass over it. The file should be the root of a project, e.g. for this package that file is src/StaticLint.jl. Other files in the project will be loaded automatically (calls to include with complicated arguments are not handled, see followinclude for details). A FileServer will be returned containing the Files of the package.

source
StaticLint.lint_stringFunction
lint_string(s, server; gethints = false)

Parse a string and run a semantic pass over it. This will mark scopes, bindings, references, and lint hints. An annotated EXPR is returned or, if gethints = true, it is paired with a collected list of errors/hints.

source
StaticLint.interpret_evalMethod

interpret_eval(x::EXPR, state)

Naive attempt to interpret x as though it has been eval'ed. Lifts any bindings made within the scope of x to the toplevel and replaces (some) interpolated binding names with the value where possible.

source
StaticLint.resolve_getfieldMethod
resolve_getfield(x::EXPR, parent::Union{EXPR,Scope,ModuleStore,Binding}, state::State)::Bool

Given an expression of the form parent.x try to resolve x. The method called with parent::EXPR resolves the reference for parent, other methods then check whether the Binding/Scope/ModuleStore to which parent points has a field matching x.

source
StaticLint.valofidMethod
valofid(x)

Returns the string value of an expression for which isidentifier is true, i.e. handles NONSTDIDENTIFIERs.

source
StaticLint.scopesMethod
scopes(x::EXPR, state)

Called when traversing the syntax tree and handles the association of scopes with expressions. On the first pass this will add scopes as necessary, on following passes it empties it.

source
StaticLint.getenvMethod
getenv(file::File, server::FileServer)

Get the relevant ExternalEnv for a given file.

source

Linting

StaticLint.check_kw_defaultMethod
check_kw_default(x::EXPR, server)

Check that the default value matches the type for keyword arguments. Following types are checked: String, Symbol, Int, Char, Bool, Float32, Float64, UInt8, UInt16, UInt32, UInt64, UInt128.

source
StaticLint.collect_hintsFunction

collect_hints(x::EXPR, env, missingrefs = :all, isquoted = false, errs = Tuple{Int,EXPR}[], pos = 0)

Collect hints and errors from an expression. missingrefs = (:none, :id, :all) determines whether unresolved identifiers are marked, the :all option will mark identifiers used in getfield calls."

source