Assignments are okay in SC2094 (fixes #1192)

This commit is contained in:
Ng Zhi An 2018-05-13 15:17:32 -07:00
parent 235bf6605f
commit b3362f1dc3
1 changed files with 6 additions and 1 deletions

View File

@ -573,6 +573,7 @@ prop_checkRedirectToSame4 = verifyNot checkRedirectToSame "foo /dev/null > /dev/
prop_checkRedirectToSame5 = verifyNot checkRedirectToSame "foo > bar 2> bar" prop_checkRedirectToSame5 = verifyNot checkRedirectToSame "foo > bar 2> bar"
prop_checkRedirectToSame6 = verifyNot checkRedirectToSame "echo foo > foo" prop_checkRedirectToSame6 = verifyNot checkRedirectToSame "echo foo > foo"
prop_checkRedirectToSame7 = verifyNot checkRedirectToSame "sed 's/foo/bar/g' file | sponge file" prop_checkRedirectToSame7 = verifyNot checkRedirectToSame "sed 's/foo/bar/g' file | sponge file"
prop_checkRedirectToSame8 = verifyNot checkRedirectToSame "while read -r line; do _=\"$fname\"; done <\"$fname\""
checkRedirectToSame params s@(T_Pipeline _ _ list) = checkRedirectToSame params s@(T_Pipeline _ _ list) =
mapM_ (\l -> (mapM_ (\x -> doAnalysis (checkOccurrences x) l) (getAllRedirs list))) list mapM_ (\l -> (mapM_ (\x -> doAnalysis (checkOccurrences x) l) (getAllRedirs list))) list
where where
@ -583,7 +584,8 @@ checkRedirectToSame params s@(T_Pipeline _ _ list) =
&& x == y && x == y
&& not (isOutput t && isOutput u) && not (isOutput t && isOutput u)
&& not (special t) && not (special t)
&& not (any isHarmlessCommand [t,u])) $ do && not (any isHarmlessCommand [t,u])
&& not (any containsAssignment [u])) $ do
addComment $ note newId addComment $ note newId
addComment $ note exceptId addComment $ note exceptId
checkOccurrences _ _ = return () checkOccurrences _ _ = return ()
@ -610,6 +612,9 @@ checkRedirectToSame params s@(T_Pipeline _ _ list) =
cmd <- getClosestCommand (parentMap params) arg cmd <- getClosestCommand (parentMap params) arg
name <- getCommandBasename cmd name <- getCommandBasename cmd
return $ name `elem` ["echo", "printf", "sponge"] return $ name `elem` ["echo", "printf", "sponge"]
containsAssignment arg = fromMaybe False $ do
cmd <- getClosestCommand (parentMap params) arg
return $ isAssignment cmd
checkRedirectToSame _ _ = return () checkRedirectToSame _ _ = return ()