1
1
@enum (
2
- LintCodes,
3
-
4
- MissingRef,
2
+ LintCodes, MissingRef,
5
3
IncorrectCallArgs,
6
4
IncorrectIterSpec,
7
5
NothingEquality,
@@ -177,9 +175,9 @@ function func_nargs(x::EXPR)
177
175
maxargs != = typemax (Int) && (maxargs += 1 )
178
176
end
179
177
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" )))
183
181
maxargs = typemax (Int)
184
182
else
185
183
minargs += 1
243
241
# compare_f_call(m_counts, call_counts) = true # fallback method
244
242
245
243
function 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
+ )
249
247
# check matching on positional arguments
250
248
if act_maxargs == typemax (Int)
251
249
act_minargs <= act_maxargs < ref_minargs && return false
@@ -265,10 +263,10 @@ end
265
263
266
264
function is_something_with_methods (x:: Binding )
267
265
(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)
270
268
end
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
272
270
is_something_with_methods (x) = false
273
271
274
272
function check_call (x, env:: ExternalEnv )
@@ -372,13 +370,13 @@ function check_incorrect_iter_spec(x, body, env)
372
370
if headof (rng) === :FLOAT || headof (rng) === :INTEGER || (iscall (rng) && refof (rng. args[1 ]) === getsymbols (env)[:Base ][:length ])
373
371
seterror! (x, IncorrectIterSpec)
374
372
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
+ )
382
380
if length (x. args) >= 1
383
381
lhs = x. args[1 ]
384
382
arr = rng. args[3 ]. args[2 ]
@@ -421,14 +419,14 @@ end
421
419
function check_nothing_equality (x:: EXPR , env:: ExternalEnv )
422
420
if isbinarycall (x) && length (x. args) == 3
423
421
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
+ )
427
425
seterror! (x. args[1 ], NothingEquality)
428
426
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
+ )
432
430
seterror! (x. args[1 ], NothingNotEq)
433
431
end
434
432
end
520
518
521
519
function check_modulename (x:: EXPR )
522
520
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
526
524
seterror! (CSTParser. get_name (x), InvalidModuleName)
527
525
end
528
526
end
@@ -532,7 +530,7 @@ function check_farg_unused(x::EXPR)
532
530
if CSTParser. defines_function (x)
533
531
sig = CSTParser. rem_wheres_decls (CSTParser. get_sig (x))
534
532
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 ]))
536
534
return # Allow functions that return constants
537
535
end
538
536
if iscall (sig)
@@ -566,12 +564,12 @@ function check_farg_unused_(arg, arg_names)
566
564
valof (b. name) isa String && all_underscore (valof (b. name)) && return false
567
565
568
566
if b === nothing ||
569
- # no refs:
567
+ # no refs:
570
568
isempty (b. refs) ||
571
- # only self ref:
569
+ # only self ref:
572
570
(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 ]))
575
573
seterror! (arg, UnusedFunctionArgument)
576
574
end
577
575
591
589
592
590
function is_nospecialize_call (x)
593
591
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 ])
596
594
end
597
595
598
596
"""
@@ -612,8 +610,8 @@ function collect_hints(x::EXPR, env, missingrefs=:all, isquoted=false, errs=Tupl
612
610
push! (errs, (pos, x))
613
611
elseif ! isquoted
614
612
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" ))
617
615
618
616
push! (errs, (pos, x))
619
617
elseif haserror (x) && errorof (x) isa StaticLint. LintCodes
642
640
643
641
function should_mark_missing_getfield_ref (x, env)
644
642
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
646
644
lhsref = refof_maybe_getfield (parentof (parentof (x)). args[1 ])
647
645
hasref (x) && return false # We've resolved
648
646
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)
711
709
if iscall (x)
712
710
func_name = x. args[1 ]
713
711
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()
715
713
end
716
714
return false
717
715
end
718
716
719
717
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))))))
722
720
end
723
721
724
722
isunionfaketype (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)
951
949
if headof (scope. expr) != = :struct && headof (scope. expr) != = :tuple && ! all_underscore (valof (b. name))
952
950
refs = loose_refs (b)
953
951
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)
956
954
seterror! (b. name, UnusedBinding)
957
955
end
958
956
end
0 commit comments