Skip to content

Commit

Permalink
Format files using DocumentFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
davidanthoff authored Mar 12, 2022
1 parent 06d008e commit 62862bd
Show file tree
Hide file tree
Showing 14 changed files with 284 additions and 284 deletions.
18 changes: 9 additions & 9 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ using StaticLint
using Documenter

makedocs(;
modules=[StaticLint],
authors="Julia VSCode",
repo="https://github.com/julia-vscode/StaticLint.jl/blob/{commit}{path}#L{line}",
sitename="StaticLint.jl",
format=Documenter.HTML(;
prettyurls=prettyurls = get(ENV, "CI", nothing) == "true",
modules = [StaticLint],
authors = "Julia VSCode",
repo = "https://github.com/julia-vscode/StaticLint.jl/blob/{commit}{path}#L{line}",
sitename = "StaticLint.jl",
format = Documenter.HTML(;
prettyurls = prettyurls = get(ENV, "CI", nothing) == "true"
# canonical="https://www.julia-vscode.org/StaticLint.jl",
# assets=String[],
),
pages=[
pages = [
"Home" => "index.md",
"Syntax Reference" => "syntax.md",
],
]
)

deploydocs(;
repo="github.com/julia-vscode/StaticLint.jl",
repo = "github.com/julia-vscode/StaticLint.jl"
)
8 changes: 4 additions & 4 deletions src/bindings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Binding(x::EXPR) = Binding(CSTParser.get_name(x), x, nothing, [])
function Base.show(io::IO, b::Binding)
printstyled(io, " Binding(", to_codeobject(b.name),
b.type === nothing ? "" : ":: ",
b.refs isa Vector ? "($(length(b.refs)) refs))" : ")", color=:blue)
b.refs isa Vector ? "($(length(b.refs)) refs))" : ")", color = :blue)
end


Expand Down Expand Up @@ -120,7 +120,7 @@ function mark_bindings!(x::EXPR, state)
end


function mark_binding!(x::EXPR, val=x)
function mark_binding!(x::EXPR, val = x)
if CSTParser.iskwarg(x) || (CSTParser.isdeclaration(x) && CSTParser.istuple(x.args[1]))
mark_binding!(x.args[1], x)
elseif CSTParser.istuple(x) || CSTParser.isparameters(x)
Expand Down Expand Up @@ -268,7 +268,7 @@ Add the binding of `x` to the current scope. Special handling is required for:
Some simple type inference is run.
"""
function add_binding(x, state, scope=state.scope)
function add_binding(x, state, scope = state.scope)
if bindingof(x) isa Binding
b = bindingof(x)
if isidentifier(b.name)
Expand Down Expand Up @@ -366,7 +366,7 @@ function add_binding(x, state, scope=state.scope)
end

function enforce_hard_scope(x::EXPR, scope)
scope.expr.head === :for && is_in_fexpr(x, x-> x == scope.expr.args[1])
scope.expr.head === :for && is_in_fexpr(x, x -> x == scope.expr.args[1])
end

name_is_getfield(x) = parentof(x) isa EXPR && parentof(parentof(x)) isa EXPR && CSTParser.is_getfield_w_quotenode(parentof(parentof(x)))
Expand Down
2 changes: 1 addition & 1 deletion src/coretypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ isva(x::SymbolServer.FakeUnionAll) = isva(x.body)
@static if Core.Vararg isa Core.Type
function isva(x)
return (x isa SymbolServer.FakeTypeName && x.name.name == :Vararg &&
x.name.parent isa SymbolServer.VarRef && x.name.parent.name == :Core)
x.name.parent isa SymbolServer.VarRef && x.name.parent.name == :Core)
end
else
isva(x) = x isa SymbolServer.FakeTypeofVararg
Expand Down
2 changes: 1 addition & 1 deletion src/exception_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ end

function Base.showerror(io::IO, ex::SLInvalidPath)
print(io, ex.msg)
end
end
18 changes: 9 additions & 9 deletions src/imports.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function resolve_import_block(x::EXPR, state::State, root, usinged, markfinal=true)
function resolve_import_block(x::EXPR, state::State, root, usinged, markfinal = true)
if x.head == :as
resolve_import_block(x.args[1], state, root, usinged, markfinal)
if x.args[2].meta === nothing
Expand Down Expand Up @@ -37,7 +37,7 @@ function resolve_import_block(x::EXPR, state::State, root, usinged, markfinal=tr
end
end

function resolve_import(x::EXPR, state::State, root=getsymbols(state))
function resolve_import(x::EXPR, state::State, root = getsymbols(state))
if headof(x) === :using || headof(x) === :import
usinged = headof(x) === :using
if length(x.args) > 0 && isoperator(headof(x.args[1])) && valof(headof(x.args[1])) == ":"
Expand Down Expand Up @@ -86,11 +86,11 @@ end

function has_workspace_package(server, name)
haskey(server.workspacepackages, name) &&
hasscope(getcst(server.workspacepackages[name])) &&
haskey(scopeof(getcst(server.workspacepackages[name])).names, name) &&
scopeof(getcst(server.workspacepackages[name])).names[name] isa Binding &&
scopeof(getcst(server.workspacepackages[name])).names[name].val isa EXPR &&
CSTParser.defines_module(scopeof(getcst(server.workspacepackages[name])).names[name].val)
hasscope(getcst(server.workspacepackages[name])) &&
haskey(scopeof(getcst(server.workspacepackages[name])).names, name) &&
scopeof(getcst(server.workspacepackages[name])).names[name] isa Binding &&
scopeof(getcst(server.workspacepackages[name])).names[name].val isa EXPR &&
CSTParser.defines_module(scopeof(getcst(server.workspacepackages[name])).names[name].val)
end

function add_to_imported_modules(scope::Scope, name::Symbol, val)
Expand Down Expand Up @@ -121,8 +121,8 @@ function _get_field(par, arg, state)
if par isa SymbolServer.EnvStore
if (arg_scope = retrieve_scope(arg)) !== nothing && (tlm = get_named_toplevel_module(arg_scope, arg_str_rep)) !== nothing && hasbinding(tlm)
return bindingof(tlm)
# elseif has_workspace_package(state.server, arg_str_rep)
# return scopeof(getcst(state.server.workspacepackages[arg_str_rep])).names[arg_str_rep]
# elseif has_workspace_package(state.server, arg_str_rep)
# return scopeof(getcst(state.server.workspacepackages[arg_str_rep])).names[arg_str_rep]
elseif haskey(par, Symbol(arg_str_rep))
if isempty(state.env.project_deps) || Symbol(arg_str_rep) in state.env.project_deps
return par[Symbol(arg_str_rep)]
Expand Down
4 changes: 2 additions & 2 deletions src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function setup_server(env = dirname(SymbolServer.Pkg.Types.Context().env.project
server = StaticLint.FileServer()
ssi = SymbolServerInstance(depot, cache)
_, server.symbolserver = SymbolServer.getstore(ssi, env)
server.symbol_extends = SymbolServer.collect_extended_methods(server.symbolserver)
server.symbol_extends = SymbolServer.collect_extended_methods(server.symbolserver)
server
end

Expand Down Expand Up @@ -46,7 +46,7 @@ function lint_file(rootpath, server = setup_server(); gethints = false)
end
if gethints
hints = []
for (p,f) in server.files
for (p, f) in server.files
append!(hints, [(x, string(haserror(x) ? LintCodeDescriptions[x.meta.error] : "Missing reference", " at offset ", offset, " of ", p)) for (offset, x) in collect_hints(f.cst, getenv(f, server))])
end
return root, hints
Expand Down
114 changes: 57 additions & 57 deletions src/linting/checks.jl
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
@enum(LintCodes,
MissingRef,
IncorrectCallArgs,
IncorrectIterSpec,
NothingEquality,
NothingNotEq,
ConstIfCondition,
EqInIfConditional,
PointlessOR,
PointlessAND,
UnusedBinding,
InvalidTypeDeclaration,
UnusedTypeParameter,
IncludeLoop,
MissingFile,
InvalidModuleName,
TypePiracy,
UnusedFunctionArgument,
CannotDeclareConst,
InvalidRedefofConst,
NotEqDef,
KwDefaultMismatch,
InappropriateUseOfLiteral,
ShouldBeInALoop,
TypeDeclOnGlobalVariable,
UnsupportedConstLocalVariable,
UnassignedKeywordArgument,
CannotDefineFuncAlreadyHasValue,
DuplicateFuncArgName,
IncludePathContainsNULL)
MissingRef,
IncorrectCallArgs,
IncorrectIterSpec,
NothingEquality,
NothingNotEq,
ConstIfCondition,
EqInIfConditional,
PointlessOR,
PointlessAND,
UnusedBinding,
InvalidTypeDeclaration,
UnusedTypeParameter,
IncludeLoop,
MissingFile,
InvalidModuleName,
TypePiracy,
UnusedFunctionArgument,
CannotDeclareConst,
InvalidRedefofConst,
NotEqDef,
KwDefaultMismatch,
InappropriateUseOfLiteral,
ShouldBeInALoop,
TypeDeclOnGlobalVariable,
UnsupportedConstLocalVariable,
UnassignedKeywordArgument,
CannotDefineFuncAlreadyHasValue,
DuplicateFuncArgName,
IncludePathContainsNULL)



Expand Down Expand Up @@ -59,7 +59,7 @@ const LintCodeDescriptions = Dict{LintCodes,String}(IncorrectCallArgs => "Possib
CannotDefineFuncAlreadyHasValue => "Cannot define function ; it already has a value.",
DuplicateFuncArgName => "Function argument name not unique.",
IncludePathContainsNULL => "Cannot include file, path cotains NULL characters."
)
)

haserror(m::Meta) = m.error !== nothing
haserror(x::EXPR) = hasmeta(x) && haserror(x.meta)
Expand Down Expand Up @@ -173,9 +173,9 @@ function func_nargs(x::EXPR)
maxargs !== typemax(Int) && (maxargs += 1)
end
elseif issplat(arg) ||
(isdeclaration(arg) &&
((isidentifier(arg.args[2]) && valofid(arg.args[2]) == "Vararg") ||
(iscurly(arg.args[2]) && isidentifier(arg.args[2].args[1]) && valofid(arg.args[2].args[1]) == "Vararg")))
(isdeclaration(arg) &&
((isidentifier(arg.args[2]) && valofid(arg.args[2]) == "Vararg") ||
(iscurly(arg.args[2]) && isidentifier(arg.args[2].args[1]) && valofid(arg.args[2].args[1]) == "Vararg")))
maxargs = typemax(Int)
else
minargs += 1
Expand Down Expand Up @@ -239,9 +239,9 @@ end
# compare_f_call(m_counts, call_counts) = true # fallback method

function compare_f_call(
(ref_minargs, ref_maxargs, ref_kws, kwsplat),
(act_minargs, act_maxargs, act_kws),
)
(ref_minargs, ref_maxargs, ref_kws, kwsplat),
(act_minargs, act_maxargs, act_kws),
)
# check matching on positional arguments
if act_maxargs == typemax(Int)
act_minargs <= act_maxargs < ref_minargs && return false
Expand All @@ -261,10 +261,10 @@ end

function is_something_with_methods(x::Binding)
(CoreTypes.isfunction(x.type) && x.val isa EXPR) ||
(CoreTypes.isdatatype(x.type) && x.val isa EXPR && CSTParser.defines_struct(x.val)) ||
(x.val isa SymbolServer.FunctionStore || x.val isa SymbolServer.DataTypeStore)
(CoreTypes.isdatatype(x.type) && x.val isa EXPR && CSTParser.defines_struct(x.val)) ||
(x.val isa SymbolServer.FunctionStore || x.val isa SymbolServer.DataTypeStore)
end
is_something_with_methods(x::T) where T <: Union{SymbolServer.FunctionStore,SymbolServer.DataTypeStore} = true
is_something_with_methods(x::T) where {T<:Union{SymbolServer.FunctionStore,SymbolServer.DataTypeStore}} = true
is_something_with_methods(x) = false

function check_call(x, env::ExternalEnv)
Expand Down Expand Up @@ -457,9 +457,9 @@ end

function check_modulename(x::EXPR)
if CSTParser.defines_module(x) && # x is a module
scopeof(x) isa Scope && parentof(scopeof(x)) isa Scope && # it has a scope and a parent scope
CSTParser.defines_module(parentof(scopeof(x)).expr) && # the parent scope is a module
valof(CSTParser.get_name(x)) == valof(CSTParser.get_name(parentof(scopeof(x)).expr)) # their names match
scopeof(x) isa Scope && parentof(scopeof(x)) isa Scope && # it has a scope and a parent scope
CSTParser.defines_module(parentof(scopeof(x)).expr) && # the parent scope is a module
valof(CSTParser.get_name(x)) == valof(CSTParser.get_name(parentof(scopeof(x)).expr)) # their names match
seterror!(CSTParser.get_name(x), InvalidModuleName)
end
end
Expand All @@ -469,7 +469,7 @@ function check_farg_unused(x::EXPR)
if CSTParser.defines_function(x)
sig = CSTParser.rem_wheres_decls(CSTParser.get_sig(x))
if (headof(x) === :function && length(x.args) == 2 && x.args[2] isa EXPR && length(x.args[2].args) == 1 && CSTParser.isliteral(x.args[2].args[1])) ||
(length(x.args) > 1 && headof(x.args[2]) === :block && length(x.args[2].args) == 1 && CSTParser.isliteral(x.args[2].args[1]))
(length(x.args) > 1 && headof(x.args[2]) === :block && length(x.args[2].args) == 1 && CSTParser.isliteral(x.args[2].args[1]))
return # Allow functions that return constants
end
if iscall(sig)
Expand Down Expand Up @@ -503,12 +503,12 @@ function check_farg_unused_(arg, arg_names)
valof(b.name) isa String && all_underscore(valof(b.name)) && return false

if b === nothing ||
# no refs:
# no refs:
isempty(b.refs) ||
# only self ref:
# only self ref:
(length(b.refs) == 1 && first(b.refs) == b.name) ||
# first usage has binding:
(length(b.refs) > 1 && b.refs[2] isa EXPR && hasbinding(b.refs[2]))
# first usage has binding:
(length(b.refs) > 1 && b.refs[2] isa EXPR && hasbinding(b.refs[2]))
seterror!(arg, UnusedFunctionArgument)
end

Expand All @@ -528,8 +528,8 @@ end

function is_nospecialize_call(x)
CSTParser.ismacrocall(x) &&
CSTParser.ismacroname(x.args[1]) &&
is_nospecialize(x.args[1])
CSTParser.ismacroname(x.args[1]) &&
is_nospecialize(x.args[1])
end

"""
Expand All @@ -538,7 +538,7 @@ collect_hints(x::EXPR, env, missingrefs = :all, isquoted = false, errs = Tuple{I
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."
"""
function collect_hints(x::EXPR, env, missingrefs=:all, isquoted=false, errs=Tuple{Int,EXPR}[], pos=0)
function collect_hints(x::EXPR, env, missingrefs = :all, isquoted = false, errs = Tuple{Int,EXPR}[], pos = 0)
if quoted(x)
isquoted = true
elseif isquoted && unquoted(x)
Expand All @@ -549,8 +549,8 @@ function collect_hints(x::EXPR, env, missingrefs=:all, isquoted=false, errs=Tupl
push!(errs, (pos, x))
elseif !isquoted
if missingrefs != :none && isidentifier(x) && !hasref(x) &&
!(valof(x) == "var" && parentof(x) isa EXPR && isnonstdid(parentof(x))) &&
!((valof(x) == "stdcall" || valof(x) == "cdecl" || valof(x) == "fastcall" || valof(x) == "thiscall" || valof(x) == "llvmcall") && is_in_fexpr(x, x -> iscall(x) && isidentifier(x.args[1]) && valof(x.args[1]) == "ccall"))
!(valof(x) == "var" && parentof(x) isa EXPR && isnonstdid(parentof(x))) &&
!((valof(x) == "stdcall" || valof(x) == "cdecl" || valof(x) == "fastcall" || valof(x) == "thiscall" || valof(x) == "llvmcall") && is_in_fexpr(x, x -> iscall(x) && isidentifier(x.args[1]) && valof(x.args[1]) == "ccall"))

push!(errs, (pos, x))
elseif haserror(x) && errorof(x) isa StaticLint.LintCodes
Expand Down Expand Up @@ -579,7 +579,7 @@ end

function should_mark_missing_getfield_ref(x, env)
if isidentifier(x) && !hasref(x) && # x has no ref
parentof(x) isa EXPR && headof(parentof(x)) === :quotenode && parentof(parentof(x)) isa EXPR && is_getfield(parentof(parentof(x))) # x is the rhs of a getproperty
parentof(x) isa EXPR && headof(parentof(x)) === :quotenode && parentof(parentof(x)) isa EXPR && is_getfield(parentof(parentof(x))) # x is the rhs of a getproperty
lhsref = refof_maybe_getfield(parentof(parentof(x)).args[1])
hasref(x) && return false # We've resolved
if lhsref isa SymbolServer.ModuleStore || (lhsref isa Binding && lhsref.val isa SymbolServer.ModuleStore)
Expand Down Expand Up @@ -648,14 +648,14 @@ function is_type_of_call_to_getproperty(x::EXPR)
if iscall(x)
func_name = x.args[1]
return (isidentifier(func_name) && valof(func_name) == "getproperty") || # getproperty()
(is_getfield_w_quotenode(func_name) && isidentifier(func_name.args[2].args[1]) && valof(func_name.args[2].args[1]) == "getproperty") # Base.getproperty()
(is_getfield_w_quotenode(func_name) && isidentifier(func_name.args[2].args[1]) && valof(func_name.args[2].args[1]) == "getproperty") # Base.getproperty()
end
return false
end

return parentof(x) isa EXPR && parentof(parentof(x)) isa EXPR &&
((isdeclaration(parentof(x)) && x === parentof(x).args[2] && is_call_to_getproperty(parentof(parentof(x)))) ||
(iscurly(parentof(x)) && x === parentof(x).args[1] && isdeclaration(parentof(parentof(x))) && parentof(parentof(parentof(x))) isa EXPR && is_call_to_getproperty(parentof(parentof(parentof(x))))))
((isdeclaration(parentof(x)) && x === parentof(x).args[2] && is_call_to_getproperty(parentof(parentof(x)))) ||
(iscurly(parentof(x)) && x === parentof(x).args[1] && isdeclaration(parentof(parentof(x))) && parentof(parentof(parentof(x))) isa EXPR && is_call_to_getproperty(parentof(parentof(parentof(x))))))
end

isunionfaketype(t::SymbolServer.FakeTypeName) = t.name.name === :Union && t.name.parent isa SymbolServer.VarRef && t.name.parent.name === :Core
Expand Down Expand Up @@ -765,7 +765,7 @@ end

# find any parent nodes that are :if blocks and a pseudo-index of which branch
# x is in
function find_if_parents(x::EXPR, current=Int[], list=Dict{EXPR,Vector{Int}}())
function find_if_parents(x::EXPR, current = Int[], list = Dict{EXPR,Vector{Int}}())
if x.head in (:block, :elseif) && parentof(x) isa EXPR && headof(parentof(x)) in (:if, :elseif)
i = 1
while i <= length(parentof(x).args)
Expand Down
Loading

0 comments on commit 62862bd

Please sign in to comment.