Skip to content

Commit 58372ab

Browse files
pfitzsebgithub-actions[bot]
authored andcommitted
Format files using DocumentFormat
1 parent f7008ed commit 58372ab

File tree

14 files changed

+262
-264
lines changed

14 files changed

+262
-264
lines changed

src/StaticLint.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ Meta() = Meta(nothing, nothing, nothing, nothing)
2929

3030
function Base.show(io::IO, m::Meta)
3131
m.binding !== nothing && show(io, m.binding)
32-
m.ref !== nothing && printstyled(io, " * ", color = :red)
33-
m.scope !== nothing && printstyled(io, " new scope", color = :green)
34-
m.error !== nothing && printstyled(io, " lint ", color = :red)
32+
m.ref !== nothing && printstyled(io, " * ", color=:red)
33+
m.scope !== nothing && printstyled(io, " new scope", color=:green)
34+
m.error !== nothing && printstyled(io, " lint ", color=:red)
3535
end
3636
hasmeta(x::EXPR) = x.meta isa Meta
3737
hasbinding(m::Meta) = m.binding isa Binding
@@ -173,7 +173,7 @@ end
173173
174174
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.
175175
"""
176-
function semantic_pass(file, modified_expr = nothing)
176+
function semantic_pass(file, modified_expr=nothing)
177177
server = file.server
178178
env = getenv(file, server)
179179
setscope!(getcst(file), Scope(nothing, getcst(file), Dict(), Dict{Symbol,Any}(:Base => env.symbols[:Base], :Core => env.symbols[:Core]), nothing))

src/bindings.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function mark_binding!(x::EXPR, val=x)
144144
return x
145145
end
146146

147-
function mark_parameters(sig::EXPR, params = String[])
147+
function mark_parameters(sig::EXPR, params=String[])
148148
if CSTParser.issubtypedecl(sig)
149149
mark_parameters(sig.args[1], params)
150150
elseif iswhere(sig)
@@ -370,7 +370,7 @@ function add_binding(x, state, scope=state.scope)
370370
end
371371

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

376376
name_is_getfield(x) = parentof(x) isa EXPR && parentof(parentof(x)) isa EXPR && CSTParser.is_getfield_w_quotenode(parentof(parentof(x)))

src/coretypes.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ isva(x::SymbolServer.FakeUnionAll) = isva(x.body)
3939
@static if Core.Vararg isa Core.Type
4040
function isva(x)
4141
return (x isa SymbolServer.FakeTypeName && x.name.name == :Vararg &&
42-
x.name.parent isa SymbolServer.VarRef && x.name.parent.name == :Core)
42+
x.name.parent isa SymbolServer.VarRef && x.name.parent.name == :Core)
4343
end
4444
else
4545
isva(x) = x isa SymbolServer.FakeTypeofVararg

src/exception_types.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ end
44

55
function Base.showerror(io::IO, ex::SLInvalidPath)
66
print(io, ex.msg)
7-
end
7+
end

src/imports.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,19 @@ function _mark_import_arg(arg, par, state, usinged)
107107
add_to_imported_modules(state.scope, Symbol(valofid(arg)), scopeof(par.val.val))
108108
end
109109
else
110-
# import binds the name in the current scope
111-
state.scope.names[valofid(arg)] = bindingof(arg)
110+
# import binds the name in the current scope
111+
state.scope.names[valofid(arg)] = bindingof(arg)
112112
end
113113
end
114114
end
115115

116116
function has_workspace_package(server, name)
117117
haskey(server.workspacepackages, name) &&
118-
hasscope(getcst(server.workspacepackages[name])) &&
119-
haskey(scopeof(getcst(server.workspacepackages[name])).names, name) &&
120-
scopeof(getcst(server.workspacepackages[name])).names[name] isa Binding &&
121-
scopeof(getcst(server.workspacepackages[name])).names[name].val isa EXPR &&
122-
CSTParser.defines_module(scopeof(getcst(server.workspacepackages[name])).names[name].val)
118+
hasscope(getcst(server.workspacepackages[name])) &&
119+
haskey(scopeof(getcst(server.workspacepackages[name])).names, name) &&
120+
scopeof(getcst(server.workspacepackages[name])).names[name] isa Binding &&
121+
scopeof(getcst(server.workspacepackages[name])).names[name].val isa EXPR &&
122+
CSTParser.defines_module(scopeof(getcst(server.workspacepackages[name])).names[name].val)
123123
end
124124

125125
function add_to_imported_modules(scope::Scope, name::Symbol, val)
@@ -150,8 +150,8 @@ function _get_field(par, arg, state)
150150
if par isa SymbolServer.EnvStore
151151
if (arg_scope = retrieve_scope(arg)) !== nothing && (tlm = get_named_toplevel_module(arg_scope, arg_str_rep)) !== nothing && hasbinding(tlm)
152152
return bindingof(tlm)
153-
# elseif has_workspace_package(state.server, arg_str_rep)
154-
# return scopeof(getcst(state.server.workspacepackages[arg_str_rep])).names[arg_str_rep]
153+
# elseif has_workspace_package(state.server, arg_str_rep)
154+
# return scopeof(getcst(state.server.workspacepackages[arg_str_rep])).names[arg_str_rep]
155155
elseif haskey(par, Symbol(arg_str_rep))
156156
if isempty(state.env.project_deps) || Symbol(arg_str_rep) in state.env.project_deps
157157
return par[Symbol(arg_str_rep)]

src/interface.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function setup_server(env = dirname(SymbolServer.Pkg.Types.Context().env.project_file), depot = first(SymbolServer.Pkg.depots()), cache = joinpath(dirname(pathof(SymbolServer)), "..", "store"))
1+
function setup_server(env=dirname(SymbolServer.Pkg.Types.Context().env.project_file), depot=first(SymbolServer.Pkg.depots()), cache=joinpath(dirname(pathof(SymbolServer)), "..", "store"))
22
server = StaticLint.FileServer()
33
ssi = SymbolServerInstance(depot, cache)
44
_, symbols = SymbolServer.getstore(ssi, env)
@@ -14,7 +14,7 @@ Parse a string and run a semantic pass over it. This will mark scopes, bindings,
1414
references, and lint hints. An annotated `EXPR` is returned or, if `gethints = true`,
1515
it is paired with a collected list of errors/hints.
1616
"""
17-
function lint_string(s::String, server = setup_server(); gethints = false)
17+
function lint_string(s::String, server=setup_server(); gethints=false)
1818
empty!(server.files)
1919
f = File("", s, CSTParser.parse(s, true), nothing, server)
2020
env = getenv(f, server)
@@ -38,7 +38,7 @@ in the project will be loaded automatically (calls to `include` with complicated
3838
are not handled, see `followinclude` for details). A `FileServer` will be returned
3939
containing the `File`s of the package.
4040
"""
41-
function lint_file(rootpath, server = setup_server(); gethints = false)
41+
function lint_file(rootpath, server=setup_server(); gethints=false)
4242
empty!(server.files)
4343
root = loadfile(server, rootpath)
4444
semantic_pass(root)
@@ -47,7 +47,7 @@ function lint_file(rootpath, server = setup_server(); gethints = false)
4747
end
4848
if gethints
4949
hints = []
50-
for (p,f) in server.files
50+
for (p, f) in server.files
5151
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))])
5252
end
5353
return root, hints

src/linting/checks.jl

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
@enum(
2-
LintCodes,
3-
4-
MissingRef,
2+
LintCodes, MissingRef,
53
IncorrectCallArgs,
64
IncorrectIterSpec,
75
NothingEquality,
@@ -183,9 +181,9 @@ function func_nargs(x::EXPR)
183181
maxargs !== typemax(Int) && (maxargs += 1)
184182
end
185183
elseif issplat(arg) ||
186-
(isdeclaration(arg) &&
187-
((isidentifier(arg.args[2]) && valofid(arg.args[2]) == "Vararg") ||
188-
(iscurly(arg.args[2]) && isidentifier(arg.args[2].args[1]) && valofid(arg.args[2].args[1]) == "Vararg")))
184+
(isdeclaration(arg) &&
185+
((isidentifier(arg.args[2]) && valofid(arg.args[2]) == "Vararg") ||
186+
(iscurly(arg.args[2]) && isidentifier(arg.args[2].args[1]) && valofid(arg.args[2].args[1]) == "Vararg")))
189187
maxargs = typemax(Int)
190188
else
191189
minargs += 1
@@ -249,9 +247,9 @@ end
249247
# compare_f_call(m_counts, call_counts) = true # fallback method
250248

251249
function compare_f_call(
252-
(ref_minargs, ref_maxargs, ref_kws, kwsplat),
253-
(act_minargs, act_maxargs, act_kws),
254-
)
250+
(ref_minargs, ref_maxargs, ref_kws, kwsplat),
251+
(act_minargs, act_maxargs, act_kws),
252+
)
255253
# check matching on positional arguments
256254
if act_maxargs == typemax(Int)
257255
act_minargs <= act_maxargs < ref_minargs && return false
@@ -271,10 +269,10 @@ end
271269

272270
function is_something_with_methods(x::Binding)
273271
(CoreTypes.isfunction(x.type) && x.val isa EXPR) ||
274-
(CoreTypes.isdatatype(x.type) && x.val isa EXPR && CSTParser.defines_struct(x.val)) ||
275-
(x.val isa SymbolServer.FunctionStore || x.val isa SymbolServer.DataTypeStore)
272+
(CoreTypes.isdatatype(x.type) && x.val isa EXPR && CSTParser.defines_struct(x.val)) ||
273+
(x.val isa SymbolServer.FunctionStore || x.val isa SymbolServer.DataTypeStore)
276274
end
277-
is_something_with_methods(x::T) where T <: Union{SymbolServer.FunctionStore,SymbolServer.DataTypeStore} = true
275+
is_something_with_methods(x::T) where T<:Union{SymbolServer.FunctionStore,SymbolServer.DataTypeStore} = true
278276
is_something_with_methods(x) = false
279277

280278
function check_call(x, env::ExternalEnv)
@@ -383,13 +381,13 @@ function check_incorrect_iter_spec(x, body, env)
383381
if headof(rng) === :FLOAT || headof(rng) === :INTEGER || (iscall(rng) && refof(rng.args[1]) === getsymbols(env)[:Base][:length])
384382
seterror!(x, IncorrectIterSpec)
385383
elseif iscall(rng) && valof(rng.args[1]) == ":" &&
386-
length(rng.args) === 3 &&
387-
headof(rng.args[2]) === :INTEGER &&
388-
iscall(rng.args[3]) &&
389-
length(rng.args[3].args) > 1 && (
390-
refof(rng.args[3].args[1]) === getsymbols(env)[:Base][:length] ||
391-
refof(rng.args[3].args[1]) === getsymbols(env)[:Base][:size]
392-
)
384+
length(rng.args) === 3 &&
385+
headof(rng.args[2]) === :INTEGER &&
386+
iscall(rng.args[3]) &&
387+
length(rng.args[3].args) > 1 && (
388+
refof(rng.args[3].args[1]) === getsymbols(env)[:Base][:length] ||
389+
refof(rng.args[3].args[1]) === getsymbols(env)[:Base][:size]
390+
)
393391
if length(x.args) >= 1
394392
lhs = x.args[1]
395393
arr = rng.args[3].args[2]
@@ -433,14 +431,14 @@ function check_nothing_equality(x::EXPR, env::ExternalEnv)
433431
if isbinarycall(x) && length(x.args) == 3
434432
nothings = (getsymbols(env)[:Core][:nothing], getsymbols(env)[:Base][:nothing])
435433
if valof(x.args[1]) == "==" && (
436-
(valof(x.args[2]) == "nothing" && refof(x.args[2]) in nothings) ||
437-
(valof(x.args[3]) == "nothing" && refof(x.args[3]) in nothings)
438-
)
434+
(valof(x.args[2]) == "nothing" && refof(x.args[2]) in nothings) ||
435+
(valof(x.args[3]) == "nothing" && refof(x.args[3]) in nothings)
436+
)
439437
seterror!(x.args[1], NothingEquality)
440438
elseif valof(x.args[1]) == "!=" && (
441-
(valof(x.args[2]) == "nothing" && refof(x.args[2]) in nothings) ||
442-
(valof(x.args[3]) == "nothing" && refof(x.args[3]) in nothings)
443-
)
439+
(valof(x.args[2]) == "nothing" && refof(x.args[2]) in nothings) ||
440+
(valof(x.args[3]) == "nothing" && refof(x.args[3]) in nothings)
441+
)
444442
seterror!(x.args[1], NothingNotEq)
445443
end
446444
end
@@ -532,9 +530,9 @@ end
532530

533531
function check_modulename(x::EXPR)
534532
if CSTParser.defines_module(x) && # x is a module
535-
scopeof(x) isa Scope && parentof(scopeof(x)) isa Scope && # it has a scope and a parent scope
536-
CSTParser.defines_module(parentof(scopeof(x)).expr) && # the parent scope is a module
537-
valof(CSTParser.get_name(x)) == valof(CSTParser.get_name(parentof(scopeof(x)).expr)) # their names match
533+
scopeof(x) isa Scope && parentof(scopeof(x)) isa Scope && # it has a scope and a parent scope
534+
CSTParser.defines_module(parentof(scopeof(x)).expr) && # the parent scope is a module
535+
valof(CSTParser.get_name(x)) == valof(CSTParser.get_name(parentof(scopeof(x)).expr)) # their names match
538536
seterror!(CSTParser.get_name(x), InvalidModuleName)
539537
end
540538
end
@@ -544,7 +542,7 @@ function check_farg_unused(x::EXPR)
544542
if CSTParser.defines_function(x)
545543
sig = CSTParser.rem_wheres_decls(CSTParser.get_sig(x))
546544
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])) ||
547-
(length(x.args) > 1 && headof(x.args[2]) === :block && length(x.args[2].args) == 1 && CSTParser.isliteral(x.args[2].args[1]))
545+
(length(x.args) > 1 && headof(x.args[2]) === :block && length(x.args[2].args) == 1 && CSTParser.isliteral(x.args[2].args[1]))
548546
return # Allow functions that return constants
549547
end
550548
if iscall(sig)
@@ -581,12 +579,12 @@ function check_farg_unused_(arg, arg_names)
581579
valof(b.name) isa String && all_underscore(valof(b.name)) && return false
582580

583581
if b === nothing ||
584-
# no refs:
582+
# no refs:
585583
isempty(b.refs) ||
586-
# only self ref:
584+
# only self ref:
587585
(length(b.refs) == 1 && first(b.refs) == b.name) ||
588-
# first usage has binding:
589-
(length(b.refs) > 1 && b.refs[2] isa EXPR && hasbinding(b.refs[2]))
586+
# first usage has binding:
587+
(length(b.refs) > 1 && b.refs[2] isa EXPR && hasbinding(b.refs[2]))
590588
seterror!(arg, UnusedFunctionArgument)
591589
end
592590

@@ -606,8 +604,8 @@ end
606604

607605
function is_nospecialize_call(x)
608606
CSTParser.ismacrocall(x) &&
609-
CSTParser.ismacroname(x.args[1]) &&
610-
is_nospecialize(x.args[1])
607+
CSTParser.ismacroname(x.args[1]) &&
608+
is_nospecialize(x.args[1])
611609
end
612610

613611
"""
@@ -627,8 +625,8 @@ function collect_hints(x::EXPR, env, missingrefs=:all, isquoted=false, errs=Tupl
627625
push!(errs, (pos, x))
628626
elseif !isquoted
629627
if missingrefs != :none && isidentifier(x) && !hasref(x) &&
630-
!(valof(x) == "var" && parentof(x) isa EXPR && isnonstdid(parentof(x))) &&
631-
!((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"))
628+
!(valof(x) == "var" && parentof(x) isa EXPR && isnonstdid(parentof(x))) &&
629+
!((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"))
632630

633631
push!(errs, (pos, x))
634632
elseif haserror(x) && errorof(x) isa StaticLint.LintCodes
@@ -657,7 +655,7 @@ end
657655

658656
function should_mark_missing_getfield_ref(x, env)
659657
if isidentifier(x) && !hasref(x) && # x has no ref
660-
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
658+
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
661659
lhsref = refof_maybe_getfield(parentof(parentof(x)).args[1])
662660
hasref(x) && return false # We've resolved
663661
if lhsref isa SymbolServer.ModuleStore || (lhsref isa Binding && lhsref.val isa SymbolServer.ModuleStore)
@@ -726,14 +724,14 @@ function is_type_of_call_to_getproperty(x::EXPR)
726724
if iscall(x)
727725
func_name = x.args[1]
728726
return (isidentifier(func_name) && valof(func_name) == "getproperty") || # getproperty()
729-
(is_getfield_w_quotenode(func_name) && isidentifier(func_name.args[2].args[1]) && valof(func_name.args[2].args[1]) == "getproperty") # Base.getproperty()
727+
(is_getfield_w_quotenode(func_name) && isidentifier(func_name.args[2].args[1]) && valof(func_name.args[2].args[1]) == "getproperty") # Base.getproperty()
730728
end
731729
return false
732730
end
733731

734732
return parentof(x) isa EXPR && parentof(parentof(x)) isa EXPR &&
735-
((isdeclaration(parentof(x)) && x === parentof(x).args[2] && is_call_to_getproperty(parentof(parentof(x)))) ||
736-
(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))))))
733+
((isdeclaration(parentof(x)) && x === parentof(x).args[2] && is_call_to_getproperty(parentof(parentof(x)))) ||
734+
(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))))))
737735
end
738736

739737
isunionfaketype(t::SymbolServer.FakeTypeName) = t.name.name === :Union && t.name.parent isa SymbolServer.VarRef && t.name.parent.name === :Core
@@ -966,8 +964,8 @@ function check_unused_binding(b::Binding, scope::Scope)
966964
if headof(scope.expr) !== :struct && headof(scope.expr) !== :tuple && !all_underscore(valof(b.name))
967965
refs = loose_refs(b)
968966
if (isempty(refs) || length(refs) == 1 && refs[1] == b.name) &&
969-
!is_sig_arg(b.name) && !is_overwritten_in_loop(b.name) &&
970-
!is_overwritten_subsequently(b, scope) && !is_kw_of_macrocall(b)
967+
!is_sig_arg(b.name) && !is_overwritten_in_loop(b.name) &&
968+
!is_overwritten_subsequently(b, scope) && !is_kw_of_macrocall(b)
971969
seterror!(b.name, UnusedBinding)
972970
end
973971
end

0 commit comments

Comments
 (0)