diff --git a/WDL/Lint.py b/WDL/Lint.py index f06ba312..c73803e3 100644 --- a/WDL/Lint.py +++ b/WDL/Lint.py @@ -747,6 +747,27 @@ def document(self, obj: Tree.Document) -> Any: ) +@a_linter +class ImportNewerWDL(Linter): + # Document imports a document with a newer WDL version + def document(self, obj: Tree.Document) -> Any: + doc_version = self._version_order(obj.effective_wdl_version) + for imp in obj.imports: + if self._version_order(imp.doc.effective_wdl_version) > doc_version: + self.add( + obj, + "imported document has newer WDL version", + pos=imp.pos, + ) + + def _version_order(self, wdl_version: str) -> int: + if wdl_version == "draft-2": + return 2 + elif wdl_version == "development": + return 99 + return int(wdl_version.replace(".", "")) + + @a_linter class ForwardReference(Linter): # Ident referencing a value or call output lexically precedes Decl/Call diff --git a/tests/test_3corpi.py b/tests/test_3corpi.py index c085df18..4e6305f2 100644 --- a/tests/test_3corpi.py +++ b/tests/test_3corpi.py @@ -410,6 +410,7 @@ class dxWDL(unittest.TestCase): "UnverifiedStruct": 3, "Deprecated": 2, "UnexpectedRuntimeValue": 1, + "ImportNewerWDL": 1, }, blocklist=["check_quant", "incomplete_call", "issue596"], ) @@ -437,6 +438,7 @@ class Contrived(unittest.TestCase): "UnverifiedStruct": 3, "Deprecated": 3, "UnexpectedRuntimeValue": 1, + "ImportNewerWDL": 2, }, check_quant=False, blocklist=["incomplete_call"],