mirror of
https://github.com/koalaman/shellcheck
synced 2025-07-15 01:23:07 -07:00
Merge pull request #1901 from josephcsible/bracedstring
Mostly get rid of bracedString
This commit is contained in:
commit
73cc11fd0a
5 changed files with 40 additions and 45 deletions
|
@ -680,8 +680,7 @@ prop_checkExportedExpansions4 = verifyNot checkExportedExpansions "export ${foo?
|
|||
checkExportedExpansions = CommandCheck (Exactly "export") (mapM_ check . arguments)
|
||||
where
|
||||
check t = sequence_ $ do
|
||||
var <- getSingleUnmodifiedVariable t
|
||||
let name = bracedString var
|
||||
name <- getSingleUnmodifiedBracedString t
|
||||
return . warn (getId t) 2163 $
|
||||
"This does not export '" ++ name ++ "'. Remove $/${} for that, or use ${var?} to quiet."
|
||||
|
||||
|
@ -702,21 +701,20 @@ checkReadExpansions = CommandCheck (Exactly "read") check
|
|||
|
||||
check cmd = mapM_ warning $ getVars cmd
|
||||
warning t = sequence_ $ do
|
||||
var <- getSingleUnmodifiedVariable t
|
||||
let name = bracedString var
|
||||
name <- getSingleUnmodifiedBracedString t
|
||||
guard $ isVariableName name -- e.g. not $1
|
||||
return . warn (getId t) 2229 $
|
||||
"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.
|
||||
-- e.g. $foo -> $foo, "$foo"'' -> $foo , "hello $name" -> Nothing
|
||||
getSingleUnmodifiedVariable :: Token -> Maybe Token
|
||||
getSingleUnmodifiedVariable word =
|
||||
getSingleUnmodifiedBracedString :: Token -> Maybe String
|
||||
getSingleUnmodifiedBracedString word =
|
||||
case getWordParts word of
|
||||
[t@(T_DollarBraced {})] ->
|
||||
let contents = bracedString t
|
||||
[T_DollarBraced _ _ l] ->
|
||||
let contents = concat $ oversimplify l
|
||||
name = getBracedReference contents
|
||||
in guard (contents == name) >> return t
|
||||
in guard (contents == name) >> return contents
|
||||
_ -> Nothing
|
||||
|
||||
prop_checkAliasesUsesArgs1 = verify checkAliasesUsesArgs "alias a='cp $1 /a'"
|
||||
|
|
|
@ -243,7 +243,7 @@ checkBashisms = ForShell [Sh, Dash] $ \t -> do
|
|||
when (isBashVariable var) $
|
||||
warnMsg id $ var ++ " is"
|
||||
where
|
||||
str = bracedString t
|
||||
str = concat $ oversimplify token
|
||||
var = getBracedReference str
|
||||
check (regex, feature) =
|
||||
when (isJust $ matchRegex regex str) $ warnMsg id feature
|
||||
|
@ -506,13 +506,13 @@ checkMultiDimensionalArrays = ForShell [Bash] f
|
|||
case token of
|
||||
T_Assignment _ _ name (first:second:_) _ -> about second
|
||||
T_IndexedElement _ (first:second:_) _ -> about second
|
||||
T_DollarBraced {} ->
|
||||
when (isMultiDim token) $ about token
|
||||
T_DollarBraced _ _ l ->
|
||||
when (isMultiDim l) $ about token
|
||||
_ -> return ()
|
||||
about t = warn (getId t) 2180 "Bash does not support multidimensional arrays. Use 1D or associative arrays."
|
||||
|
||||
re = mkRegex "^\\[.*\\]\\[.*\\]" -- Fixme, this matches ${foo:- [][]} and such as well
|
||||
isMultiDim t = getBracedModifier (bracedString t) `matches` re
|
||||
isMultiDim l = getBracedModifier (concat $ oversimplify l) `matches` re
|
||||
|
||||
prop_checkPS11 = verify checkPS1Assignments "PS1='\\033[1;35m\\$ '"
|
||||
prop_checkPS11a= verify checkPS1Assignments "export PS1='\\033[1;35m\\$ '"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue