1
1
@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)
31
31
32
32
33
33
@@ -59,7 +59,7 @@ const LintCodeDescriptions = Dict{LintCodes,String}(IncorrectCallArgs => "Possib
59
59
CannotDefineFuncAlreadyHasValue => " Cannot define function ; it already has a value." ,
60
60
DuplicateFuncArgName => " Function argument name not unique." ,
61
61
IncludePathContainsNULL => " Cannot include file, path cotains NULL characters."
62
- )
62
+ )
63
63
64
64
haserror (m:: Meta ) = m. error != = nothing
65
65
haserror (x:: EXPR ) = hasmeta (x) && haserror (x. meta)
@@ -173,9 +173,9 @@ function func_nargs(x::EXPR)
173
173
maxargs != = typemax (Int) && (maxargs += 1 )
174
174
end
175
175
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" )))
179
179
maxargs = typemax (Int)
180
180
else
181
181
minargs += 1
239
239
# compare_f_call(m_counts, call_counts) = true # fallback method
240
240
241
241
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
+ )
245
245
# check matching on positional arguments
246
246
if act_maxargs == typemax (Int)
247
247
act_minargs <= act_maxargs < ref_minargs && return false
@@ -261,10 +261,10 @@ end
261
261
262
262
function is_something_with_methods (x:: Binding )
263
263
(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)
266
266
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
268
268
is_something_with_methods (x) = false
269
269
270
270
function check_call (x, env:: ExternalEnv )
@@ -364,14 +364,14 @@ end
364
364
function check_nothing_equality (x:: EXPR , env:: ExternalEnv )
365
365
if isbinarycall (x) && length (x. args) == 3
366
366
if valof (x. args[1 ]) == " ==" && (
367
- (valof (x. args[2 ]) == " nothing" && refof (x. args[2 ]) === getsymbols (env)[:Core ][:nothing ]) ||
368
- (valof (x. args[3 ]) == " nothing" && refof (x. args[3 ]) === getsymbols (env)[:Core ][:nothing ])
369
- )
367
+ (valof (x. args[2 ]) == " nothing" && refof (x. args[2 ]) === getsymbols (env)[:Core ][:nothing ]) ||
368
+ (valof (x. args[3 ]) == " nothing" && refof (x. args[3 ]) === getsymbols (env)[:Core ][:nothing ])
369
+ )
370
370
seterror! (x. args[1 ], NothingEquality)
371
371
elseif valof (x. args[1 ]) == " !=" && (
372
- (valof (x. args[2 ]) == " nothing" && refof (x. args[2 ]) === getsymbols (env)[:Core ][:nothing ]) ||
373
- (valof (x. args[3 ]) == " nothing" && refof (x. args[3 ]) === getsymbols (env)[:Core ][:nothing ])
374
- )
372
+ (valof (x. args[2 ]) == " nothing" && refof (x. args[2 ]) === getsymbols (env)[:Core ][:nothing ]) ||
373
+ (valof (x. args[3 ]) == " nothing" && refof (x. args[3 ]) === getsymbols (env)[:Core ][:nothing ])
374
+ )
375
375
seterror! (x. args[1 ], NothingNotEq)
376
376
end
377
377
end
463
463
464
464
function check_modulename (x:: EXPR )
465
465
if CSTParser. defines_module (x) && # x is a module
466
- scopeof (x) isa Scope && parentof (scopeof (x)) isa Scope && # it has a scope and a parent scope
467
- CSTParser. defines_module (parentof (scopeof (x)). expr) && # the parent scope is a module
468
- valof (CSTParser. get_name (x)) == valof (CSTParser. get_name (parentof (scopeof (x)). expr)) # their names match
466
+ scopeof (x) isa Scope && parentof (scopeof (x)) isa Scope && # it has a scope and a parent scope
467
+ CSTParser. defines_module (parentof (scopeof (x)). expr) && # the parent scope is a module
468
+ valof (CSTParser. get_name (x)) == valof (CSTParser. get_name (parentof (scopeof (x)). expr)) # their names match
469
469
seterror! (CSTParser. get_name (x), InvalidModuleName)
470
470
end
471
471
end
@@ -475,7 +475,7 @@ function check_farg_unused(x::EXPR)
475
475
if CSTParser. defines_function (x)
476
476
sig = CSTParser. rem_wheres_decls (CSTParser. get_sig (x))
477
477
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 ])) ||
478
- (length (x. args) > 1 && headof (x. args[2 ]) === :block && length (x. args[2 ]. args) == 1 && CSTParser. isliteral (x. args[2 ]. args[1 ]))
478
+ (length (x. args) > 1 && headof (x. args[2 ]) === :block && length (x. args[2 ]. args) == 1 && CSTParser. isliteral (x. args[2 ]. args[1 ]))
479
479
return # Allow functions that return constants
480
480
end
481
481
if iscall (sig)
@@ -509,12 +509,12 @@ function check_farg_unused_(arg, arg_names)
509
509
valof (b. name) isa String && all_underscore (valof (b. name)) && return false
510
510
511
511
if b === nothing ||
512
- # no refs:
512
+ # no refs:
513
513
isempty (b. refs) ||
514
- # only self ref:
514
+ # only self ref:
515
515
(length (b. refs) == 1 && first (b. refs) == b. name) ||
516
- # first usage has binding:
517
- (length (b. refs) > 1 && b. refs[2 ] isa EXPR && hasbinding (b. refs[2 ]))
516
+ # first usage has binding:
517
+ (length (b. refs) > 1 && b. refs[2 ] isa EXPR && hasbinding (b. refs[2 ]))
518
518
seterror! (arg, UnusedFunctionArgument)
519
519
end
520
520
534
534
535
535
function is_nospecialize_call (x)
536
536
CSTParser. ismacrocall (x) &&
537
- CSTParser. ismacroname (x. args[1 ]) &&
538
- is_nospecialize (x. args[1 ])
537
+ CSTParser. ismacroname (x. args[1 ]) &&
538
+ is_nospecialize (x. args[1 ])
539
539
end
540
540
541
541
"""
@@ -555,8 +555,8 @@ function collect_hints(x::EXPR, env, missingrefs=:all, isquoted=false, errs=Tupl
555
555
push! (errs, (pos, x))
556
556
elseif ! isquoted
557
557
if missingrefs != :none && isidentifier (x) && ! hasref (x) &&
558
- ! (valof (x) == " var" && parentof (x) isa EXPR && isnonstdid (parentof (x))) &&
559
- ! ((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" ))
558
+ ! (valof (x) == " var" && parentof (x) isa EXPR && isnonstdid (parentof (x))) &&
559
+ ! ((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" ))
560
560
561
561
push! (errs, (pos, x))
562
562
elseif haserror (x) && errorof (x) isa StaticLint. LintCodes
585
585
586
586
function should_mark_missing_getfield_ref (x, env)
587
587
if isidentifier (x) && ! hasref (x) && # x has no ref
588
- 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
588
+ 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
589
589
lhsref = refof_maybe_getfield (parentof (parentof (x)). args[1 ])
590
590
hasref (x) && return false # We've resolved
591
591
if lhsref isa SymbolServer. ModuleStore || (lhsref isa Binding && lhsref. val isa SymbolServer. ModuleStore)
@@ -654,14 +654,14 @@ function is_type_of_call_to_getproperty(x::EXPR)
654
654
if iscall (x)
655
655
func_name = x. args[1 ]
656
656
return (isidentifier (func_name) && valof (func_name) == " getproperty" ) || # getproperty()
657
- (is_getfield_w_quotenode (func_name) && isidentifier (func_name. args[2 ]. args[1 ]) && valof (func_name. args[2 ]. args[1 ]) == " getproperty" ) # Base.getproperty()
657
+ (is_getfield_w_quotenode (func_name) && isidentifier (func_name. args[2 ]. args[1 ]) && valof (func_name. args[2 ]. args[1 ]) == " getproperty" ) # Base.getproperty()
658
658
end
659
659
return false
660
660
end
661
661
662
662
return parentof (x) isa EXPR && parentof (parentof (x)) isa EXPR &&
663
- ((isdeclaration (parentof (x)) && x === parentof (x). args[2 ] && is_call_to_getproperty (parentof (parentof (x)))) ||
664
- (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))))))
663
+ ((isdeclaration (parentof (x)) && x === parentof (x). args[2 ] && is_call_to_getproperty (parentof (parentof (x)))) ||
664
+ (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))))))
665
665
end
666
666
667
667
isunionfaketype (t:: SymbolServer.FakeTypeName ) = t. name. name === :Union && t. name. parent isa SymbolServer. VarRef && t. name. parent. name === :Core
0 commit comments