@@ -26,24 +26,17 @@ def lint_inputs(tool_xml, lint_ctx):
2626 lint_ctx .warn ("Param input [%s] with no format specified - 'data' format will be assumed." , param_name )
2727 # TODO: Validate type, much more...
2828
29- def find_list (elem , expression ):
30- matching = elem .findall (expression )
31- if matching is None :
32- return []
33- else :
34- return matching
35-
3629 conditional_selects = tool_xml .findall ("./inputs//conditional" )
3730 for conditional in conditional_selects :
38- booleans = find_list (conditional , "./ param[@ type=' boolean'] " )
39- selects = find_list (conditional , "./ param[@ type=' select'] " )
31+ booleans = _find_with_attribute (conditional , "param" , " type" , " boolean" )
32+ selects = _find_with_attribute (conditional , "param" , " type" , " select" )
4033 # Should conditionals ever not have a select?
4134 if not len (selects ) and not len (booleans ):
4235 lint_ctx .warn ("Conditional without <param type=\" select\" /> or <param type=\" boolean\" />" )
4336 continue
4437
4538 for select in selects :
46- select_options = select .findall ('./ option[@ value] ' )
39+ select_options = select .findall (select , ' option' , ' value' )
4740 if any (['value' not in option .attrib for option in select_options ]):
4841 lint_ctx .error ("Option without value" )
4942
@@ -91,3 +84,17 @@ def lint_repeats(tool_xml, lint_ctx):
9184 lint_ctx .error ("Repeat does not specify name attribute." )
9285 if "title" not in repeat .attrib :
9386 lint_ctx .error ("Repeat does not specify title attribute." )
87+
88+
89+ def _find_with_attribute (element , tag , attribute , test_value = None ):
90+ rval = []
91+ for el in (element .findall ('./%s' % tag ) or []):
92+ if attribute not in el .attribute :
93+ continue
94+ value = el .attribute [attribute ]
95+ if test_value is not None :
96+ if value == test_value :
97+ rval .append (el )
98+ else :
99+ rval .append (el )
100+ return rval
0 commit comments