@@ -3596,6 +3596,8 @@ prop_checkPipeToNowhere17 = verify checkPipeToNowhere "echo World | cat << 'EOF'
35963596prop_checkPipeToNowhere18 = verifyNot checkPipeToNowhere " ls 1>&3 3>&1 3>&- | wc -l"
35973597prop_checkPipeToNowhere19 = verifyNot checkPipeToNowhere " find . -print0 | du --files0-from=/dev/stdin"
35983598prop_checkPipeToNowhere20 = verifyNot checkPipeToNowhere " find . | du --exclude-from=/dev/fd/0"
3599+ prop_checkPipeToNowhere21 = verifyNot checkPipeToNowhere " yes | cp -ri foo/* bar"
3600+ prop_checkPipeToNowhere22 = verifyNot checkPipeToNowhere " yes | rm --interactive *"
35993601
36003602data PipeType = StdoutPipe | StdoutStderrPipe | NoPipe deriving (Eq )
36013603checkPipeToNowhere :: Parameters -> Token -> WriterT [TokenComment ] Identity ()
@@ -3661,6 +3663,7 @@ checkPipeToNowhere params t =
36613663 commandSpecificException name cmd =
36623664 case name of
36633665 " du" -> any ((`elem` [" exclude-from" , " files0-from" ]) . snd ) $ getAllFlags cmd
3666+ _ | name `elem` interactiveFlagCmds -> hasInteractiveFlag cmd
36643667 _ -> False
36653668
36663669 warnAboutDupes (n, list@ (_: _: _)) =
@@ -3684,7 +3687,7 @@ checkPipeToNowhere params t =
36843687 name <- getCommandBasename cmd
36853688 guard $ name `elem` nonReadingCommands
36863689 guard . not $ hasAdditionalConsumers cmd
3687- guard . not $ name `elem` [ " cp " , " mv " , " rm " ] && cmd `hasFlag` " i "
3690+ guard . not $ name `elem` interactiveFlagCmds && hasInteractiveFlag cmd
36883691 let suggestion =
36893692 if name == " echo"
36903693 then " Did you want 'cat' instead?"
@@ -3699,6 +3702,9 @@ checkPipeToNowhere params t =
36993702 treeContains pred t = isNothing $
37003703 doAnalysis (guard . not . pred ) t
37013704
3705+ interactiveFlagCmds = [ " cp" , " mv" , " rm" ]
3706+ hasInteractiveFlag cmd = cmd `hasFlag` " i" || cmd `hasFlag` " interactive"
3707+
37023708 mayConsume t =
37033709 case t of
37043710 T_ProcSub _ " <" _ -> True
0 commit comments