1
1
@enum (
2
- LintCodes,
3
-
4
- MissingRef,
2
+ LintCodes, MissingRef,
5
3
IncorrectCallArgs,
6
4
IncorrectIterSpec,
7
5
NothingEquality,
@@ -181,9 +179,9 @@ function func_nargs(x::EXPR)
181
179
maxargs != = typemax (Int) && (maxargs += 1 )
182
180
end
183
181
elseif issplat (arg) ||
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" )))
182
+ (isdeclaration (arg) &&
183
+ ((isidentifier (arg. args[2 ]) && valofid (arg. args[2 ]) == " Vararg" ) ||
184
+ (iscurly (arg. args[2 ]) && isidentifier (arg. args[2 ]. args[1 ]) && valofid (arg. args[2 ]. args[1 ]) == " Vararg" )))
187
185
maxargs = typemax (Int)
188
186
else
189
187
minargs += 1
247
245
# compare_f_call(m_counts, call_counts) = true # fallback method
248
246
249
247
function compare_f_call (
250
- (ref_minargs, ref_maxargs, ref_kws, kwsplat),
251
- (act_minargs, act_maxargs, act_kws),
252
- )
248
+ (ref_minargs, ref_maxargs, ref_kws, kwsplat),
249
+ (act_minargs, act_maxargs, act_kws),
250
+ )
253
251
# check matching on positional arguments
254
252
if act_maxargs == typemax (Int)
255
253
act_minargs <= act_maxargs < ref_minargs && return false
@@ -269,10 +267,10 @@ end
269
267
270
268
function is_something_with_methods (x:: Binding )
271
269
(CoreTypes. isfunction (x. type) && x. val isa EXPR) ||
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)
270
+ (CoreTypes. isdatatype (x. type) && x. val isa EXPR && CSTParser. defines_struct (x. val)) ||
271
+ (x. val isa SymbolServer. FunctionStore || x. val isa SymbolServer. DataTypeStore)
274
272
end
275
- is_something_with_methods (x:: T ) where T <: Union{SymbolServer.FunctionStore,SymbolServer.DataTypeStore} = true
273
+ is_something_with_methods (x:: T ) where T<: Union{SymbolServer.FunctionStore,SymbolServer.DataTypeStore} = true
276
274
is_something_with_methods (x) = false
277
275
278
276
function check_call (x, env:: ExternalEnv )
@@ -376,13 +374,13 @@ function check_incorrect_iter_spec(x, body, env)
376
374
if headof (rng) === :FLOAT || headof (rng) === :INTEGER || (iscall (rng) && refof (rng. args[1 ]) === getsymbols (env)[:Base ][:length ])
377
375
seterror! (x, IncorrectIterSpec)
378
376
elseif iscall (rng) && valof (rng. args[1 ]) == " :" &&
379
- length (rng. args) === 3 &&
380
- headof (rng. args[2 ]) === :INTEGER &&
381
- iscall (rng. args[3 ]) &&
382
- length (rng. args[3 ]. args) > 1 && (
383
- refof (rng. args[3 ]. args[1 ]) === getsymbols (env)[:Base ][:length ] ||
384
- refof (rng. args[3 ]. args[1 ]) === getsymbols (env)[:Base ][:size ]
385
- )
377
+ length (rng. args) === 3 &&
378
+ headof (rng. args[2 ]) === :INTEGER &&
379
+ iscall (rng. args[3 ]) &&
380
+ length (rng. args[3 ]. args) > 1 && (
381
+ refof (rng. args[3 ]. args[1 ]) === getsymbols (env)[:Base ][:length ] ||
382
+ refof (rng. args[3 ]. args[1 ]) === getsymbols (env)[:Base ][:size ]
383
+ )
386
384
if length (x. args) >= 1
387
385
lhs = x. args[1 ]
388
386
arr = rng. args[3 ]. args[2 ]
@@ -425,14 +423,14 @@ end
425
423
function check_nothing_equality (x:: EXPR , env:: ExternalEnv )
426
424
if isbinarycall (x) && length (x. args) == 3
427
425
if valof (x. args[1 ]) == " ==" && (
428
- (valof (x. args[2 ]) == " nothing" && refof (x. args[2 ]) === getsymbols (env)[:Core ][:nothing ]) ||
429
- (valof (x. args[3 ]) == " nothing" && refof (x. args[3 ]) === getsymbols (env)[:Core ][:nothing ])
430
- )
426
+ (valof (x. args[2 ]) == " nothing" && refof (x. args[2 ]) === getsymbols (env)[:Core ][:nothing ]) ||
427
+ (valof (x. args[3 ]) == " nothing" && refof (x. args[3 ]) === getsymbols (env)[:Core ][:nothing ])
428
+ )
431
429
seterror! (x. args[1 ], NothingEquality)
432
430
elseif valof (x. args[1 ]) == " !=" && (
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
- )
431
+ (valof (x. args[2 ]) == " nothing" && refof (x. args[2 ]) === getsymbols (env)[:Core ][:nothing ]) ||
432
+ (valof (x. args[3 ]) == " nothing" && refof (x. args[3 ]) === getsymbols (env)[:Core ][:nothing ])
433
+ )
436
434
seterror! (x. args[1 ], NothingNotEq)
437
435
end
438
436
end
524
522
525
523
function check_modulename (x:: EXPR )
526
524
if CSTParser. defines_module (x) && # x is a module
527
- scopeof (x) isa Scope && parentof (scopeof (x)) isa Scope && # it has a scope and a parent scope
528
- CSTParser. defines_module (parentof (scopeof (x)). expr) && # the parent scope is a module
529
- valof (CSTParser. get_name (x)) == valof (CSTParser. get_name (parentof (scopeof (x)). expr)) # their names match
525
+ scopeof (x) isa Scope && parentof (scopeof (x)) isa Scope && # it has a scope and a parent scope
526
+ CSTParser. defines_module (parentof (scopeof (x)). expr) && # the parent scope is a module
527
+ valof (CSTParser. get_name (x)) == valof (CSTParser. get_name (parentof (scopeof (x)). expr)) # their names match
530
528
seterror! (CSTParser. get_name (x), InvalidModuleName)
531
529
end
532
530
end
@@ -536,7 +534,7 @@ function check_farg_unused(x::EXPR)
536
534
if CSTParser. defines_function (x)
537
535
sig = CSTParser. rem_wheres_decls (CSTParser. get_sig (x))
538
536
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 ])) ||
539
- (length (x. args) > 1 && headof (x. args[2 ]) === :block && length (x. args[2 ]. args) == 1 && CSTParser. isliteral (x. args[2 ]. args[1 ]))
537
+ (length (x. args) > 1 && headof (x. args[2 ]) === :block && length (x. args[2 ]. args) == 1 && CSTParser. isliteral (x. args[2 ]. args[1 ]))
540
538
return # Allow functions that return constants
541
539
end
542
540
if iscall (sig)
@@ -573,12 +571,12 @@ function check_farg_unused_(arg, arg_names)
573
571
valof (b. name) isa String && all_underscore (valof (b. name)) && return false
574
572
575
573
if b === nothing ||
576
- # no refs:
574
+ # no refs:
577
575
isempty (b. refs) ||
578
- # only self ref:
576
+ # only self ref:
579
577
(length (b. refs) == 1 && first (b. refs) == b. name) ||
580
- # first usage has binding:
581
- (length (b. refs) > 1 && b. refs[2 ] isa EXPR && hasbinding (b. refs[2 ]))
578
+ # first usage has binding:
579
+ (length (b. refs) > 1 && b. refs[2 ] isa EXPR && hasbinding (b. refs[2 ]))
582
580
seterror! (arg, UnusedFunctionArgument)
583
581
end
584
582
598
596
599
597
function is_nospecialize_call (x)
600
598
CSTParser. ismacrocall (x) &&
601
- CSTParser. ismacroname (x. args[1 ]) &&
602
- is_nospecialize (x. args[1 ])
599
+ CSTParser. ismacroname (x. args[1 ]) &&
600
+ is_nospecialize (x. args[1 ])
603
601
end
604
602
605
603
"""
@@ -619,8 +617,8 @@ function collect_hints(x::EXPR, env, missingrefs=:all, isquoted=false, errs=Tupl
619
617
push! (errs, (pos, x))
620
618
elseif ! isquoted
621
619
if missingrefs != :none && isidentifier (x) && ! hasref (x) &&
622
- ! (valof (x) == " var" && parentof (x) isa EXPR && isnonstdid (parentof (x))) &&
623
- ! ((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" ))
620
+ ! (valof (x) == " var" && parentof (x) isa EXPR && isnonstdid (parentof (x))) &&
621
+ ! ((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" ))
624
622
625
623
push! (errs, (pos, x))
626
624
elseif haserror (x) && errorof (x) isa StaticLint. LintCodes
649
647
650
648
function should_mark_missing_getfield_ref (x, env)
651
649
if isidentifier (x) && ! hasref (x) && # x has no ref
652
- 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
650
+ 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
653
651
lhsref = refof_maybe_getfield (parentof (parentof (x)). args[1 ])
654
652
hasref (x) && return false # We've resolved
655
653
if lhsref isa SymbolServer. ModuleStore || (lhsref isa Binding && lhsref. val isa SymbolServer. ModuleStore)
@@ -718,14 +716,14 @@ function is_type_of_call_to_getproperty(x::EXPR)
718
716
if iscall (x)
719
717
func_name = x. args[1 ]
720
718
return (isidentifier (func_name) && valof (func_name) == " getproperty" ) || # getproperty()
721
- (is_getfield_w_quotenode (func_name) && isidentifier (func_name. args[2 ]. args[1 ]) && valof (func_name. args[2 ]. args[1 ]) == " getproperty" ) # Base.getproperty()
719
+ (is_getfield_w_quotenode (func_name) && isidentifier (func_name. args[2 ]. args[1 ]) && valof (func_name. args[2 ]. args[1 ]) == " getproperty" ) # Base.getproperty()
722
720
end
723
721
return false
724
722
end
725
723
726
724
return parentof (x) isa EXPR && parentof (parentof (x)) isa EXPR &&
727
- ((isdeclaration (parentof (x)) && x === parentof (x). args[2 ] && is_call_to_getproperty (parentof (parentof (x)))) ||
728
- (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))))))
725
+ ((isdeclaration (parentof (x)) && x === parentof (x). args[2 ] && is_call_to_getproperty (parentof (parentof (x)))) ||
726
+ (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))))))
729
727
end
730
728
731
729
isunionfaketype (t:: SymbolServer.FakeTypeName ) = t. name. name === :Union && t. name. parent isa SymbolServer. VarRef && t. name. parent. name === :Core
@@ -958,8 +956,8 @@ function check_unused_binding(b::Binding, scope::Scope)
958
956
if headof (scope. expr) != = :struct && headof (scope. expr) != = :tuple && ! all_underscore (valof (b. name))
959
957
refs = loose_refs (b)
960
958
if (isempty (refs) || length (refs) == 1 && refs[1 ] == b. name) &&
961
- ! is_sig_arg (b. name) && ! is_overwritten_in_loop (b. name) &&
962
- ! is_overwritten_subsequently (b, scope) && ! is_kw_of_macrocall (b)
959
+ ! is_sig_arg (b. name) && ! is_overwritten_in_loop (b. name) &&
960
+ ! is_overwritten_subsequently (b, scope) && ! is_kw_of_macrocall (b)
963
961
seterror! (b. name, UnusedBinding)
964
962
end
965
963
end
0 commit comments