Skip to content

Commit 62862bd

Browse files
authored
Format files using DocumentFormat
1 parent 06d008e commit 62862bd

File tree

14 files changed

+284
-284
lines changed

14 files changed

+284
-284
lines changed

docs/make.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ using StaticLint
22
using Documenter
33

44
makedocs(;
5-
modules=[StaticLint],
6-
authors="Julia VSCode",
7-
repo="https://github.com/julia-vscode/StaticLint.jl/blob/{commit}{path}#L{line}",
8-
sitename="StaticLint.jl",
9-
format=Documenter.HTML(;
10-
prettyurls=prettyurls = get(ENV, "CI", nothing) == "true",
5+
modules = [StaticLint],
6+
authors = "Julia VSCode",
7+
repo = "https://github.com/julia-vscode/StaticLint.jl/blob/{commit}{path}#L{line}",
8+
sitename = "StaticLint.jl",
9+
format = Documenter.HTML(;
10+
prettyurls = prettyurls = get(ENV, "CI", nothing) == "true"
1111
# canonical="https://www.julia-vscode.org/StaticLint.jl",
1212
# assets=String[],
1313
),
14-
pages=[
14+
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/bindings.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Binding(x::EXPR) = Binding(CSTParser.get_name(x), x, nothing, [])
1717
function Base.show(io::IO, b::Binding)
1818
printstyled(io, " Binding(", to_codeobject(b.name),
1919
b.type === nothing ? "" : ":: ",
20-
b.refs isa Vector ? "($(length(b.refs)) refs))" : ")", color=:blue)
20+
b.refs isa Vector ? "($(length(b.refs)) refs))" : ")", color = :blue)
2121
end
2222

2323

@@ -120,7 +120,7 @@ function mark_bindings!(x::EXPR, state)
120120
end
121121

122122

123-
function mark_binding!(x::EXPR, val=x)
123+
function mark_binding!(x::EXPR, val = x)
124124
if CSTParser.iskwarg(x) || (CSTParser.isdeclaration(x) && CSTParser.istuple(x.args[1]))
125125
mark_binding!(x.args[1], x)
126126
elseif CSTParser.istuple(x) || CSTParser.isparameters(x)
@@ -268,7 +268,7 @@ Add the binding of `x` to the current scope. Special handling is required for:
268268
269269
Some simple type inference is run.
270270
"""
271-
function add_binding(x, state, scope=state.scope)
271+
function add_binding(x, state, scope = state.scope)
272272
if bindingof(x) isa Binding
273273
b = bindingof(x)
274274
if isidentifier(b.name)
@@ -366,7 +366,7 @@ function add_binding(x, state, scope=state.scope)
366366
end
367367

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

372372
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
@@ -1,4 +1,4 @@
1-
function resolve_import_block(x::EXPR, state::State, root, usinged, markfinal=true)
1+
function resolve_import_block(x::EXPR, state::State, root, usinged, markfinal = true)
22
if x.head == :as
33
resolve_import_block(x.args[1], state, root, usinged, markfinal)
44
if x.args[2].meta === nothing
@@ -37,7 +37,7 @@ function resolve_import_block(x::EXPR, state::State, root, usinged, markfinal=tr
3737
end
3838
end
3939

40-
function resolve_import(x::EXPR, state::State, root=getsymbols(state))
40+
function resolve_import(x::EXPR, state::State, root = getsymbols(state))
4141
if headof(x) === :using || headof(x) === :import
4242
usinged = headof(x) === :using
4343
if length(x.args) > 0 && isoperator(headof(x.args[1])) && valof(headof(x.args[1])) == ":"
@@ -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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ function setup_server(env = dirname(SymbolServer.Pkg.Types.Context().env.project
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

@@ -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: 57 additions & 57 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)
@@ -457,9 +457,9 @@ end
457457

458458
function check_modulename(x::EXPR)
459459
if CSTParser.defines_module(x) && # x is a module
460-
scopeof(x) isa Scope && parentof(scopeof(x)) isa Scope && # it has a scope and a parent scope
461-
CSTParser.defines_module(parentof(scopeof(x)).expr) && # the parent scope is a module
462-
valof(CSTParser.get_name(x)) == valof(CSTParser.get_name(parentof(scopeof(x)).expr)) # their names match
460+
scopeof(x) isa Scope && parentof(scopeof(x)) isa Scope && # it has a scope and a parent scope
461+
CSTParser.defines_module(parentof(scopeof(x)).expr) && # the parent scope is a module
462+
valof(CSTParser.get_name(x)) == valof(CSTParser.get_name(parentof(scopeof(x)).expr)) # their names match
463463
seterror!(CSTParser.get_name(x), InvalidModuleName)
464464
end
465465
end
@@ -469,7 +469,7 @@ function check_farg_unused(x::EXPR)
469469
if CSTParser.defines_function(x)
470470
sig = CSTParser.rem_wheres_decls(CSTParser.get_sig(x))
471471
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])) ||
472-
(length(x.args) > 1 && headof(x.args[2]) === :block && length(x.args[2].args) == 1 && CSTParser.isliteral(x.args[2].args[1]))
472+
(length(x.args) > 1 && headof(x.args[2]) === :block && length(x.args[2].args) == 1 && CSTParser.isliteral(x.args[2].args[1]))
473473
return # Allow functions that return constants
474474
end
475475
if iscall(sig)
@@ -503,12 +503,12 @@ function check_farg_unused_(arg, arg_names)
503503
valof(b.name) isa String && all_underscore(valof(b.name)) && return false
504504

505505
if b === nothing ||
506-
# no refs:
506+
# no refs:
507507
isempty(b.refs) ||
508-
# only self ref:
508+
# only self ref:
509509
(length(b.refs) == 1 && first(b.refs) == b.name) ||
510-
# first usage has binding:
511-
(length(b.refs) > 1 && b.refs[2] isa EXPR && hasbinding(b.refs[2]))
510+
# first usage has binding:
511+
(length(b.refs) > 1 && b.refs[2] isa EXPR && hasbinding(b.refs[2]))
512512
seterror!(arg, UnusedFunctionArgument)
513513
end
514514

@@ -528,8 +528,8 @@ end
528528

529529
function is_nospecialize_call(x)
530530
CSTParser.ismacrocall(x) &&
531-
CSTParser.ismacroname(x.args[1]) &&
532-
is_nospecialize(x.args[1])
531+
CSTParser.ismacroname(x.args[1]) &&
532+
is_nospecialize(x.args[1])
533533
end
534534

535535
"""
@@ -538,7 +538,7 @@ collect_hints(x::EXPR, env, missingrefs = :all, isquoted = false, errs = Tuple{I
538538
Collect hints and errors from an expression. `missingrefs` = (:none, :id, :all) determines whether unresolved
539539
identifiers are marked, the :all option will mark identifiers used in getfield calls."
540540
"""
541-
function collect_hints(x::EXPR, env, missingrefs=:all, isquoted=false, errs=Tuple{Int,EXPR}[], pos=0)
541+
function collect_hints(x::EXPR, env, missingrefs = :all, isquoted = false, errs = Tuple{Int,EXPR}[], pos = 0)
542542
if quoted(x)
543543
isquoted = true
544544
elseif isquoted && unquoted(x)
@@ -549,8 +549,8 @@ function collect_hints(x::EXPR, env, missingrefs=:all, isquoted=false, errs=Tupl
549549
push!(errs, (pos, x))
550550
elseif !isquoted
551551
if missingrefs != :none && isidentifier(x) && !hasref(x) &&
552-
!(valof(x) == "var" && parentof(x) isa EXPR && isnonstdid(parentof(x))) &&
553-
!((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"))
552+
!(valof(x) == "var" && parentof(x) isa EXPR && isnonstdid(parentof(x))) &&
553+
!((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"))
554554

555555
push!(errs, (pos, x))
556556
elseif haserror(x) && errorof(x) isa StaticLint.LintCodes
@@ -579,7 +579,7 @@ end
579579

580580
function should_mark_missing_getfield_ref(x, env)
581581
if isidentifier(x) && !hasref(x) && # x has no ref
582-
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
582+
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
583583
lhsref = refof_maybe_getfield(parentof(parentof(x)).args[1])
584584
hasref(x) && return false # We've resolved
585585
if lhsref isa SymbolServer.ModuleStore || (lhsref isa Binding && lhsref.val isa SymbolServer.ModuleStore)
@@ -648,14 +648,14 @@ function is_type_of_call_to_getproperty(x::EXPR)
648648
if iscall(x)
649649
func_name = x.args[1]
650650
return (isidentifier(func_name) && valof(func_name) == "getproperty") || # getproperty()
651-
(is_getfield_w_quotenode(func_name) && isidentifier(func_name.args[2].args[1]) && valof(func_name.args[2].args[1]) == "getproperty") # Base.getproperty()
651+
(is_getfield_w_quotenode(func_name) && isidentifier(func_name.args[2].args[1]) && valof(func_name.args[2].args[1]) == "getproperty") # Base.getproperty()
652652
end
653653
return false
654654
end
655655

656656
return parentof(x) isa EXPR && parentof(parentof(x)) isa EXPR &&
657-
((isdeclaration(parentof(x)) && x === parentof(x).args[2] && is_call_to_getproperty(parentof(parentof(x)))) ||
658-
(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))))))
657+
((isdeclaration(parentof(x)) && x === parentof(x).args[2] && is_call_to_getproperty(parentof(parentof(x)))) ||
658+
(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))))))
659659
end
660660

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

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

0 commit comments

Comments
 (0)