Combine bracedString into getSingleUnmodifiedVariable
Everywhere we used getSingleUnmodifiedVariable, we just called bracedString on the result. Move this into that function instead, and rename it accordingly.
This commit is contained in:
parent
8a7497c4f0
commit
a9d564a8bc
|
@ -687,8 +687,7 @@ prop_checkExportedExpansions4 = verifyNot checkExportedExpansions "export ${foo?
|
||||||
checkExportedExpansions = CommandCheck (Exactly "export") (mapM_ check . arguments)
|
checkExportedExpansions = CommandCheck (Exactly "export") (mapM_ check . arguments)
|
||||||
where
|
where
|
||||||
check t = sequence_ $ do
|
check t = sequence_ $ do
|
||||||
var <- getSingleUnmodifiedVariable t
|
name <- getSingleUnmodifiedBracedString t
|
||||||
let name = bracedString var
|
|
||||||
return . warn (getId t) 2163 $
|
return . warn (getId t) 2163 $
|
||||||
"This does not export '" ++ name ++ "'. Remove $/${} for that, or use ${var?} to quiet."
|
"This does not export '" ++ name ++ "'. Remove $/${} for that, or use ${var?} to quiet."
|
||||||
|
|
||||||
|
@ -709,21 +708,20 @@ checkReadExpansions = CommandCheck (Exactly "read") check
|
||||||
|
|
||||||
check cmd = mapM_ warning $ getVars cmd
|
check cmd = mapM_ warning $ getVars cmd
|
||||||
warning t = sequence_ $ do
|
warning t = sequence_ $ do
|
||||||
var <- getSingleUnmodifiedVariable t
|
name <- getSingleUnmodifiedBracedString t
|
||||||
let name = bracedString var
|
|
||||||
guard $ isVariableName name -- e.g. not $1
|
guard $ isVariableName name -- e.g. not $1
|
||||||
return . warn (getId t) 2229 $
|
return . warn (getId t) 2229 $
|
||||||
"This does not read '" ++ name ++ "'. Remove $/${} for that, or use ${var?} to quiet."
|
"This does not read '" ++ name ++ "'. Remove $/${} for that, or use ${var?} to quiet."
|
||||||
|
|
||||||
-- Return the single variable expansion that makes up this word, if any.
|
-- Return the single variable expansion that makes up this word, if any.
|
||||||
-- e.g. $foo -> $foo, "$foo"'' -> $foo , "hello $name" -> Nothing
|
-- e.g. $foo -> $foo, "$foo"'' -> $foo , "hello $name" -> Nothing
|
||||||
getSingleUnmodifiedVariable :: Token -> Maybe Token
|
getSingleUnmodifiedBracedString :: Token -> Maybe String
|
||||||
getSingleUnmodifiedVariable word =
|
getSingleUnmodifiedBracedString word =
|
||||||
case getWordParts word of
|
case getWordParts word of
|
||||||
[t@(T_DollarBraced {})] ->
|
[t@(T_DollarBraced {})] ->
|
||||||
let contents = bracedString t
|
let contents = bracedString t
|
||||||
name = getBracedReference contents
|
name = getBracedReference contents
|
||||||
in guard (contents == name) >> return t
|
in guard (contents == name) >> return (bracedString t)
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
|
|
||||||
prop_checkAliasesUsesArgs1 = verify checkAliasesUsesArgs "alias a='cp $1 /a'"
|
prop_checkAliasesUsesArgs1 = verify checkAliasesUsesArgs "alias a='cp $1 /a'"
|
||||||
|
|
Loading…
Reference in New Issue