Skip to content

Commit 6bb8831

Browse files
authored
Format files using DocumentFormat
1 parent 86eff5d commit 6bb8831

15 files changed

+283
-283
lines changed

docs/make.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ makedocs(;
77
repo="https://github.com/julia-vscode/StaticLint.jl/blob/{commit}{path}#L{line}",
88
sitename="StaticLint.jl",
99
format=Documenter.HTML(;
10-
prettyurls=prettyurls = get(ENV, "CI", nothing) == "true",
10+
prettyurls=prettyurls = get(ENV, "CI", nothing) == "true"
1111
# canonical="https://www.julia-vscode.org/StaticLint.jl",
1212
# assets=String[],
1313
),
1414
pages=[
1515
"Home" => "index.md",
1616
"Syntax Reference" => "syntax.md",
17-
],
17+
]
1818
)
1919

2020
deploydocs(;
21-
repo="github.com/julia-vscode/StaticLint.jl",
21+
repo="github.com/julia-vscode/StaticLint.jl"
2222
)

src/StaticLint.jl

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

2828
function Base.show(io::IO, m::Meta)
2929
m.binding !== nothing && show(io, m.binding)
30-
m.ref !== nothing && printstyled(io, " * ", color = :red)
31-
m.scope !== nothing && printstyled(io, " new scope", color = :green)
32-
m.error !== nothing && printstyled(io, " lint ", color = :red)
30+
m.ref !== nothing && printstyled(io, " * ", color=:red)
31+
m.scope !== nothing && printstyled(io, " new scope", color=:green)
32+
m.error !== nothing && printstyled(io, " lint ", color=:red)
3333
end
3434
hasmeta(x::EXPR) = x.meta isa Meta
3535
hasbinding(m::Meta) = m.binding isa Binding
@@ -166,7 +166,7 @@ end
166166
167167
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.
168168
"""
169-
function semantic_pass(file, modified_expr = nothing)
169+
function semantic_pass(file, modified_expr=nothing)
170170
server = file.server
171171
env = getenv(file, server)
172172
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
@@ -139,7 +139,7 @@ function mark_binding!(x::EXPR, val=x)
139139
return x
140140
end
141141

142-
function mark_parameters(sig::EXPR, params = String[])
142+
function mark_parameters(sig::EXPR, params=String[])
143143
if CSTParser.issubtypedecl(sig)
144144
mark_parameters(sig.args[1], params)
145145
elseif iswhere(sig)
@@ -365,7 +365,7 @@ function add_binding(x, state, scope=state.scope)
365365
end
366366

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

371371
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: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ end
8686

8787
function has_workspace_package(server, name)
8888
haskey(server.workspacepackages, name) &&
89-
hasscope(getcst(server.workspacepackages[name])) &&
90-
haskey(scopeof(getcst(server.workspacepackages[name])).names, name) &&
91-
scopeof(getcst(server.workspacepackages[name])).names[name] isa Binding &&
92-
scopeof(getcst(server.workspacepackages[name])).names[name].val isa EXPR &&
93-
CSTParser.defines_module(scopeof(getcst(server.workspacepackages[name])).names[name].val)
89+
hasscope(getcst(server.workspacepackages[name])) &&
90+
haskey(scopeof(getcst(server.workspacepackages[name])).names, name) &&
91+
scopeof(getcst(server.workspacepackages[name])).names[name] isa Binding &&
92+
scopeof(getcst(server.workspacepackages[name])).names[name].val isa EXPR &&
93+
CSTParser.defines_module(scopeof(getcst(server.workspacepackages[name])).names[name].val)
9494
end
9595

9696
function add_to_imported_modules(scope::Scope, name::Symbol, val)
@@ -121,8 +121,8 @@ function _get_field(par, arg, state)
121121
if par isa SymbolServer.EnvStore
122122
if (arg_scope = retrieve_scope(arg)) !== nothing && (tlm = get_named_toplevel_module(arg_scope, arg_str_rep)) !== nothing && hasbinding(tlm)
123123
return bindingof(tlm)
124-
# elseif has_workspace_package(state.server, arg_str_rep)
125-
# return scopeof(getcst(state.server.workspacepackages[arg_str_rep])).names[arg_str_rep]
124+
# elseif has_workspace_package(state.server, arg_str_rep)
125+
# return scopeof(getcst(state.server.workspacepackages[arg_str_rep])).names[arg_str_rep]
126126
elseif haskey(par, Symbol(arg_str_rep))
127127
if isempty(state.env.project_deps) || Symbol(arg_str_rep) in state.env.project_deps
128128
return par[Symbol(arg_str_rep)]

src/interface.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
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
_, server.symbolserver = SymbolServer.getstore(ssi, env)
5-
server.symbol_extends = SymbolServer.collect_extended_methods(server.symbolserver)
5+
server.symbol_extends = SymbolServer.collect_extended_methods(server.symbolserver)
66
server
77
end
88

@@ -13,7 +13,7 @@ Parse a string and run a semantic pass over it. This will mark scopes, bindings,
1313
references, and lint hints. An annotated `EXPR` is returned or, if `gethints = true`,
1414
it is paired with a collected list of errors/hints.
1515
"""
16-
function lint_string(s::String, server = setup_server(); gethints = false)
16+
function lint_string(s::String, server=setup_server(); gethints=false)
1717
empty!(server.files)
1818
f = File("", s, CSTParser.parse(s, true), nothing, server)
1919
env = getenv(f, server)
@@ -37,7 +37,7 @@ in the project will be loaded automatically (calls to `include` with complicated
3737
are not handled, see `followinclude` for details). A `FileServer` will be returned
3838
containing the `File`s of the package.
3939
"""
40-
function lint_file(rootpath, server = setup_server(); gethints = false)
40+
function lint_file(rootpath, server=setup_server(); gethints=false)
4141
empty!(server.files)
4242
root = loadfile(server, rootpath)
4343
semantic_pass(root)
@@ -46,7 +46,7 @@ function lint_file(rootpath, server = setup_server(); gethints = false)
4646
end
4747
if gethints
4848
hints = []
49-
for (p,f) in server.files
49+
for (p, f) in server.files
5050
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))])
5151
end
5252
return root, hints

src/linting/checks.jl

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
@enum(LintCodes,
2-
MissingRef,
3-
IncorrectCallArgs,
4-
IncorrectIterSpec,
5-
NothingEquality,
6-
NothingNotEq,
7-
ConstIfCondition,
8-
EqInIfConditional,
9-
PointlessOR,
10-
PointlessAND,
11-
UnusedBinding,
12-
InvalidTypeDeclaration,
13-
UnusedTypeParameter,
14-
IncludeLoop,
15-
MissingFile,
16-
InvalidModuleName,
17-
TypePiracy,
18-
UnusedFunctionArgument,
19-
CannotDeclareConst,
20-
InvalidRedefofConst,
21-
NotEqDef,
22-
KwDefaultMismatch,
23-
InappropriateUseOfLiteral,
24-
ShouldBeInALoop,
25-
TypeDeclOnGlobalVariable,
26-
UnsupportedConstLocalVariable,
27-
UnassignedKeywordArgument,
28-
CannotDefineFuncAlreadyHasValue,
29-
DuplicateFuncArgName,
30-
IncludePathContainsNULL)
2+
MissingRef,
3+
IncorrectCallArgs,
4+
IncorrectIterSpec,
5+
NothingEquality,
6+
NothingNotEq,
7+
ConstIfCondition,
8+
EqInIfConditional,
9+
PointlessOR,
10+
PointlessAND,
11+
UnusedBinding,
12+
InvalidTypeDeclaration,
13+
UnusedTypeParameter,
14+
IncludeLoop,
15+
MissingFile,
16+
InvalidModuleName,
17+
TypePiracy,
18+
UnusedFunctionArgument,
19+
CannotDeclareConst,
20+
InvalidRedefofConst,
21+
NotEqDef,
22+
KwDefaultMismatch,
23+
InappropriateUseOfLiteral,
24+
ShouldBeInALoop,
25+
TypeDeclOnGlobalVariable,
26+
UnsupportedConstLocalVariable,
27+
UnassignedKeywordArgument,
28+
CannotDefineFuncAlreadyHasValue,
29+
DuplicateFuncArgName,
30+
IncludePathContainsNULL)
3131

3232

3333

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

6464
haserror(m::Meta) = m.error !== nothing
6565
haserror(x::EXPR) = hasmeta(x) && haserror(x.meta)
@@ -173,9 +173,9 @@ function func_nargs(x::EXPR)
173173
maxargs !== typemax(Int) && (maxargs += 1)
174174
end
175175
elseif issplat(arg) ||
176-
(isdeclaration(arg) &&
177-
((isidentifier(arg.args[2]) && valofid(arg.args[2]) == "Vararg") ||
178-
(iscurly(arg.args[2]) && isidentifier(arg.args[2].args[1]) && valofid(arg.args[2].args[1]) == "Vararg")))
176+
(isdeclaration(arg) &&
177+
((isidentifier(arg.args[2]) && valofid(arg.args[2]) == "Vararg") ||
178+
(iscurly(arg.args[2]) && isidentifier(arg.args[2].args[1]) && valofid(arg.args[2].args[1]) == "Vararg")))
179179
maxargs = typemax(Int)
180180
else
181181
minargs += 1
@@ -239,9 +239,9 @@ end
239239
# compare_f_call(m_counts, call_counts) = true # fallback method
240240

241241
function compare_f_call(
242-
(ref_minargs, ref_maxargs, ref_kws, kwsplat),
243-
(act_minargs, act_maxargs, act_kws),
244-
)
242+
(ref_minargs, ref_maxargs, ref_kws, kwsplat),
243+
(act_minargs, act_maxargs, act_kws),
244+
)
245245
# check matching on positional arguments
246246
if act_maxargs == typemax(Int)
247247
act_minargs <= act_maxargs < ref_minargs && return false
@@ -261,10 +261,10 @@ end
261261

262262
function is_something_with_methods(x::Binding)
263263
(CoreTypes.isfunction(x.type) && x.val isa EXPR) ||
264-
(CoreTypes.isdatatype(x.type) && x.val isa EXPR && CSTParser.defines_struct(x.val)) ||
265-
(x.val isa SymbolServer.FunctionStore || x.val isa SymbolServer.DataTypeStore)
264+
(CoreTypes.isdatatype(x.type) && x.val isa EXPR && CSTParser.defines_struct(x.val)) ||
265+
(x.val isa SymbolServer.FunctionStore || x.val isa SymbolServer.DataTypeStore)
266266
end
267-
is_something_with_methods(x::T) where T <: Union{SymbolServer.FunctionStore,SymbolServer.DataTypeStore} = true
267+
is_something_with_methods(x::T) where {T<:Union{SymbolServer.FunctionStore,SymbolServer.DataTypeStore}} = true
268268
is_something_with_methods(x) = false
269269

270270
function check_call(x, env::ExternalEnv)
@@ -364,14 +364,14 @@ end
364364
function check_nothing_equality(x::EXPR, env::ExternalEnv)
365365
if isbinarycall(x) && length(x.args) == 3
366366
if valof(x.args[1]) == "==" && (
367-
(valof(x.args[2]) == "nothing" && refof(x.args[2]) === getsymbols(env)[:Core][:nothing]) ||
368-
(valof(x.args[3]) == "nothing" && refof(x.args[3]) === getsymbols(env)[:Core][:nothing])
369-
)
367+
(valof(x.args[2]) == "nothing" && refof(x.args[2]) === getsymbols(env)[:Core][:nothing]) ||
368+
(valof(x.args[3]) == "nothing" && refof(x.args[3]) === getsymbols(env)[:Core][:nothing])
369+
)
370370
seterror!(x.args[1], NothingEquality)
371371
elseif valof(x.args[1]) == "!=" && (
372-
(valof(x.args[2]) == "nothing" && refof(x.args[2]) === getsymbols(env)[:Core][:nothing]) ||
373-
(valof(x.args[3]) == "nothing" && refof(x.args[3]) === getsymbols(env)[:Core][:nothing])
374-
)
372+
(valof(x.args[2]) == "nothing" && refof(x.args[2]) === getsymbols(env)[:Core][:nothing]) ||
373+
(valof(x.args[3]) == "nothing" && refof(x.args[3]) === getsymbols(env)[:Core][:nothing])
374+
)
375375
seterror!(x.args[1], NothingNotEq)
376376
end
377377
end
@@ -463,9 +463,9 @@ end
463463

464464
function check_modulename(x::EXPR)
465465
if CSTParser.defines_module(x) && # x is a module
466-
scopeof(x) isa Scope && parentof(scopeof(x)) isa Scope && # it has a scope and a parent scope
467-
CSTParser.defines_module(parentof(scopeof(x)).expr) && # the parent scope is a module
468-
valof(CSTParser.get_name(x)) == valof(CSTParser.get_name(parentof(scopeof(x)).expr)) # their names match
466+
scopeof(x) isa Scope && parentof(scopeof(x)) isa Scope && # it has a scope and a parent scope
467+
CSTParser.defines_module(parentof(scopeof(x)).expr) && # the parent scope is a module
468+
valof(CSTParser.get_name(x)) == valof(CSTParser.get_name(parentof(scopeof(x)).expr)) # their names match
469469
seterror!(CSTParser.get_name(x), InvalidModuleName)
470470
end
471471
end
@@ -475,7 +475,7 @@ function check_farg_unused(x::EXPR)
475475
if CSTParser.defines_function(x)
476476
sig = CSTParser.rem_wheres_decls(CSTParser.get_sig(x))
477477
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])) ||
478-
(length(x.args) > 1 && headof(x.args[2]) === :block && length(x.args[2].args) == 1 && CSTParser.isliteral(x.args[2].args[1]))
478+
(length(x.args) > 1 && headof(x.args[2]) === :block && length(x.args[2].args) == 1 && CSTParser.isliteral(x.args[2].args[1]))
479479
return # Allow functions that return constants
480480
end
481481
if iscall(sig)
@@ -509,12 +509,12 @@ function check_farg_unused_(arg, arg_names)
509509
valof(b.name) isa String && all_underscore(valof(b.name)) && return false
510510

511511
if b === nothing ||
512-
# no refs:
512+
# no refs:
513513
isempty(b.refs) ||
514-
# only self ref:
514+
# only self ref:
515515
(length(b.refs) == 1 && first(b.refs) == b.name) ||
516-
# first usage has binding:
517-
(length(b.refs) > 1 && b.refs[2] isa EXPR && hasbinding(b.refs[2]))
516+
# first usage has binding:
517+
(length(b.refs) > 1 && b.refs[2] isa EXPR && hasbinding(b.refs[2]))
518518
seterror!(arg, UnusedFunctionArgument)
519519
end
520520

@@ -534,8 +534,8 @@ end
534534

535535
function is_nospecialize_call(x)
536536
CSTParser.ismacrocall(x) &&
537-
CSTParser.ismacroname(x.args[1]) &&
538-
is_nospecialize(x.args[1])
537+
CSTParser.ismacroname(x.args[1]) &&
538+
is_nospecialize(x.args[1])
539539
end
540540

541541
"""
@@ -555,8 +555,8 @@ function collect_hints(x::EXPR, env, missingrefs=:all, isquoted=false, errs=Tupl
555555
push!(errs, (pos, x))
556556
elseif !isquoted
557557
if missingrefs != :none && isidentifier(x) && !hasref(x) &&
558-
!(valof(x) == "var" && parentof(x) isa EXPR && isnonstdid(parentof(x))) &&
559-
!((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"))
558+
!(valof(x) == "var" && parentof(x) isa EXPR && isnonstdid(parentof(x))) &&
559+
!((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"))
560560

561561
push!(errs, (pos, x))
562562
elseif haserror(x) && errorof(x) isa StaticLint.LintCodes
@@ -585,7 +585,7 @@ end
585585

586586
function should_mark_missing_getfield_ref(x, env)
587587
if isidentifier(x) && !hasref(x) && # x has no ref
588-
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
588+
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
589589
lhsref = refof_maybe_getfield(parentof(parentof(x)).args[1])
590590
hasref(x) && return false # We've resolved
591591
if lhsref isa SymbolServer.ModuleStore || (lhsref isa Binding && lhsref.val isa SymbolServer.ModuleStore)
@@ -654,14 +654,14 @@ function is_type_of_call_to_getproperty(x::EXPR)
654654
if iscall(x)
655655
func_name = x.args[1]
656656
return (isidentifier(func_name) && valof(func_name) == "getproperty") || # getproperty()
657-
(is_getfield_w_quotenode(func_name) && isidentifier(func_name.args[2].args[1]) && valof(func_name.args[2].args[1]) == "getproperty") # Base.getproperty()
657+
(is_getfield_w_quotenode(func_name) && isidentifier(func_name.args[2].args[1]) && valof(func_name.args[2].args[1]) == "getproperty") # Base.getproperty()
658658
end
659659
return false
660660
end
661661

662662
return parentof(x) isa EXPR && parentof(parentof(x)) isa EXPR &&
663-
((isdeclaration(parentof(x)) && x === parentof(x).args[2] && is_call_to_getproperty(parentof(parentof(x)))) ||
664-
(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))))))
663+
((isdeclaration(parentof(x)) && x === parentof(x).args[2] && is_call_to_getproperty(parentof(parentof(x)))) ||
664+
(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))))))
665665
end
666666

667667
isunionfaketype(t::SymbolServer.FakeTypeName) = t.name.name === :Union && t.name.parent isa SymbolServer.VarRef && t.name.parent.name === :Core

0 commit comments

Comments
 (0)