From c7964a7a78e73d1b6745fb7c1d75e88e41c71c75 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 5 Dec 2015 16:09:44 -0800 Subject: [PATCH] Warn about missing space in 'function foo{'. --- ShellCheck/Parser.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ShellCheck/Parser.hs b/ShellCheck/Parser.hs index 8c499ce..f9fa400 100644 --- a/ShellCheck/Parser.hs +++ b/ShellCheck/Parser.hs @@ -1976,6 +1976,9 @@ prop_readFunctionDefinition5 = isOk readFunctionDefinition ":(){ :|:;}" prop_readFunctionDefinition6 = isOk readFunctionDefinition "?(){ foo; }" prop_readFunctionDefinition7 = isOk readFunctionDefinition "..(){ cd ..; }" prop_readFunctionDefinition8 = isOk readFunctionDefinition "foo() (ls)" +prop_readFunctionDefinition9 = isOk readFunctionDefinition "function foo { true; }" +prop_readFunctionDefinition10= isOk readFunctionDefinition "function foo () { true; }" +prop_readFunctionDefinition11= isWarning readFunctionDefinition "function foo{\ntrue\n}" readFunctionDefinition = called "function" $ do functionSignature <- try readFunctionSignature allspacing @@ -1993,8 +1996,11 @@ readFunctionDefinition = called "function" $ do whitespace spacing name <- readFunctionName - spacing + spaces <- spacing hasParens <- wasIncluded readParens + when (not hasParens && null spaces) $ + acceptButWarn (lookAhead (oneOf "{(")) + ErrorC 1095 "You need a space or linefeed between the function name and body." return $ T_Function id (FunctionKeyword True) (FunctionParentheses hasParens) name readWithoutFunction = try $ do