Skip to content

Commit

Permalink
Merge b0c1c8b into b242d59
Browse files Browse the repository at this point in the history
  • Loading branch information
mlin committed Nov 17, 2019
2 parents b242d59 + b0c1c8b commit 2760237
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
13 changes: 11 additions & 2 deletions WDL/Lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,15 +717,24 @@ class UnnecessaryQuantifier(Linter):
# A declaration like T? x = :T: where the right-hand side can't be null.
# The optional quantifier is unnecessary except within a task/workflow
# input section (where it denotes that the default value can be overridden
# by expressly passing null)
# by expressly passing null). Another exception is File? outputs of tasks,
# e.g. File? optional_file_output = "filename.txt"

def decl(self, obj: Tree.Decl) -> Any:
if obj.type.optional and obj.expr and not obj.expr.type.optional:
tw = obj
while not isinstance(tw, (Tree.Task, Tree.Workflow)):
tw = getattr(tw, "parent")
assert isinstance(tw, (Tree.Task, Tree.Workflow))
if isinstance(tw.inputs, list) and obj not in tw.inputs:
if (
isinstance(tw.inputs, list)
and obj not in tw.inputs
and not (
isinstance(tw, Tree.Task)
and isinstance(obj.type, Type.File)
and obj in tw.outputs
)
):
self.add(
obj,
"unnecessary optional quantifier (?) for non-input {} {}".format(
Expand Down
1 change: 1 addition & 0 deletions test_corpi/contrived/contrived.wdl
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ task popular {
Array[String] nums = [1]
String left_contents = contents.left
String right_contents = contents.right
File? optional_file = "nonexistent.txt"
}
}
8 changes: 4 additions & 4 deletions tests/test_3corpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,30 +268,30 @@ class Contrived2(unittest.TestCase):
# these use the pattern 'input { Type? x = default }' and need check_quant=False
"mergecounts","somaticseq"
],
expected_lint={'OptionalCoercion': 9, 'StringCoercion': 14, 'UnusedDeclaration': 18, 'UnnecessaryQuantifier': 41, 'NonemptyCoercion': 1, 'NameCollision': 1, 'SelectArray': 1},
expected_lint={'OptionalCoercion': 9, 'StringCoercion': 14, 'UnusedDeclaration': 18, 'NonemptyCoercion': 1, 'NameCollision': 1, 'SelectArray': 1},
)
class BioWDLTasks(unittest.TestCase):
pass

@wdl_corpus(
["test_corpi/biowdl/aligning/**"],
expected_lint={'OptionalCoercion': 12, 'StringCoercion': 14, 'UnusedDeclaration': 12, 'UnnecessaryQuantifier': 41, 'NonemptyCoercion': 1, 'NameCollision': 1},
expected_lint={'OptionalCoercion': 12, 'StringCoercion': 14, 'UnusedDeclaration': 12, 'NonemptyCoercion': 1, 'NameCollision': 1},
check_quant=False,
)
class BioWDLAligning(unittest.TestCase):
pass

@wdl_corpus(
["test_corpi/biowdl/expression-quantification/**"],
expected_lint={'OptionalCoercion': 11, 'StringCoercion': 14, 'UnusedDeclaration': 12, 'UnnecessaryQuantifier': 41, 'NonemptyCoercion': 3, 'NameCollision': 1},
expected_lint={'OptionalCoercion': 11, 'StringCoercion': 14, 'UnusedDeclaration': 12, 'NonemptyCoercion': 3, 'NameCollision': 1},
check_quant=False,
)
class BioWDLExpressionQuantification(unittest.TestCase):
pass

@wdl_corpus(
["test_corpi/biowdl/somatic-variantcalling"],
expected_lint={'UnusedImport': 2, 'OptionalCoercion': 11, 'StringCoercion': 16, 'UnusedDeclaration': 11, 'UnnecessaryQuantifier': 166, 'NonemptyCoercion': 37, 'SelectArray': 5},
expected_lint={'UnusedImport': 2, 'OptionalCoercion': 11, 'StringCoercion': 16, 'UnusedDeclaration': 11, 'NonemptyCoercion': 37, 'SelectArray': 5},
check_quant=False,
)
class BioWDLSomaticVariantCalling(unittest.TestCase):
Expand Down

0 comments on commit 2760237

Please sign in to comment.