diff --git a/lib/galaxy/tool_util/lint.py b/lib/galaxy/tool_util/lint.py index f85e92d2e20a..cf2d8d47cb06 100644 --- a/lib/galaxy/tool_util/lint.py +++ b/lib/galaxy/tool_util/lint.py @@ -101,6 +101,13 @@ def name(cls) -> str: """ return cls.__name__ + @classmethod + def list_listers(cls) -> List[str]: + """ + list the names of all linter derived from Linter + """ + return [s.__name__ for s in cls.__subclasses__()] + class LintMessage: """ @@ -375,17 +382,3 @@ def lint_xml_with(lint_context, tool_xml, extra_modules=None) -> LintContext: extra_modules = extra_modules or [] tool_source = get_tool_source(xml_tree=tool_xml) return lint_tool_source_with(lint_context, tool_source, extra_modules=extra_modules) - - -def list_linters(extra_modules: Optional[List[str]] = None) -> List[str]: - extra_modules = extra_modules or [] - linter_modules = submodules.import_submodules(galaxy.tool_util.linters) - linter_modules.extend(extra_modules) - linters = list() - for module in linter_modules: - for name, value in inspect.getmembers(module): - if callable(value) and name.startswith("lint_"): - linters.append(name[5:]) - elif inspect.isclass(value) and issubclass(value, Linter) and not inspect.isabstract(value): - linters.append(name) - return linters diff --git a/test/unit/tool_util/test_tool_linters.py b/test/unit/tool_util/test_tool_linters.py index a6d1ca395db0..0600ae32c4f2 100644 --- a/test/unit/tool_util/test_tool_linters.py +++ b/test/unit/tool_util/test_tool_linters.py @@ -8,7 +8,7 @@ lint_tool_source_with_modules, lint_xml_with, LintContext, - list_linters, + Linter, XMLLintMessageLine, XMLLintMessageXPath, ) @@ -2074,8 +2074,10 @@ def test_xml_comments_are_ignored(lint_ctx: LintContext): def test_list_linters(): - linters = list_linters() - assert len(linters) >= 129 + linter_names = Linter.list_listers() + # make sure to add/remove a test for new/removed linters if this number changes + assert len(linter_names) == 129 + assert "Linter" not in linter_names # make sure that linters from all modules are available for prefix in [ "Citations", @@ -2090,4 +2092,4 @@ def test_list_linters(): "XMLOrder", "XSD", ]: - assert len([x for x in linters if x.startswith(prefix)]) + assert len([x for x in linter_names if x.startswith(prefix)])