Use null instead of comparing with empty lists
This commit is contained in:
parent
e6e89d68fd
commit
c29b6afa56
|
@ -563,7 +563,7 @@ checkShebang params (T_Annotation _ list t) =
|
||||||
isOverride _ = False
|
isOverride _ = False
|
||||||
checkShebang params (T_Script _ (T_Literal id sb) _) = execWriter $ do
|
checkShebang params (T_Script _ (T_Literal id sb) _) = execWriter $ do
|
||||||
unless (shellTypeSpecified params) $ do
|
unless (shellTypeSpecified params) $ do
|
||||||
when (sb == "") $
|
when (null sb) $
|
||||||
err id 2148 "Tips depend on target shell and yours is unknown. Add a shebang."
|
err id 2148 "Tips depend on target shell and yours is unknown. Add a shebang."
|
||||||
when (executableFromShebang sb == "ash") $
|
when (executableFromShebang sb == "ash") $
|
||||||
warn id 2187 "Ash scripts will be checked as Dash. Add '# shellcheck shell=dash' to silence."
|
warn id 2187 "Ash scripts will be checked as Dash. Add '# shellcheck shell=dash' to silence."
|
||||||
|
@ -2332,7 +2332,7 @@ checkWhileReadPitfalls _ (T_WhileExpression id [command] contents)
|
||||||
checkMuncher _ = return ()
|
checkMuncher _ = return ()
|
||||||
|
|
||||||
stdinRedirect (T_FdRedirect _ fd _)
|
stdinRedirect (T_FdRedirect _ fd _)
|
||||||
| fd == "" || fd == "0" = True
|
| null fd || fd == "0" = True
|
||||||
stdinRedirect _ = False
|
stdinRedirect _ = False
|
||||||
checkWhileReadPitfalls _ _ = return ()
|
checkWhileReadPitfalls _ _ = return ()
|
||||||
|
|
||||||
|
|
|
@ -643,7 +643,7 @@ getModifiedVariableCommand base@(T_SimpleCommand id cmdPrefix (T_NormalWord _ (T
|
||||||
getModifierParam _ _ = []
|
getModifierParam _ _ = []
|
||||||
|
|
||||||
letParamToLiteral token =
|
letParamToLiteral token =
|
||||||
if var == ""
|
if null var
|
||||||
then []
|
then []
|
||||||
else [(base, token, var, DataString $ SourceFrom [stripEqualsFrom token])]
|
else [(base, token, var, DataString $ SourceFrom [stripEqualsFrom token])]
|
||||||
where var = takeWhile isVariableChar $ dropWhile (`elem` "+-") $ concat $ oversimplify token
|
where var = takeWhile isVariableChar $ dropWhile (`elem` "+-") $ concat $ oversimplify token
|
||||||
|
@ -952,7 +952,7 @@ getOpts string flags = process flags
|
||||||
takesArg <- Map.lookup flag1 flagMap
|
takesArg <- Map.lookup flag1 flagMap
|
||||||
if takesArg
|
if takesArg
|
||||||
then do
|
then do
|
||||||
guard $ flag2 == ""
|
guard $ null flag2
|
||||||
more <- process rest
|
more <- process rest
|
||||||
return $ (flag1, token2) : more
|
return $ (flag1, token2) : more
|
||||||
else do
|
else do
|
||||||
|
|
|
@ -198,11 +198,11 @@ prop_optionDisablesBadShebang =
|
||||||
}
|
}
|
||||||
|
|
||||||
prop_annotationDisablesBadShebang =
|
prop_annotationDisablesBadShebang =
|
||||||
[] == check "#!/usr/bin/python\n# shellcheck shell=sh\ntrue\n"
|
null $ check "#!/usr/bin/python\n# shellcheck shell=sh\ntrue\n"
|
||||||
|
|
||||||
|
|
||||||
prop_canParseDevNull =
|
prop_canParseDevNull =
|
||||||
[] == check "source /dev/null"
|
null $ check "source /dev/null"
|
||||||
|
|
||||||
prop_failsWhenNotSourcing =
|
prop_failsWhenNotSourcing =
|
||||||
[1091, 2154] == check "source lol; echo \"$bar\""
|
[1091, 2154] == check "source lol; echo \"$bar\""
|
||||||
|
@ -218,7 +218,7 @@ prop_worksWhenDotting =
|
||||||
|
|
||||||
-- FIXME: This should really be giving [1093], "recursively sourced"
|
-- FIXME: This should really be giving [1093], "recursively sourced"
|
||||||
prop_noInfiniteSourcing =
|
prop_noInfiniteSourcing =
|
||||||
[] == checkWithIncludes [("lib", "source lib")] "source lib"
|
null $ checkWithIncludes [("lib", "source lib")] "source lib"
|
||||||
|
|
||||||
prop_canSourceBadSyntax =
|
prop_canSourceBadSyntax =
|
||||||
[1094, 2086] == checkWithIncludes [("lib", "for f; do")] "source lib; echo $1"
|
[1094, 2086] == checkWithIncludes [("lib", "for f; do")] "source lib; echo $1"
|
||||||
|
@ -239,10 +239,10 @@ prop_recursiveParsing =
|
||||||
[1037] == checkRecursive [("lib", "echo \"$10\"")] "source lib"
|
[1037] == checkRecursive [("lib", "echo \"$10\"")] "source lib"
|
||||||
|
|
||||||
prop_nonRecursiveAnalysis =
|
prop_nonRecursiveAnalysis =
|
||||||
[] == checkWithIncludes [("lib", "echo $1")] "source lib"
|
null $ checkWithIncludes [("lib", "echo $1")] "source lib"
|
||||||
|
|
||||||
prop_nonRecursiveParsing =
|
prop_nonRecursiveParsing =
|
||||||
[] == checkWithIncludes [("lib", "echo \"$10\"")] "source lib"
|
null $ checkWithIncludes [("lib", "echo \"$10\"")] "source lib"
|
||||||
|
|
||||||
prop_sourceDirectiveDoesntFollowFile =
|
prop_sourceDirectiveDoesntFollowFile =
|
||||||
null $ checkWithIncludes
|
null $ checkWithIncludes
|
||||||
|
@ -328,7 +328,7 @@ prop_optionIncludes4 =
|
||||||
[2154] == checkOptionIncludes (Just [2154]) "#!/bin/sh\n var='a b'\n echo $var\n echo $bar"
|
[2154] == checkOptionIncludes (Just [2154]) "#!/bin/sh\n var='a b'\n echo $var\n echo $bar"
|
||||||
|
|
||||||
|
|
||||||
prop_readsRcFile = result == []
|
prop_readsRcFile = null result
|
||||||
where
|
where
|
||||||
result = checkWithRc "disable=2086" emptyCheckSpec {
|
result = checkWithRc "disable=2086" emptyCheckSpec {
|
||||||
csScript = "#!/bin/sh\necho $1",
|
csScript = "#!/bin/sh\necho $1",
|
||||||
|
|
|
@ -345,7 +345,7 @@ returnOrExit multi invalid = (f . arguments)
|
||||||
invalid (getId value)
|
invalid (getId value)
|
||||||
f _ = return ()
|
f _ = return ()
|
||||||
|
|
||||||
isInvalid s = s == "" || any (not . isDigit) s || length s > 5
|
isInvalid s = null s || any (not . isDigit) s || length s > 5
|
||||||
|| let value = (read s :: Integer) in value > 255
|
|| let value = (read s :: Integer) in value > 255
|
||||||
|
|
||||||
literal token = fromJust $ getLiteralStringExt lit token
|
literal token = fromJust $ getLiteralStringExt lit token
|
||||||
|
@ -706,7 +706,7 @@ checkReadExpansions = CommandCheck (Exactly "read") check
|
||||||
options = getGnuOpts flagsForRead
|
options = getGnuOpts flagsForRead
|
||||||
getVars cmd = fromMaybe [] $ do
|
getVars cmd = fromMaybe [] $ do
|
||||||
opts <- options cmd
|
opts <- options cmd
|
||||||
return [y | (x,y) <- opts, x == "" || x == "a"]
|
return [y | (x,y) <- opts, null x || x == "a"]
|
||||||
|
|
||||||
check cmd = mapM_ warning $ getVars cmd
|
check cmd = mapM_ warning $ getVars cmd
|
||||||
warning t = potentially $ do
|
warning t = potentially $ do
|
||||||
|
@ -1057,7 +1057,7 @@ checkSudoRedirect = CommandCheck (Basename "sudo") f
|
||||||
Just (T_Redirecting _ redirs _) ->
|
Just (T_Redirecting _ redirs _) ->
|
||||||
mapM_ warnAbout redirs
|
mapM_ warnAbout redirs
|
||||||
warnAbout (T_FdRedirect _ s (T_IoFile id op file))
|
warnAbout (T_FdRedirect _ s (T_IoFile id op file))
|
||||||
| (s == "" || s == "&") && not (special file) =
|
| (null s || s == "&") && not (special file) =
|
||||||
case op of
|
case op of
|
||||||
T_Less _ ->
|
T_Less _ ->
|
||||||
info (getId op) 2024
|
info (getId op) 2024
|
||||||
|
|
|
@ -3169,7 +3169,7 @@ readScriptFile sourced = do
|
||||||
Nothing -> parseProblemAt pos ErrorC 1008 "This shebang was unrecognized. ShellCheck only supports sh/bash/dash/ksh. Add a 'shell' directive to specify."
|
Nothing -> parseProblemAt pos ErrorC 1008 "This shebang was unrecognized. ShellCheck only supports sh/bash/dash/ksh. Add a 'shell' directive to specify."
|
||||||
|
|
||||||
isValidShell s =
|
isValidShell s =
|
||||||
let good = s == "" || any (`isPrefixOf` s) goodShells
|
let good = null s || any (`isPrefixOf` s) goodShells
|
||||||
bad = any (`isPrefixOf` s) badShells
|
bad = any (`isPrefixOf` s) badShells
|
||||||
in
|
in
|
||||||
if good
|
if good
|
||||||
|
|
Loading…
Reference in New Issue