Add SC2238 about redirections to command names
This commit is contained in:
parent
1a6ae4f19e
commit
3e2cb26119
|
@ -2,6 +2,7 @@
|
|||
### Added
|
||||
- Command line option --severity/-S for filtering by minimum severity
|
||||
- SC2236/SC2237: Suggest -n/-z instead of ! -z/-n
|
||||
- SC2238: Warn when redirecting to a known command name, e.g. ls > rm
|
||||
### Changed
|
||||
- Most warnings now have useful end positions
|
||||
- SC1117 about unknown double-quoted escape sequences has been retired
|
||||
|
|
|
@ -169,6 +169,7 @@ nodeChecks = [
|
|||
,checkForLoopGlobVariables
|
||||
,checkSubshelledTests
|
||||
,checkInvertedStringTest
|
||||
,checkRedirectionToCommand
|
||||
]
|
||||
|
||||
|
||||
|
@ -3027,6 +3028,15 @@ checkInvertedStringTest _ t =
|
|||
_ -> return ()
|
||||
_ -> return ()
|
||||
|
||||
prop_checkRedirectionToCommand1 = verify checkRedirectionToCommand "ls > rm"
|
||||
prop_checkRedirectionToCommand2 = verifyNot checkRedirectionToCommand "ls > 'rm'"
|
||||
prop_checkRedirectionToCommand3 = verifyNot checkRedirectionToCommand "ls > myfile"
|
||||
checkRedirectionToCommand _ t =
|
||||
case t of
|
||||
T_IoFile _ _ (T_NormalWord id [T_Literal _ str]) | str `elem` commonCommands ->
|
||||
unless (str == "file") $ -- This would be confusing
|
||||
warn id 2238 "Redirecting to/from command name instead of file. Did you want pipes/xargs (or quote to ignore)?"
|
||||
_ -> return ()
|
||||
|
||||
return []
|
||||
runTests = $( [| $(forAllProperties) (quickCheckWithResult (stdArgs { maxSuccess = 1 }) ) |])
|
||||
|
|
Loading…
Reference in New Issue