From 5084ba8d7ed017551de498365861f8a585eca360 Mon Sep 17 00:00:00 2001 From: "Joseph C. Sible" Date: Sun, 5 Apr 2020 21:23:34 -0400 Subject: [PATCH 1/2] Make skipRepeating lazier and faster --- src/ShellCheck/Checks/Commands.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ShellCheck/Checks/Commands.hs b/src/ShellCheck/Checks/Commands.hs index e321102..14a8c09 100644 --- a/src/ShellCheck/Checks/Commands.hs +++ b/src/ShellCheck/Checks/Commands.hs @@ -966,9 +966,9 @@ checkCatastrophicRm = CommandCheck (Basename "rm") $ \t -> f _ = return "" stripTrailing c = reverse . dropWhile (== c) . reverse - skipRepeating c (a:b:rest) | a == b && b == c = skipRepeating c (b:rest) - skipRepeating c (a:r) = a:skipRepeating c r - skipRepeating _ [] = [] + skipRepeating c = foldr go [] + where + go a r = a : if a == c then case r of b:rest | b == c -> rest; _ -> r else r paths = [ "", "/bin", "/etc", "/home", "/mnt", "/usr", "/usr/share", "/usr/local", From cd38afce26d9914085ea632d3eebded5fd667778 Mon Sep 17 00:00:00 2001 From: "Joseph C. Sible" Date: Sun, 5 Apr 2020 21:45:51 -0400 Subject: [PATCH 2/2] Make it slightly lazier still (and more clear) --- src/ShellCheck/Checks/Commands.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ShellCheck/Checks/Commands.hs b/src/ShellCheck/Checks/Commands.hs index 14a8c09..ae02cd8 100644 --- a/src/ShellCheck/Checks/Commands.hs +++ b/src/ShellCheck/Checks/Commands.hs @@ -968,7 +968,7 @@ checkCatastrophicRm = CommandCheck (Basename "rm") $ \t -> stripTrailing c = reverse . dropWhile (== c) . reverse skipRepeating c = foldr go [] where - go a r = a : if a == c then case r of b:rest | b == c -> rest; _ -> r else r + go a r = a : case r of b:rest | b == c && a == b -> rest; _ -> r paths = [ "", "/bin", "/etc", "/home", "/mnt", "/usr", "/usr/share", "/usr/local",