Merge parser and analyzer shebang parsing

This commit is contained in:
Vidar Holen 2021-03-11 23:04:17 -08:00
parent ea83b602d7
commit f02c297fdd
5 changed files with 52 additions and 29 deletions

View file

@ -24,7 +24,7 @@
module ShellCheck.Parser (parseScript, runTests) where
import ShellCheck.AST
import ShellCheck.ASTLib
import ShellCheck.ASTLib hiding (runTests)
import ShellCheck.Data
import ShellCheck.Interface
@ -3216,8 +3216,8 @@ readScriptFile sourced = do
let ignoreShebang = shellAnnotationSpecified || shellFlagSpecified
unless ignoreShebang $
verifyShebang pos (getShell shebangString)
if ignoreShebang || isValidShell (getShell shebangString) /= Just False
verifyShebang pos (executableFromShebang shebangString)
if ignoreShebang || isValidShell (executableFromShebang shebangString) /= Just False
then do
commands <- withAnnotations annotations readCompoundListOrEmpty
id <- endSpan start
@ -3231,18 +3231,6 @@ readScriptFile sourced = do
return $ T_Script id shebang []
where
basename s = reverse . takeWhile (/= '/') . reverse $ s
skipFlags = dropWhile ("-" `isPrefixOf`)
getShell sb =
case words sb of
[] -> ""
[x] -> basename x
(first:args) | basename first == "env" ->
fromMaybe "" $ find (notElem '=') $ skipFlags args
(first:second:args) | basename first == "busybox" ->
second
(first:_) -> basename first
verifyShebang pos s = do
case isValidShell s of
Just True -> return ()