Simplify check and checkTranslatedStringVariable
Avoid the "potentially" and "Maybe" business, and just use regular guards.
This commit is contained in:
parent
ffbbfcfe25
commit
4bfe6496d9
|
@ -2933,16 +2933,15 @@ checkTrailingBracket _ token =
|
||||||
T_SimpleCommand _ _ tokens@(_:_) -> check (last tokens) token
|
T_SimpleCommand _ _ tokens@(_:_) -> check (last tokens) token
|
||||||
_ -> return ()
|
_ -> return ()
|
||||||
where
|
where
|
||||||
check t command =
|
check (T_NormalWord id [T_Literal _ str]) command
|
||||||
case t of
|
| str `elem` [ "]]", "]" ]
|
||||||
T_NormalWord id [T_Literal _ str] -> potentially $ do
|
&& opposite `notElem` parameters
|
||||||
guard $ str `elem` [ "]]", "]" ]
|
= warn id 2171 $
|
||||||
let opposite = invert str
|
|
||||||
parameters = oversimplify command
|
|
||||||
guard $ opposite `notElem` parameters
|
|
||||||
return $ warn id 2171 $
|
|
||||||
"Found trailing " ++ str ++ " outside test. Add missing " ++ opposite ++ " or quote if intentional."
|
"Found trailing " ++ str ++ " outside test. Add missing " ++ opposite ++ " or quote if intentional."
|
||||||
_ -> return ()
|
where
|
||||||
|
opposite = invert str
|
||||||
|
parameters = oversimplify command
|
||||||
|
check _ _ = return ()
|
||||||
invert s =
|
invert s =
|
||||||
case s of
|
case s of
|
||||||
"]]" -> "[["
|
"]]" -> "[["
|
||||||
|
@ -3462,12 +3461,10 @@ prop_checkTranslatedStringVariable2 = verifyNot checkTranslatedStringVariable "$
|
||||||
prop_checkTranslatedStringVariable3 = verifyNot checkTranslatedStringVariable "$\"..\""
|
prop_checkTranslatedStringVariable3 = verifyNot checkTranslatedStringVariable "$\"..\""
|
||||||
prop_checkTranslatedStringVariable4 = verifyNot checkTranslatedStringVariable "var=val; $\"$var\""
|
prop_checkTranslatedStringVariable4 = verifyNot checkTranslatedStringVariable "var=val; $\"$var\""
|
||||||
prop_checkTranslatedStringVariable5 = verifyNot checkTranslatedStringVariable "foo=var; bar=val2; $\"foo bar\""
|
prop_checkTranslatedStringVariable5 = verifyNot checkTranslatedStringVariable "foo=var; bar=val2; $\"foo bar\""
|
||||||
checkTranslatedStringVariable params (T_DollarDoubleQuoted id [T_Literal _ s]) =
|
checkTranslatedStringVariable params (T_DollarDoubleQuoted id [T_Literal _ s])
|
||||||
sequence_ $ do
|
| all isVariableChar s
|
||||||
guard $ all isVariableChar s
|
&& Map.member s assignments
|
||||||
Map.lookup s assignments
|
= warnWithFix id 2256 "This translated string is the name of a variable. Flip leading $ and \" if this should be a quoted substitution." (fix id)
|
||||||
return $
|
|
||||||
warnWithFix id 2256 "This translated string is the name of a variable. Flip leading $ and \" if this should be a quoted substitution." (fix id)
|
|
||||||
where
|
where
|
||||||
assignments = foldl (flip ($)) Map.empty (map insertAssignment $ variableFlow params)
|
assignments = foldl (flip ($)) Map.empty (map insertAssignment $ variableFlow params)
|
||||||
insertAssignment (Assignment (_, token, name, _)) | isVariableName name =
|
insertAssignment (Assignment (_, token, name, _)) | isVariableName name =
|
||||||
|
|
Loading…
Reference in New Issue