From dda9bcf5e7110ebafc96b5d39340a4105e8312c1 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 3 Apr 2020 15:32:30 +0200 Subject: [PATCH] Smarter regexes for sed -i subsitutions detections --- package_linter.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/package_linter.py b/package_linter.py index c7d93c1..4e5fc5f 100755 --- a/package_linter.py +++ b/package_linter.py @@ -712,7 +712,7 @@ class Script(): For instance, "app setting" is contained in "yunohost app setting $app ..." """ - return any(re.match(regex, line) + return any(re.search(regex, line) for line in [' '.join(line) for line in self.lines]) def analyze(self): @@ -799,8 +799,9 @@ class Script(): if self.contains("rm -rf"): print_error("[YEP-2.12] You should avoid using 'rm -rf', please use 'ynh_secure_remove' instead") - if self.contains("sed -i"): - print_warning("[YEP-2.12] You should avoid using 'sed -i', please use 'ynh_replace_string' instead") + + if self.containsregex(r"sed\s+(-i|--in-place)\s+(-r\s+)?s") or self.containsregex(r"sed\s+s\S*\s+(-i|--in-place)"): + print_warning("[YEP-2.12] You should avoid using 'sed -i' for substitutions, please use 'ynh_replace_string' instead") if self.containsregex(r"sudo \w"): # \w is here to not match sudo -u, legit use because ynh_exec_as not official yet... print_warning( "[YEP-2.12] You should not need to use 'sudo', the script is being run as root. "