-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New linter - lint order of XML appearing in the XML file.
The best practice guidelines prescribe a fixed order - this verifies that order. It will also print a little info box if unknown top-level tags are encountered - this may become a warning in the future (certainly if the XSD validation works out). Fix tool_builder.py to actually produce best practice tools.
- Loading branch information
Showing
3 changed files
with
36 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
TAG_ORDER = [ | ||
'description', | ||
'macros', | ||
'requirements', | ||
'code', | ||
'stdio', | ||
'version_command', | ||
'command', | ||
'inputs', | ||
'outputs', | ||
'tests', | ||
'help', | ||
'citations', | ||
] | ||
|
||
|
||
# Ensure the XML blocks appear in the correct order prescribed | ||
# by the tool author best practices. | ||
def lint_xml_ordering(tool_xml, lint_ctx): | ||
last_tag = None | ||
last_key = None | ||
for elem in list(tool_xml.getroot()): | ||
tag = elem.tag | ||
if tag in TAG_ORDER: | ||
key = TAG_ORDER.index(tag) | ||
if last_key: | ||
if last_key > key: | ||
lint_ctx.warn("Best practice violation [%s] elements should come before [%s]" % (tag, last_tag)) | ||
last_tag = tag | ||
last_key = key | ||
else: | ||
lint_ctx.info("Unknown tag [%s] encoutered, this may result in a warning in the future." % tag) |