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
249247# compare_f_call(m_counts, call_counts) = true # fallback method
250248
251249function 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
272270function 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)
276274end
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
278276is_something_with_methods (x) = false
279277
280278function 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 ]
@@ -432,14 +430,14 @@ end
432430function check_nothing_equality (x:: EXPR , env:: ExternalEnv )
433431 if isbinarycall (x) && length (x. args) == 3
434432 if valof (x. args[1 ]) == " ==" && (
435- (valof (x. args[2 ]) == " nothing" && refof (x. args[2 ]) === getsymbols (env)[:Core ][:nothing ]) ||
436- (valof (x. args[3 ]) == " nothing" && refof (x. args[3 ]) === getsymbols (env)[:Core ][:nothing ])
437- )
433+ (valof (x. args[2 ]) == " nothing" && refof (x. args[2 ]) === getsymbols (env)[:Core ][:nothing ]) ||
434+ (valof (x. args[3 ]) == " nothing" && refof (x. args[3 ]) === getsymbols (env)[:Core ][:nothing ])
435+ )
438436 seterror! (x. args[1 ], NothingEquality)
439437 elseif valof (x. args[1 ]) == " !=" && (
440- (valof (x. args[2 ]) == " nothing" && refof (x. args[2 ]) === getsymbols (env)[:Core ][:nothing ]) ||
441- (valof (x. args[3 ]) == " nothing" && refof (x. args[3 ]) === getsymbols (env)[:Core ][:nothing ])
442- )
438+ (valof (x. args[2 ]) == " nothing" && refof (x. args[2 ]) === getsymbols (env)[:Core ][:nothing ]) ||
439+ (valof (x. args[3 ]) == " nothing" && refof (x. args[3 ]) === getsymbols (env)[:Core ][:nothing ])
440+ )
443441 seterror! (x. args[1 ], NothingNotEq)
444442 end
445443 end
531529
532530function check_modulename (x:: EXPR )
533531 if CSTParser. defines_module (x) && # x is a module
534- scopeof (x) isa Scope && parentof (scopeof (x)) isa Scope && # it has a scope and a parent scope
535- CSTParser. defines_module (parentof (scopeof (x)). expr) && # the parent scope is a module
536- valof (CSTParser. get_name (x)) == valof (CSTParser. get_name (parentof (scopeof (x)). expr)) # their names match
532+ scopeof (x) isa Scope && parentof (scopeof (x)) isa Scope && # it has a scope and a parent scope
533+ CSTParser. defines_module (parentof (scopeof (x)). expr) && # the parent scope is a module
534+ valof (CSTParser. get_name (x)) == valof (CSTParser. get_name (parentof (scopeof (x)). expr)) # their names match
537535 seterror! (CSTParser. get_name (x), InvalidModuleName)
538536 end
539537end
@@ -543,7 +541,7 @@ function check_farg_unused(x::EXPR)
543541 if CSTParser. defines_function (x)
544542 sig = CSTParser. rem_wheres_decls (CSTParser. get_sig (x))
545543 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 ])) ||
546- (length (x. args) > 1 && headof (x. args[2 ]) === :block && length (x. args[2 ]. args) == 1 && CSTParser. isliteral (x. args[2 ]. args[1 ]))
544+ (length (x. args) > 1 && headof (x. args[2 ]) === :block && length (x. args[2 ]. args) == 1 && CSTParser. isliteral (x. args[2 ]. args[1 ]))
547545 return # Allow functions that return constants
548546 end
549547 if iscall (sig)
@@ -580,12 +578,12 @@ function check_farg_unused_(arg, arg_names)
580578 valof (b. name) isa String && all_underscore (valof (b. name)) && return false
581579
582580 if b === nothing ||
583- # no refs:
581+ # no refs:
584582 isempty (b. refs) ||
585- # only self ref:
583+ # only self ref:
586584 (length (b. refs) == 1 && first (b. refs) == b. name) ||
587- # first usage has binding:
588- (length (b. refs) > 1 && b. refs[2 ] isa EXPR && hasbinding (b. refs[2 ]))
585+ # first usage has binding:
586+ (length (b. refs) > 1 && b. refs[2 ] isa EXPR && hasbinding (b. refs[2 ]))
589587 seterror! (arg, UnusedFunctionArgument)
590588 end
591589
605603
606604function is_nospecialize_call (x)
607605 CSTParser. ismacrocall (x) &&
608- CSTParser. ismacroname (x. args[1 ]) &&
609- is_nospecialize (x. args[1 ])
606+ CSTParser. ismacroname (x. args[1 ]) &&
607+ is_nospecialize (x. args[1 ])
610608end
611609
612610"""
@@ -626,8 +624,8 @@ function collect_hints(x::EXPR, env, missingrefs=:all, isquoted=false, errs=Tupl
626624 push! (errs, (pos, x))
627625 elseif ! isquoted
628626 if missingrefs != :none && isidentifier (x) && ! hasref (x) &&
629- ! (valof (x) == " var" && parentof (x) isa EXPR && isnonstdid (parentof (x))) &&
630- ! ((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" ))
627+ ! (valof (x) == " var" && parentof (x) isa EXPR && isnonstdid (parentof (x))) &&
628+ ! ((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" ))
631629
632630 push! (errs, (pos, x))
633631 elseif haserror (x) && errorof (x) isa StaticLint. LintCodes
656654
657655function should_mark_missing_getfield_ref (x, env)
658656 if isidentifier (x) && ! hasref (x) && # x has no ref
659- 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
657+ 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
660658 lhsref = refof_maybe_getfield (parentof (parentof (x)). args[1 ])
661659 hasref (x) && return false # We've resolved
662660 if lhsref isa SymbolServer. ModuleStore || (lhsref isa Binding && lhsref. val isa SymbolServer. ModuleStore)
@@ -725,14 +723,14 @@ function is_type_of_call_to_getproperty(x::EXPR)
725723 if iscall (x)
726724 func_name = x. args[1 ]
727725 return (isidentifier (func_name) && valof (func_name) == " getproperty" ) || # getproperty()
728- (is_getfield_w_quotenode (func_name) && isidentifier (func_name. args[2 ]. args[1 ]) && valof (func_name. args[2 ]. args[1 ]) == " getproperty" ) # Base.getproperty()
726+ (is_getfield_w_quotenode (func_name) && isidentifier (func_name. args[2 ]. args[1 ]) && valof (func_name. args[2 ]. args[1 ]) == " getproperty" ) # Base.getproperty()
729727 end
730728 return false
731729 end
732730
733731 return parentof (x) isa EXPR && parentof (parentof (x)) isa EXPR &&
734- ((isdeclaration (parentof (x)) && x === parentof (x). args[2 ] && is_call_to_getproperty (parentof (parentof (x)))) ||
735- (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))))))
732+ ((isdeclaration (parentof (x)) && x === parentof (x). args[2 ] && is_call_to_getproperty (parentof (parentof (x)))) ||
733+ (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))))))
736734end
737735
738736isunionfaketype (t:: SymbolServer.FakeTypeName ) = t. name. name === :Union && t. name. parent isa SymbolServer. VarRef && t. name. parent. name === :Core
@@ -965,8 +963,8 @@ function check_unused_binding(b::Binding, scope::Scope)
965963 if headof (scope. expr) != = :struct && headof (scope. expr) != = :tuple && ! all_underscore (valof (b. name))
966964 refs = loose_refs (b)
967965 if (isempty (refs) || length (refs) == 1 && refs[1 ] == b. name) &&
968- ! is_sig_arg (b. name) && ! is_overwritten_in_loop (b. name) &&
969- ! is_overwritten_subsequently (b, scope) && ! is_kw_of_macrocall (b)
966+ ! is_sig_arg (b. name) && ! is_overwritten_in_loop (b. name) &&
967+ ! is_overwritten_subsequently (b, scope) && ! is_kw_of_macrocall (b)
970968 seterror! (b. name, UnusedBinding)
971969 end
972970 end
0 commit comments