11@enum (
2- LintCodes,
3-
4- MissingRef,
2+ LintCodes, MissingRef,
53 IncorrectCallArgs,
64 IncorrectIterSpec,
75 NothingEquality,
@@ -177,9 +175,9 @@ function func_nargs(x::EXPR)
177175 maxargs != = typemax (Int) && (maxargs += 1 )
178176 end
179177 elseif issplat (arg) ||
180- (isdeclaration (arg) &&
181- ((isidentifier (arg. args[2 ]) && valofid (arg. args[2 ]) == " Vararg" ) ||
182- (iscurly (arg. args[2 ]) && isidentifier (arg. args[2 ]. args[1 ]) && valofid (arg. args[2 ]. args[1 ]) == " Vararg" )))
178+ (isdeclaration (arg) &&
179+ ((isidentifier (arg. args[2 ]) && valofid (arg. args[2 ]) == " Vararg" ) ||
180+ (iscurly (arg. args[2 ]) && isidentifier (arg. args[2 ]. args[1 ]) && valofid (arg. args[2 ]. args[1 ]) == " Vararg" )))
183181 maxargs = typemax (Int)
184182 else
185183 minargs += 1
243241# compare_f_call(m_counts, call_counts) = true # fallback method
244242
245243function compare_f_call (
246- (ref_minargs, ref_maxargs, ref_kws, kwsplat),
247- (act_minargs, act_maxargs, act_kws),
248- )
244+ (ref_minargs, ref_maxargs, ref_kws, kwsplat),
245+ (act_minargs, act_maxargs, act_kws),
246+ )
249247 # check matching on positional arguments
250248 if act_maxargs == typemax (Int)
251249 act_minargs <= act_maxargs < ref_minargs && return false
@@ -265,10 +263,10 @@ end
265263
266264function is_something_with_methods (x:: Binding )
267265 (CoreTypes. isfunction (x. type) && x. val isa EXPR) ||
268- (CoreTypes. isdatatype (x. type) && x. val isa EXPR && CSTParser. defines_struct (x. val)) ||
269- (x. val isa SymbolServer. FunctionStore || x. val isa SymbolServer. DataTypeStore)
266+ (CoreTypes. isdatatype (x. type) && x. val isa EXPR && CSTParser. defines_struct (x. val)) ||
267+ (x. val isa SymbolServer. FunctionStore || x. val isa SymbolServer. DataTypeStore)
270268end
271- is_something_with_methods (x:: T ) where T <: Union{SymbolServer.FunctionStore,SymbolServer.DataTypeStore} = true
269+ is_something_with_methods (x:: T ) where T<: Union{SymbolServer.FunctionStore,SymbolServer.DataTypeStore} = true
272270is_something_with_methods (x) = false
273271
274272function check_call (x, env:: ExternalEnv )
@@ -372,13 +370,13 @@ function check_incorrect_iter_spec(x, body, env)
372370 if headof (rng) === :FLOAT || headof (rng) === :INTEGER || (iscall (rng) && refof (rng. args[1 ]) === getsymbols (env)[:Base ][:length ])
373371 seterror! (x, IncorrectIterSpec)
374372 elseif iscall (rng) && valof (rng. args[1 ]) == " :" &&
375- length (rng. args) === 3 &&
376- headof (rng. args[2 ]) === :INTEGER &&
377- iscall (rng. args[3 ]) &&
378- length (rng. args[3 ]. args) > 1 && (
379- refof (rng. args[3 ]. args[1 ]) === getsymbols (env)[:Base ][:length ] ||
380- refof (rng. args[3 ]. args[1 ]) === getsymbols (env)[:Base ][:size ]
381- )
373+ length (rng. args) === 3 &&
374+ headof (rng. args[2 ]) === :INTEGER &&
375+ iscall (rng. args[3 ]) &&
376+ length (rng. args[3 ]. args) > 1 && (
377+ refof (rng. args[3 ]. args[1 ]) === getsymbols (env)[:Base ][:length ] ||
378+ refof (rng. args[3 ]. args[1 ]) === getsymbols (env)[:Base ][:size ]
379+ )
382380 if length (x. args) >= 1
383381 lhs = x. args[1 ]
384382 arr = rng. args[3 ]. args[2 ]
@@ -421,14 +419,14 @@ end
421419function check_nothing_equality (x:: EXPR , env:: ExternalEnv )
422420 if isbinarycall (x) && length (x. args) == 3
423421 if valof (x. args[1 ]) == " ==" && (
424- (valof (x. args[2 ]) == " nothing" && refof (x. args[2 ]) === getsymbols (env)[:Core ][:nothing ]) ||
425- (valof (x. args[3 ]) == " nothing" && refof (x. args[3 ]) === getsymbols (env)[:Core ][:nothing ])
426- )
422+ (valof (x. args[2 ]) == " nothing" && refof (x. args[2 ]) === getsymbols (env)[:Core ][:nothing ]) ||
423+ (valof (x. args[3 ]) == " nothing" && refof (x. args[3 ]) === getsymbols (env)[:Core ][:nothing ])
424+ )
427425 seterror! (x. args[1 ], NothingEquality)
428426 elseif valof (x. args[1 ]) == " !=" && (
429- (valof (x. args[2 ]) == " nothing" && refof (x. args[2 ]) === getsymbols (env)[:Core ][:nothing ]) ||
430- (valof (x. args[3 ]) == " nothing" && refof (x. args[3 ]) === getsymbols (env)[:Core ][:nothing ])
431- )
427+ (valof (x. args[2 ]) == " nothing" && refof (x. args[2 ]) === getsymbols (env)[:Core ][:nothing ]) ||
428+ (valof (x. args[3 ]) == " nothing" && refof (x. args[3 ]) === getsymbols (env)[:Core ][:nothing ])
429+ )
432430 seterror! (x. args[1 ], NothingNotEq)
433431 end
434432 end
520518
521519function check_modulename (x:: EXPR )
522520 if CSTParser. defines_module (x) && # x is a module
523- scopeof (x) isa Scope && parentof (scopeof (x)) isa Scope && # it has a scope and a parent scope
524- CSTParser. defines_module (parentof (scopeof (x)). expr) && # the parent scope is a module
525- valof (CSTParser. get_name (x)) == valof (CSTParser. get_name (parentof (scopeof (x)). expr)) # their names match
521+ scopeof (x) isa Scope && parentof (scopeof (x)) isa Scope && # it has a scope and a parent scope
522+ CSTParser. defines_module (parentof (scopeof (x)). expr) && # the parent scope is a module
523+ valof (CSTParser. get_name (x)) == valof (CSTParser. get_name (parentof (scopeof (x)). expr)) # their names match
526524 seterror! (CSTParser. get_name (x), InvalidModuleName)
527525 end
528526end
@@ -532,7 +530,7 @@ function check_farg_unused(x::EXPR)
532530 if CSTParser. defines_function (x)
533531 sig = CSTParser. rem_wheres_decls (CSTParser. get_sig (x))
534532 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 ])) ||
535- (length (x. args) > 1 && headof (x. args[2 ]) === :block && length (x. args[2 ]. args) == 1 && CSTParser. isliteral (x. args[2 ]. args[1 ]))
533+ (length (x. args) > 1 && headof (x. args[2 ]) === :block && length (x. args[2 ]. args) == 1 && CSTParser. isliteral (x. args[2 ]. args[1 ]))
536534 return # Allow functions that return constants
537535 end
538536 if iscall (sig)
@@ -566,12 +564,12 @@ function check_farg_unused_(arg, arg_names)
566564 valof (b. name) isa String && all_underscore (valof (b. name)) && return false
567565
568566 if b === nothing ||
569- # no refs:
567+ # no refs:
570568 isempty (b. refs) ||
571- # only self ref:
569+ # only self ref:
572570 (length (b. refs) == 1 && first (b. refs) == b. name) ||
573- # first usage has binding:
574- (length (b. refs) > 1 && b. refs[2 ] isa EXPR && hasbinding (b. refs[2 ]))
571+ # first usage has binding:
572+ (length (b. refs) > 1 && b. refs[2 ] isa EXPR && hasbinding (b. refs[2 ]))
575573 seterror! (arg, UnusedFunctionArgument)
576574 end
577575
591589
592590function is_nospecialize_call (x)
593591 CSTParser. ismacrocall (x) &&
594- CSTParser. ismacroname (x. args[1 ]) &&
595- is_nospecialize (x. args[1 ])
592+ CSTParser. ismacroname (x. args[1 ]) &&
593+ is_nospecialize (x. args[1 ])
596594end
597595
598596"""
@@ -612,8 +610,8 @@ function collect_hints(x::EXPR, env, missingrefs=:all, isquoted=false, errs=Tupl
612610 push! (errs, (pos, x))
613611 elseif ! isquoted
614612 if missingrefs != :none && isidentifier (x) && ! hasref (x) &&
615- ! (valof (x) == " var" && parentof (x) isa EXPR && isnonstdid (parentof (x))) &&
616- ! ((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" ))
613+ ! (valof (x) == " var" && parentof (x) isa EXPR && isnonstdid (parentof (x))) &&
614+ ! ((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" ))
617615
618616 push! (errs, (pos, x))
619617 elseif haserror (x) && errorof (x) isa StaticLint. LintCodes
642640
643641function should_mark_missing_getfield_ref (x, env)
644642 if isidentifier (x) && ! hasref (x) && # x has no ref
645- 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
643+ 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
646644 lhsref = refof_maybe_getfield (parentof (parentof (x)). args[1 ])
647645 hasref (x) && return false # We've resolved
648646 if lhsref isa SymbolServer. ModuleStore || (lhsref isa Binding && lhsref. val isa SymbolServer. ModuleStore)
@@ -711,14 +709,14 @@ function is_type_of_call_to_getproperty(x::EXPR)
711709 if iscall (x)
712710 func_name = x. args[1 ]
713711 return (isidentifier (func_name) && valof (func_name) == " getproperty" ) || # getproperty()
714- (is_getfield_w_quotenode (func_name) && isidentifier (func_name. args[2 ]. args[1 ]) && valof (func_name. args[2 ]. args[1 ]) == " getproperty" ) # Base.getproperty()
712+ (is_getfield_w_quotenode (func_name) && isidentifier (func_name. args[2 ]. args[1 ]) && valof (func_name. args[2 ]. args[1 ]) == " getproperty" ) # Base.getproperty()
715713 end
716714 return false
717715 end
718716
719717 return parentof (x) isa EXPR && parentof (parentof (x)) isa EXPR &&
720- ((isdeclaration (parentof (x)) && x === parentof (x). args[2 ] && is_call_to_getproperty (parentof (parentof (x)))) ||
721- (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))))))
718+ ((isdeclaration (parentof (x)) && x === parentof (x). args[2 ] && is_call_to_getproperty (parentof (parentof (x)))) ||
719+ (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))))))
722720end
723721
724722isunionfaketype (t:: SymbolServer.FakeTypeName ) = t. name. name === :Union && t. name. parent isa SymbolServer. VarRef && t. name. parent. name === :Core
@@ -951,8 +949,8 @@ function check_unused_binding(b::Binding, scope::Scope)
951949 if headof (scope. expr) != = :struct && headof (scope. expr) != = :tuple && ! all_underscore (valof (b. name))
952950 refs = loose_refs (b)
953951 if (isempty (refs) || length (refs) == 1 && refs[1 ] == b. name) &&
954- ! is_sig_arg (b. name) && ! is_overwritten_in_loop (b. name) &&
955- ! is_overwritten_subsequently (b, scope) && ! is_kw_of_macrocall (b)
952+ ! is_sig_arg (b. name) && ! is_overwritten_in_loop (b. name) &&
953+ ! is_overwritten_subsequently (b, scope) && ! is_kw_of_macrocall (b)
956954 seterror! (b. name, UnusedBinding)
957955 end
958956 end
0 commit comments