Merge pull request #1872 from josephcsible/checkforinquoted

Simplify checkForInQuoted
This commit is contained in:
Vidar Holen 2020-03-31 19:10:25 -07:00 committed by GitHub
commit db11e2f663
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 8 deletions

View File

@ -583,18 +583,17 @@ prop_checkForInQuoted8 = verify checkForInQuoted "for f in 'ls', 'grep', 'mv'; d
prop_checkForInQuoted9 = verifyNot checkForInQuoted "for f in 'ls,' 'grep,' 'mv'; do true; done" prop_checkForInQuoted9 = verifyNot checkForInQuoted "for f in 'ls,' 'grep,' 'mv'; do true; done"
checkForInQuoted _ (T_ForIn _ f [T_NormalWord _ [word@(T_DoubleQuoted id list)]] _) checkForInQuoted _ (T_ForIn _ f [T_NormalWord _ [word@(T_DoubleQuoted id list)]] _)
| any (\x -> willSplit x && not (mayBecomeMultipleArgs x)) list | any (\x -> willSplit x && not (mayBecomeMultipleArgs x)) list
|| (fmap wouldHaveBeenGlob (getLiteralString word) == Just True) = || maybe False wouldHaveBeenGlob (getLiteralString word) =
err id 2066 "Since you double quoted this, it will not word split, and the loop will only run once." err id 2066 "Since you double quoted this, it will not word split, and the loop will only run once."
checkForInQuoted _ (T_ForIn _ f [T_NormalWord _ [T_SingleQuoted id _]] _) = checkForInQuoted _ (T_ForIn _ f [T_NormalWord _ [T_SingleQuoted id _]] _) =
warn id 2041 "This is a literal string. To run as a command, use $(..) instead of '..' . " warn id 2041 "This is a literal string. To run as a command, use $(..) instead of '..' . "
checkForInQuoted _ (T_ForIn _ _ [single] _) | fromMaybe False $ fmap (',' `elem`) $ getUnquotedLiteral single = checkForInQuoted _ (T_ForIn _ _ [single] _)
| maybe False (',' `elem`) $ getUnquotedLiteral single =
warn (getId single) 2042 "Use spaces, not commas, to separate loop elements." warn (getId single) 2042 "Use spaces, not commas, to separate loop elements."
checkForInQuoted _ (T_ForIn _ _ [single] _) | not (willSplit single) && not (mayBecomeMultipleArgs single) = | not (willSplit single || mayBecomeMultipleArgs single) =
warn (getId single) 2043 "This loop will only ever run once. Bad quoting or missing glob/expansion?" warn (getId single) 2043 "This loop will only ever run once. Bad quoting or missing glob/expansion?"
checkForInQuoted params (T_ForIn _ _ multiple _) = checkForInQuoted params (T_ForIn _ _ multiple _) =
mapM_ f multiple forM_ multiple $ \arg -> sequence_ $ do
where
f arg = sequence_ $ do
suffix <- getTrailingUnquotedLiteral arg suffix <- getTrailingUnquotedLiteral arg
string <- getLiteralString suffix string <- getLiteralString suffix
guard $ "," `isSuffixOf` string guard $ "," `isSuffixOf` string