From 3e50a2fce8323f89b63243d2b9042d756d327920 Mon Sep 17 00:00:00 2001
From: Vidar Holen <spam@vidarholen.net>
Date: Fri, 7 Aug 2020 14:59:34 -0700
Subject: [PATCH] Suppress SC2216 for du --files0-from or --exclude-from (fixes
 #1286)

---
 src/ShellCheck/Analytics.hs | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/ShellCheck/Analytics.hs b/src/ShellCheck/Analytics.hs
index f8904be..7906e7a 100644
--- a/src/ShellCheck/Analytics.hs
+++ b/src/ShellCheck/Analytics.hs
@@ -3305,6 +3305,8 @@ prop_checkPipeToNowhere15 = verifyNot checkPipeToNowhere "ls > foo 2> bar |& gre
 prop_checkPipeToNowhere16 = verifyNot checkPipeToNowhere "echo World | cat << EOF\nhello $(cat)\nEOF\n"
 prop_checkPipeToNowhere17 = verify checkPipeToNowhere "echo World | cat << 'EOF'\nhello $(cat)\nEOF\n"
 prop_checkPipeToNowhere18 = verifyNot checkPipeToNowhere "ls 1>&3 3>&1 3>&- | wc -l"
+prop_checkPipeToNowhere19 = verifyNot checkPipeToNowhere "find . -print0 | du --files0-from=/dev/stdin"
+prop_checkPipeToNowhere20 = verifyNot checkPipeToNowhere "find . | du --exclude-from=/dev/fd/0"
 
 data PipeType = StdoutPipe | StdoutStderrPipe | NoPipe deriving (Eq)
 checkPipeToNowhere :: Parameters -> Token -> WriterT [TokenComment] Identity ()
@@ -3324,6 +3326,7 @@ checkPipeToNowhere params t =
             name <- getCommandBasename cmd
             guard $ name `elem` nonReadingCommands
             guard $ not hasConsumers && input /= NoPipe
+            guard . not $ commandSpecificException name cmd
 
             -- Confusing echo for cat is so common that it's worth a special case
             let suggestion =
@@ -3366,6 +3369,11 @@ checkPipeToNowhere params t =
                 outputWarning
                 mapM_ warnAboutDupes $ Map.assocs fdMap
 
+    commandSpecificException name cmd =
+        case name of
+            "du" -> any (`elem` ["exclude-from", "files0-from"]) $ lt $ map snd $ getAllFlags cmd
+            _ -> False
+
     warnAboutDupes (n, list@(_:_:_)) =
         forM_ list $ \c -> err (getOpId c) 2261 $
             "Multiple redirections compete for " ++ str n ++ ". Use cat, tee, or pass filenames instead."