@@ -89,8 +89,8 @@ class BadCommandsCheck(Check):
8989 )
9090
9191 def feed (self , pkg ):
92- for func_node , _ in bash .func_query .captures (pkg .tree .root_node ):
93- for node , _ in bash .cmd_query .captures (func_node ):
92+ for func_node in bash .func_query .captures (pkg .tree .root_node ). get ( "func" , () ):
93+ for node in bash .cmd_query .captures (func_node ). get ( "call" , () ):
9494 call = pkg .node_str (node )
9595 name = pkg .node_str (node .child_by_field_name ("name" ))
9696 lineno , _colno = node .start_point
@@ -134,8 +134,8 @@ class EendMissingArgCheck(Check):
134134 known_results = frozenset ([EendMissingArg ])
135135
136136 def feed (self , pkg ):
137- for func_node , _ in bash .func_query .captures (pkg .tree .root_node ):
138- for node , _ in bash .cmd_query .captures (func_node ):
137+ for func_node in bash .func_query .captures (pkg .tree .root_node ). get ( "func" , () ):
138+ for node in bash .cmd_query .captures (func_node ). get ( "call" , () ):
139139 line = pkg .node_str (node )
140140 if line == "eend" :
141141 lineno , _ = node .start_point
@@ -639,15 +639,15 @@ class MetadataVarCheck(Check):
639639 @verify_vars ("HOMEPAGE" , "KEYWORDS" )
640640 def _raw_text (self , var , node , value , pkg ):
641641 matches = []
642- for var_node , _ in bash .var_query .captures (node ):
642+ for var_node in bash .var_query .captures (node ). get ( "var" , () ):
643643 matches .append (pkg .node_str (var_node .parent ))
644644 if matches :
645645 yield ReferenceInMetadataVar (var , stable_unique (matches ), pkg = pkg )
646646
647647 @verify_vars ("LICENSE" )
648648 def _raw_text_license (self , var , node , value , pkg ):
649649 matches = []
650- for var_node , _ in bash .var_query .captures (node ):
650+ for var_node in bash .var_query .captures (node ). get ( "var" , () ):
651651 var_str = pkg .node_str (var_node .parent ).strip ()
652652 if var_str in ["$LICENSE" , "${LICENSE}" ]:
653653 continue # LICENSE in LICENSE is ok
@@ -718,7 +718,7 @@ def feed(self, pkg):
718718 line = pkg .node_str (node ), lineno = lineno + 1 , pkg = pkg
719719 )
720720 elif pkg .node_str (value_node .prev_sibling ) == "=" :
721- for var_node , _ in bash .var_query .captures (value_node ):
721+ for var_node in bash .var_query .captures (value_node ). get ( "var" , () ):
722722 if (
723723 pkg .node_str (var_node ) == name
724724 and self .canonicalize_assign (pkg .node_str (var_node .parent )) == value_str
@@ -878,12 +878,12 @@ def feed(self, pkg):
878878 # collect globally defined functions in ebuild
879879 defined_funcs = {
880880 pkg .node_str (func_node .child_by_field_name ("name" ))
881- for func_node , _ in bash .func_query .captures (pkg .tree .root_node )
881+ for func_node in bash .func_query .captures (pkg .tree .root_node ). get ( "func" , () )
882882 }
883883
884884 # register variables assigned in ebuilds
885885 assigned_vars = dict ()
886- for node , _ in bash .var_assign_query .captures (pkg .tree .root_node ):
886+ for node in bash .var_assign_query .captures (pkg .tree .root_node ). get ( "assign" , () ):
887887 name = pkg .node_str (node .child_by_field_name ("name" ))
888888 if eclass := self .get_eclass (name , pkg ):
889889 assigned_vars [name ] = eclass
@@ -892,7 +892,7 @@ def feed(self, pkg):
892892 weak_used_eclasses = set ()
893893 # match captured commands with eclasses
894894 used = defaultdict (list )
895- for node , _ in bash .cmd_query .captures (pkg .tree .root_node ):
895+ for node in bash .cmd_query .captures (pkg .tree .root_node ). get ( "call" , () ):
896896 call = pkg .node_str (node )
897897 name = pkg .node_str (node .child_by_field_name ("name" ))
898898 if name == "inherit" :
@@ -914,7 +914,7 @@ def feed(self, pkg):
914914 weak_used_eclasses .add (eclass )
915915
916916 # match captured variables with eclasses
917- for node , _ in bash .var_query .captures (pkg .tree .root_node ):
917+ for node in bash .var_query .captures (pkg .tree .root_node ). get ( "var" , () ):
918918 name = pkg .node_str (node )
919919 if node .parent .type == "unset_command" :
920920 continue
@@ -1114,12 +1114,12 @@ class VariableScopeCheck(Check):
11141114 scoped_vars .setdefault (eapi , {}).setdefault (phase , set ()).add (variable )
11151115 scoped_vars = ImmutableDict (scoped_vars )
11161116
1117- def feed (self , pkg ):
1118- for func_node , _ in bash .func_query .captures (pkg .tree .root_node ):
1117+ def feed (self , pkg : bash . ParseTree ):
1118+ for func_node in bash .func_query .captures (pkg .tree .root_node ). get ( "func" , () ):
11191119 func_name = pkg .node_str (func_node .child_by_field_name ("name" ))
11201120 if variables := self .scoped_vars [pkg .eapi ].get (func_name ):
11211121 usage = defaultdict (set )
1122- for var_node , _ in bash .var_query .captures (func_node ):
1122+ for var_node in bash .var_query .captures (func_node ). get ( "var" , () ):
11231123 var_name = pkg .node_str (var_node )
11241124 if var_name in variables :
11251125 lineno , _colno = var_node .start_point
@@ -1130,7 +1130,7 @@ def feed(self, pkg):
11301130 global_usage = defaultdict (set )
11311131 for global_node in pkg .tree .root_node .children :
11321132 if global_node .type not in ("function_definition" , "ERROR" ):
1133- for var_node , _ in bash .var_query .captures (global_node ):
1133+ for var_node in bash .var_query .captures (global_node ). get ( "var" , () ):
11341134 var_name = pkg .node_str (var_node )
11351135 if var_name in self .not_global_scope :
11361136 lineno , _colno = var_node .start_point
@@ -1271,14 +1271,14 @@ def _var_needs_quotes(self, pkg, node):
12711271 # Default: The variable should be quoted
12721272 return True
12731273
1274- def _feed (self , item ):
1274+ def _feed (self , item : bash . ParseTree ):
12751275 if item .tree .root_node .has_error :
12761276 # Do not run this check if the parse tree contains errors, as it
12771277 # might result in false positives. This check appears to be quite
12781278 # expensive though...
12791279 return
12801280 hits = defaultdict (set )
1281- for var_node , _ in bash .var_query .captures (item .tree .root_node ):
1281+ for var_node in bash .var_query .captures (item .tree .root_node ). get ( "var" , () ):
12821282 var_name = item .node_str (var_node )
12831283 if var_name in self .var_names :
12841284 if self ._var_needs_quotes (item , var_node ):
@@ -1390,7 +1390,7 @@ class DoCompressedFilesCheck(Check):
13901390 )
13911391
13921392 def feed (self , pkg ):
1393- for node , _ in bash .cmd_query .captures (pkg .tree .root_node ):
1393+ for node in bash .cmd_query .captures (pkg .tree .root_node ). get ( "call" , () ):
13941394 call_name = pkg .node_str (node .child_by_field_name ("name" ))
13951395 if call_name not in self .functions :
13961396 continue
@@ -1446,7 +1446,7 @@ def check_head_tail(self, pkg, call_node, call_name):
14461446 prev_arg = arg
14471447
14481448 def feed (self , pkg ):
1449- for call_node , _ in bash .cmd_query .captures (pkg .tree .root_node ):
1449+ for call_node in bash .cmd_query .captures (pkg .tree .root_node ). get ( "call" , () ):
14501450 call_name = pkg .node_str (call_node .child_by_field_name ("name" ))
14511451 if call_name in ("head" , "tail" ):
14521452 yield from self .check_head_tail (pkg , call_node , call_name )
@@ -1476,14 +1476,13 @@ def __init__(self, options, **kwargs):
14761476 self .glob_query = bash .query ('(concatenation (word) @word (.match? @word "[*?]")) @usage' )
14771477
14781478 def feed (self , pkg ):
1479- for node , capture in self .glob_query .captures (pkg .tree .root_node ):
1480- if capture == "usage" :
1481- for var_node , _ in bash .var_query .captures (node ):
1482- var_name = pkg .node_str (var_node )
1483- if var_name == "DISTDIR" :
1484- lineno , _colno = node .start_point
1485- yield GlobDistdir (line = pkg .node_str (node ), lineno = lineno + 1 , pkg = pkg )
1486- break
1479+ for node in self .glob_query .captures (pkg .tree .root_node ).get ("usage" , ()):
1480+ for var_node in bash .var_query .captures (node ).get ("var" , ()):
1481+ var_name = pkg .node_str (var_node )
1482+ if var_name == "DISTDIR" :
1483+ lineno , _colno = node .start_point
1484+ yield GlobDistdir (line = pkg .node_str (node ), lineno = lineno + 1 , pkg = pkg )
1485+ break
14871486
14881487
14891488class VariableShadowed (results .LinesResult , results .Warning ):
@@ -1528,7 +1527,7 @@ def feed(self, pkg: bash.ParseTree):
15281527 if value_node := node .child_by_field_name ("value" ):
15291528 if any (
15301529 pkg .node_str (node ) == used_name
1531- for node , _ in bash .var_query .captures (value_node )
1530+ for node in bash .var_query .captures (value_node ). get ( "var" , () )
15321531 ):
15331532 continue
15341533 var_assigns [used_name ].append (node )
@@ -1570,7 +1569,7 @@ class SandboxCallCheck(Check):
15701569 functions = frozenset ({"addread" , "addwrite" , "adddeny" , "addpredict" })
15711570
15721571 def feed (self , pkg : bash .ParseTree ):
1573- for node , _ in bash .cmd_query .captures (pkg .tree .root_node ):
1572+ for node in bash .cmd_query .captures (pkg .tree .root_node ). get ( "call" , () ):
15741573 name = pkg .node_str (node .child_by_field_name ("name" ))
15751574 if name in self .functions :
15761575 args = node .children_by_field_name ("argument" )
0 commit comments