Check for tr hello world
This commit is contained in:
parent
b718e5f108
commit
1e3b429abe
|
@ -63,7 +63,7 @@ basicChecks = [
|
||||||
,checkOrNeq
|
,checkOrNeq
|
||||||
,checkEcho
|
,checkEcho
|
||||||
,checkConstantIfs
|
,checkConstantIfs
|
||||||
,checkTrAZ
|
,checkTr
|
||||||
,checkPipedAssignment
|
,checkPipedAssignment
|
||||||
,checkAssignAteCommand
|
,checkAssignAteCommand
|
||||||
,checkUuoe
|
,checkUuoe
|
||||||
|
@ -567,23 +567,38 @@ checkUuoe = checkCommand "echo" f where
|
||||||
f [T_NormalWord id [T_DoubleQuoted _ [(T_DollarExpansion _ _)]]] = msg id
|
f [T_NormalWord id [T_DoubleQuoted _ [(T_DollarExpansion _ _)]]] = msg id
|
||||||
f _ = return ()
|
f _ = return ()
|
||||||
|
|
||||||
prop_checkTrAZ1 = verify checkTrAZ "tr [a-f] [A-F]"
|
prop_checkTr1 = verify checkTr "tr [a-f] [A-F]"
|
||||||
prop_checkTrAZ2 = verify checkTrAZ "tr 'a-z' 'A-Z'"
|
prop_checkTr2 = verify checkTr "tr 'a-z' 'A-Z'"
|
||||||
prop_checkTrAZ2a= verify checkTrAZ "tr '[a-z]' '[A-Z]'"
|
prop_checkTr2a= verify checkTr "tr '[a-z]' '[A-Z]'"
|
||||||
prop_checkTrAZ3 = verifyNot checkTrAZ "tr -d '[:lower:]'"
|
prop_checkTr3 = verifyNot checkTr "tr -d '[:lower:]'"
|
||||||
prop_checkTrAZ4 = verifyNot checkTrAZ "ls [a-z]"
|
prop_checkTr4 = verifyNot checkTr "ls [a-z]"
|
||||||
checkTrAZ = checkCommand "tr" (mapM_ f)
|
prop_checkTr5 = verify checkTr "tr foo bar"
|
||||||
|
prop_checkTr6 = verify checkTr "tr 'hello' 'world'"
|
||||||
|
prop_checkTr8 = verifyNot checkTr "tr aeiou _____"
|
||||||
|
prop_checkTr9 = verifyNot checkTr "a-z n-za-m"
|
||||||
|
prop_checkTr10= verifyNot checkTr "tr --squeeze-repeats rl lr"
|
||||||
|
checkTr = checkCommand "tr" (mapM_ f)
|
||||||
where
|
where
|
||||||
f w | isGlob w = do -- The user will go [ab] -> '[ab]' -> 'ab'. Fixme?
|
f w | isGlob w = do -- The user will go [ab] -> '[ab]' -> 'ab'. Fixme?
|
||||||
warn (getId w) $ "Quote the parameter to tr to prevent glob expansion."
|
warn (getId w) $ "Quote parameters to tr to prevent glob expansion."
|
||||||
f word = case getLiteralString word of
|
f word = case getLiteralString word of
|
||||||
Just "a-z" -> info (getId word) "Use '[:lower:]' to support accents and foreign alphabets."
|
Just "a-z" -> info (getId word) "Use '[:lower:]' to support accents and foreign alphabets."
|
||||||
Just "A-Z" -> info (getId word) "Use '[:upper:]' to support accents and foreign alphabets."
|
Just "A-Z" -> info (getId word) "Use '[:upper:]' to support accents and foreign alphabets."
|
||||||
Just s -> unless ("[:" `isPrefixOf` s) $
|
|
||||||
when ("[" `isPrefixOf` s && "]" `isSuffixOf` s && (length s > 2)) $
|
Just s -> do -- Eliminate false positives by only looking for dupes in SET2?
|
||||||
info (getId word) "Don't use [] around ranges in tr, it replaces literal square brackets."
|
when ((not $ "-" `isPrefixOf` s) && duplicated s) $
|
||||||
|
info (getId word) "tr replaces sets of chars, not words (mentioned due to duplicates)."
|
||||||
|
|
||||||
|
unless ("[:" `isPrefixOf` s) $
|
||||||
|
when ("[" `isPrefixOf` s && "]" `isSuffixOf` s && (length s > 2)) $
|
||||||
|
info (getId word) "Don't use [] around ranges in tr, it replaces literal square brackets."
|
||||||
Nothing -> return ()
|
Nothing -> return ()
|
||||||
|
|
||||||
|
duplicated s =
|
||||||
|
let relevant = filter isAlpha s
|
||||||
|
in not $ relevant == nub relevant
|
||||||
|
|
||||||
|
|
||||||
prop_checkFindNameGlob1 = verify checkFindNameGlob "find / -name *.php"
|
prop_checkFindNameGlob1 = verify checkFindNameGlob "find / -name *.php"
|
||||||
prop_checkFindNameGlob2 = verify checkFindNameGlob "find / -type f -ipath *(foo)"
|
prop_checkFindNameGlob2 = verify checkFindNameGlob "find / -type f -ipath *(foo)"
|
||||||
prop_checkFindNameGlob3 = verifyNot checkFindNameGlob "find * -name '*.php'"
|
prop_checkFindNameGlob3 = verifyNot checkFindNameGlob "find * -name '*.php'"
|
||||||
|
|
Loading…
Reference in New Issue