From 884eff0c36fae38b4d197345e458879c5bc9c0a3 Mon Sep 17 00:00:00 2001 From: Ng Zhi An Date: Tue, 22 May 2018 22:43:26 -0700 Subject: [PATCH] Add T_SourceCommand to wrap source commands and sourced code Fixes #1181 --- src/ShellCheck/AST.hs | 9 ++++++--- src/ShellCheck/Checks/ShellSupport.hs | 5 ++++- src/ShellCheck/Parser.hs | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/ShellCheck/AST.hs b/src/ShellCheck/AST.hs index 2f99c3b..cd96165 100644 --- a/src/ShellCheck/AST.hs +++ b/src/ShellCheck/AST.hs @@ -134,7 +134,8 @@ data Token = | T_Pipe Id String | T_CoProc Id (Maybe String) Token | T_CoProcBody Id Token - | T_Include Id Token Token -- . & source: SimpleCommand T_Script + | T_Include Id Token + | T_SourceCommand Id Token Token deriving (Show) data Annotation = @@ -270,7 +271,8 @@ analyze f g i = delve (T_Annotation id anns t) = d1 t $ T_Annotation id anns delve (T_CoProc id var body) = d1 body $ T_CoProc id var delve (T_CoProcBody id t) = d1 t $ T_CoProcBody id - delve (T_Include id includer script) = d2 includer script $ T_Include id + delve (T_Include id script) = d1 script $ T_Include id + delve (T_SourceCommand id includer t_include) = d2 includer t_include $ T_SourceCommand id delve t = return t getId :: Token -> Id @@ -370,7 +372,8 @@ getId t = case t of T_Pipe id _ -> id T_CoProc id _ _ -> id T_CoProcBody id _ -> id - T_Include id _ _ -> id + T_Include id _ -> id + T_SourceCommand id _ _ -> id T_UnparsedIndex id _ _ -> id TC_Empty id _ -> id TA_Variable id _ _ -> id diff --git a/src/ShellCheck/Checks/ShellSupport.hs b/src/ShellCheck/Checks/ShellSupport.hs index 63d9029..cfe2ded 100644 --- a/src/ShellCheck/Checks/ShellSupport.hs +++ b/src/ShellCheck/Checks/ShellSupport.hs @@ -283,7 +283,10 @@ checkBashisms = ForShell [Sh, Dash] $ \t -> do ("read", if isDash then ["r", "p"] else ["r"]), ("ulimit", ["f"]) ] - + bashism t@(T_SourceCommand id src _) = + let name = fromMaybe "" $ getCommandName src + in do + when (name == "source") $ warnMsg id "'source' in place of '.' is" bashism _ = return () varChars="_0-9a-zA-Z" diff --git a/src/ShellCheck/Parser.hs b/src/ShellCheck/Parser.hs index 08d94e1..edfb2e2 100644 --- a/src/ShellCheck/Parser.hs +++ b/src/ShellCheck/Parser.hs @@ -1922,7 +1922,7 @@ readSource pos t@(T_Redirecting _ _ (T_SimpleCommand _ _ (cmd:file:_))) = do let included = do src <- subRead filename script - return $ T_Include id t src + return $ T_SourceCommand id t (T_Include id src) let failed = do parseNoteAt pos WarningC 1094