diff --git a/src/codemodder/registry.py b/src/codemodder/registry.py index 9691eefb..2f5fc669 100644 --- a/src/codemodder/registry.py +++ b/src/codemodder/registry.py @@ -83,15 +83,18 @@ def match_codemods( base_codemods[codemod.id] = codemod # Remove duplicates and preserve order - return list(dict.fromkeys(base_codemods.values())) + return list(base_codemods.values()) matched_codemods = [] for name in codemod_include: if "*" in name: pat = re.compile(name.replace("*", ".*")) - matched_codemods.extend( - [codemod for codemod in self.codemods if pat.match(codemod.id)] - ) + pattern_matches = [code for code in self.codemods if pat.match(code.id)] + matched_codemods.extend(pattern_matches) + if not pattern_matches: + logger.warning( + "Given codemod pattern '%s' does not match any codemods.", name + ) continue try: diff --git a/tests/codemods/test_include_exclude.py b/tests/codemods/test_include_exclude.py index eb436a7a..5f4699ae 100644 --- a/tests/codemods/test_include_exclude.py +++ b/tests/codemods/test_include_exclude.py @@ -105,6 +105,13 @@ def test_include_sast_with_prefix(self): c for c in self.registry.codemods if c.origin == "sonar" ] + def test_warn_pattern_no_match(self, caplog): + assert self.registry.match_codemods(["*doesntexist*"], None) == [] + assert ( + "Given codemod pattern '*doesntexist*' does not match any codemods" + in caplog.text + ) + def test_exclude_with_pattern(self): assert self.registry.match_codemods(None, ["*django*"], sast_only=False) == [ c