From 9eac0bfab939c8c41269808ca1244fddfffb454c Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Fri, 16 Nov 2012 22:20:35 -0800 Subject: [PATCH] Homogenized punctuation across messages. --- ShellCheck/Analytics.hs | 30 ++++++++++----------- ShellCheck/Parser.hs | 58 ++++++++++++++++++++--------------------- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index f4bbb4d..57aa006 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -123,14 +123,14 @@ prop_checkForInQuoted = verify checkForInQuoted "for f in \"$(ls)\"; do echo foo prop_checkForInQuoted2 = verifyNot checkForInQuoted "for f in \"$@\"; do echo foo; done" checkForInQuoted (T_ForIn _ f [T_NormalWord _ [T_DoubleQuoted id list]] _) = when (any (\x -> willSplit x && not (isMagicInQuotes x)) list) $ - err id $ "Since you double quoted this, it will not word split, and the loop will only run once" + err id $ "Since you double quoted this, it will not word split, and the loop will only run once." checkForInQuoted _ = return () prop_checkForInLs = verify checkForInLs "for f in $(ls *.mp3); do mplayer \"$f\"; done" checkForInLs (T_ForIn _ f [T_NormalWord _ [T_DollarExpansion id [x]]] _) = case deadSimple x of ("ls":n) -> let args = (if n == [] then ["*"] else n) in - err id $ "Don't use 'for "++f++" in $(ls " ++ (intercalate " " n) ++ ")'. Use 'for "++f++" in "++ (intercalate " " args) ++ "'" + err id $ "Don't use 'for "++f++" in $(ls " ++ (intercalate " " n) ++ ")'. Use 'for "++f++" in "++ (intercalate " " args) ++ "' ." _ -> return () checkForInLs _ = return () @@ -149,7 +149,7 @@ checkMissingForQuotes t m = markUnquoted _ _ = return () mu (T_DollarBraced id s) | s == f = warning id mu _ = return () - warning id = warn id $ "Variables that could contain spaces should be quoted" + warning id = warn id $ "Variables that could contain spaces should be quoted." cq _ = return () parents = getParentTree t @@ -163,14 +163,14 @@ checkMissingPositionalQuotes t m = cq l@(T_NormalWord _ list) = unless (inUnquotableContext parents l) $ mapM_ checkPos list where checkPos (T_DollarBraced id s) | all isDigit (getBracedReference s) = - warn id $ "Positional parameters should be quoted to avoid whitespace trouble" + warn id $ "Positional parameters should be quoted to avoid whitespace trouble." checkPos _ = return () cq _ = return () parents = getParentTree t prop_checkUnquotedExpansions = verify checkUnquotedExpansions "rm $(ls)" checkUnquotedExpansions (T_SimpleCommand _ _ cmds) = mapM_ check cmds - where check (T_NormalWord _ [T_DollarExpansion id _]) = warn id "Quote the expansion to prevent word splitting" + where check (T_NormalWord _ [T_DollarExpansion id _]) = warn id "Quote the expansion to prevent word splitting." check _ = return () checkUnquotedExpansions _ = return () @@ -181,7 +181,7 @@ checkRedirectToSame s@(T_Pipeline _ list) = mapM_ (\l -> (mapM_ (\x -> doAnalysis (checkOccurences x) l) (getAllRedirs list))) list where checkOccurences (T_NormalWord exceptId x) (T_NormalWord newId y) = when (x == y && exceptId /= newId) (do - let note = Note InfoC $ "Make sure not to read and write the same file in the same pipeline" + let note = Note InfoC $ "Make sure not to read and write the same file in the same pipeline." addNoteFor newId $ note addNoteFor exceptId $ note) checkOccurences _ _ = return () @@ -204,14 +204,14 @@ checkShorthandIf _ = return () prop_checkDollarStar = verify checkDollarStar "for f in $*; do ..; done" checkDollarStar (T_NormalWord _ [(T_DollarBraced id "*")]) = - warn id $ "Use \"$@\" (with quotes) to prevent whitespace problems" + warn id $ "Use \"$@\" (with quotes) to prevent whitespace problems." checkDollarStar _ = return () prop_checkUnquotedDollarAt = verify checkUnquotedDollarAt "ls $@" prop_checkUnquotedDollarAt2 = verifyNot checkUnquotedDollarAt "ls \"$@\"" checkUnquotedDollarAt (T_NormalWord _ [T_DollarBraced id "@"]) = - err id $ "Add double quotes around $@, otherwise it's just like $* and breaks on spaces" + err id $ "Add double quotes around $@, otherwise it's just like $* and breaks on spaces." checkUnquotedDollarAt _ = return () prop_checkStderrRedirect = verify checkStderrRedirect "test 2>&1 > cow" @@ -254,7 +254,7 @@ prop_checkNumberComparisons4 = verify checkNumberComparisons "[ $foo > $bar ]" prop_checkNumberComparisons5 = verify checkNumberComparisons "until [ $n <= $z ]; do echo foo; done" checkNumberComparisons (TC_Binary id typ op lhs rhs) | op `elem` ["<", ">", "<=", ">="] = do - when (isNum lhs || isNum rhs) $ err id $ "\"" ++ op ++ "\" is for string comparisons. Use " ++ (eqv op) + when (isNum lhs || isNum rhs) $ err id $ "\"" ++ op ++ "\" is for string comparisons. Use " ++ (eqv op) ++" ." when (typ == SingleBracket) $ err id $ "Can't use " ++ op ++" in [ ]. Use [[ ]]." where isNum t = case deadSimple t of [v] -> all isDigit v @@ -270,7 +270,7 @@ prop_checkNoaryWasBinary = verify checkNoaryWasBinary "[[ a==$foo ]]" prop_checkNoaryWasBinary2 = verify checkNoaryWasBinary "[ $foo=3 ]" checkNoaryWasBinary (TC_Noary _ _ t@(T_NormalWord id l)) = do let str = concat $ deadSimple t - when ('=' `elem` str) $ err id $ "Always true because you didn't put spaces around the =" + when ('=' `elem` str) $ err id $ "Always true because you didn't put spaces around the = ." checkNoaryWasBinary _ = return () prop_checkBraceExpansionVars = verify checkBraceExpansionVars "echo {1..$n}" @@ -286,7 +286,7 @@ checkForDecimals _ = return () prop_checkDivBeforeMult = verify checkDivBeforeMult "echo $((c/n*100))" prop_checkDivBeforeMult2 = verifyNot checkDivBeforeMult "echo $((c*100/n))" checkDivBeforeMult (TA_Binary _ "*" (TA_Binary id "/" _ _) _) = do - info id $ "Increase precision by replacing a/b*c with a*c/b" + info id $ "Increase precision by replacing a/b*c with a*c/b." checkDivBeforeMult _ = return () prop_checkArithmeticDeref = verify checkArithmeticDeref "echo $((3+$foo))" @@ -294,14 +294,14 @@ prop_checkArithmeticDeref2 = verify checkArithmeticDeref "cow=14; (( s+= $cow )) prop_checkArithmeticDeref3 = verifyNot checkArithmeticDeref "cow=1/40; (( s+= ${cow%%/*} ))" prop_checkArithmeticDeref4 = verifyNot checkArithmeticDeref "(( ! $? ))" checkArithmeticDeref (TA_Expansion _ (T_DollarBraced id str)) | not $ any (`elem` "/.:#%?*@") $ str = - warn id $ "Don't use $ on variables in (( )) unless you want to dereference twice" + style id $ "Don't use $ on variables in (( ))." checkArithmeticDeref _ = return () prop_checkComparisonAgainstGlob = verify checkComparisonAgainstGlob "[[ $cow == $bar ]]" prop_checkComparisonAgainstGlob2 = verifyNot checkComparisonAgainstGlob "[[ $cow == \"$bar\" ]]" checkComparisonAgainstGlob (TC_Binary _ DoubleBracket op _ (T_NormalWord id [T_DollarBraced _ _])) | op == "=" || op == "==" = - warn id $ "Quote the rhs of = in [[ ]] to prevent glob interpretation" + warn id $ "Quote the rhs of = in [[ ]] to prevent glob interpretation." checkComparisonAgainstGlob _ = return () prop_checkCommarrays1 = verify checkCommarrays "a=(1, 2)" @@ -309,7 +309,7 @@ prop_checkCommarrays2 = verify checkCommarrays "a+=(1,2,3)" prop_checkCommarrays3 = verifyNot checkCommarrays "cow=(1 \"foo,bar\" 3)" checkCommarrays (T_Array id l) = if any ("," `isSuffixOf`) (concatMap deadSimple l) || (length $ filter (==',') (concat $ concatMap deadSimple l)) > 1 - then warn id "Use spaces, not commas, to separate array elements" + then warn id "Use spaces, not commas, to separate array elements." else return () checkCommarrays _ = return () @@ -375,7 +375,7 @@ checkPrintfVar = checkCommand "printf" f where f _ = return () check format = if not $ isLiteral format - then warn (getId format) $ "Don't use printf \"$foo\", use printf \"%s\" \"$foo\"" + then warn (getId format) $ "Don't use variables in the printf format string. Use printf \"%s\" \"$foo\"." else return () --- Subshell detection diff --git a/ShellCheck/Parser.hs b/ShellCheck/Parser.hs index ab158c0..a4daa28 100644 --- a/ShellCheck/Parser.hs +++ b/ShellCheck/Parser.hs @@ -61,7 +61,7 @@ allspacing = do when x allspacing carriageReturn = do - parseNote ErrorC "Literal carriage return. Run script through tr -d '\\r' " + parseNote ErrorC "Literal carriage return. Run script through tr -d '\\r' ." char '\r' --------- Message/position annotation on top of user state @@ -186,7 +186,7 @@ readConditionContents single = do arg <- readCondWord return $ op arg) <|> (do - parseProblemAt pos ErrorC $ "Expected this to be an argument to the unary condition" + parseProblemAt pos ErrorC $ "Expected this to be an argument to the unary condition." fail "oops") readCondUnaryOp = try $ do @@ -207,7 +207,7 @@ readConditionContents single = do if (endedWithBracket x) then do lookAhead (try $ (many whitespace) >> (eof <|> disregard readSeparator <|> disregard (g_Then <|> g_Do))) - parseProblemAt pos ErrorC $ "You need a space before the " ++ if single then "]" else "]]" + parseProblemAt pos ErrorC $ "You need a space before the " ++ (if single then "]" else "]]") ++ "." else disregard spacing return x @@ -220,7 +220,7 @@ readConditionContents single = do id <- getNextId x <- try (string "&&" <|> string "-a") when (single && x == "&&") $ addNoteFor id $ Note ErrorC "You can't use && inside [..]. Use [[..]] instead." - when (not single && x == "-a") $ addNoteFor id $ Note ErrorC "In [[..]], use && instead of -a" + when (not single && x == "-a") $ addNoteFor id $ Note ErrorC "In [[..]], use && instead of -a." softCondSpacing return $ TC_And id typ x @@ -229,7 +229,7 @@ readConditionContents single = do id <- getNextId x <- try (string "||" <|> string "-o") when (single && x == "||") $ addNoteFor id $ Note ErrorC "You can't use || inside [..]. Use [[..]] instead." - when (not single && x == "-o") $ addNoteFor id $ Note ErrorC "In [[..]], use && instead of -o" + when (not single && x == "-o") $ addNoteFor id $ Note ErrorC "In [[..]], use && instead of -o." softCondSpacing return $ TC_Or id typ x @@ -239,13 +239,13 @@ readConditionContents single = do pos <- getPosition lookAhead (char '[') parseProblemAt pos ErrorC $ if single - then "Don't use [] for grouping. Use \\( .. \\) " + then "Don't use [] for grouping. Use \\( .. \\)." else "Don't use [] for grouping. Use ()." ) (do pos <- getPosition op <- readCondBinaryOp - y <- readCondWord <|> ( (parseProblemAt pos ErrorC $ "Expected another argument for this operator") >> mzero) + y <- readCondWord <|> ( (parseProblemAt pos ErrorC $ "Expected another argument for this operator.") >> mzero) return (x `op` y) ) <|> (return $ TC_Noary id typ x) @@ -489,7 +489,7 @@ readBackTicked = do pos <- getPosition char '`' f <- readGenericLiteral (char '`') - char '`' `attempting` (eof >> parseProblemAt pos ErrorC "Can't find terminating backtick for this one") + char '`' `attempting` (eof >> parseProblemAt pos ErrorC "Can't find terminating backtick for this one.") return $ T_Literal id f @@ -638,7 +638,7 @@ readDollarVariable = do return (T_DollarBraced id [n]) `attempting` do pos <- getPosition num <- lookAhead $ many1 p - parseNoteAt pos ErrorC $ "$" ++ (n:num) ++ " is equivalent to ${" ++ [n] ++ "}"++ num + parseNoteAt pos ErrorC $ "$" ++ (n:num) ++ " is equivalent to ${" ++ [n] ++ "}"++ num ++"." let positional = singleCharred digit let special = singleCharred specialVariable @@ -658,7 +658,7 @@ readDollarLonely = do id <- getNextId char '$' n <- lookAhead (anyChar <|> (eof >> return '_')) - when (n /= '\'') $ parseNote StyleC "$ is not used specially and should therefore be escaped" + when (n /= '\'') $ parseNote StyleC "$ is not used specially and should therefore be escaped." return $ T_Literal id "$" prop_readHereDoc = isOk readHereDoc "<< foo\nlol\ncow\nfoo" @@ -688,16 +688,16 @@ readHereDoc = do `attempting` (eof >> debugHereDoc tokenPosition endToken hereInfo) verifyHereDoc dashed quoted spacing hereInfo = do - when (not dashed && spacing /= "") $ parseNote ErrorC "Use <<- instead of << if you want to indent the end token" - when (dashed && filter (/= '\t') spacing /= "" ) $ parseNote ErrorC "When using <<-, you can only indent with tabs" + when (not dashed && spacing /= "") $ parseNote ErrorC "Use <<- instead of << if you want to indent the end token." + when (dashed && filter (/= '\t') spacing /= "" ) $ parseNote ErrorC "When using <<-, you can only indent with tabs." return () debugHereDoc pos endToken doc = if endToken `isInfixOf` doc - then parseProblemAt pos ErrorC ("Found " ++ endToken ++ " further down, but not by itself at the start of the line") + then parseProblemAt pos ErrorC ("Found " ++ endToken ++ " further down, but not by itself at the start of the line.") else if (map toLower endToken) `isInfixOf` (map toLower doc) then parseProblemAt pos ErrorC ("Found " ++ endToken ++ " further down, but with wrong casing.") - else parseProblemAt pos ErrorC ("Couldn't find end token `" ++ endToken ++ "' in the here document ") + else parseProblemAt pos ErrorC ("Couldn't find end token `" ++ endToken ++ "' in the here document.") readFilename = readNormalWord @@ -752,7 +752,7 @@ readSeparatorOp = do spacing pos <- getPosition char ';' - parseProblemAt pos ErrorC "It's not 'foo &; bar', just 'foo & bar'. " + parseProblemAt pos ErrorC "It's not 'foo &; bar', just 'foo & bar'." return '&' ) <|> char ';' <|> char '&' spacing @@ -857,14 +857,14 @@ readIfClause = do elses <- option [] readElsePart g_Fi <|> (do eof - parseProblemAt pos ErrorC "Can't find 'fi' for this if. Make sure it's preceeded by a ; or \\n" + parseProblemAt pos ErrorC "Can't find 'fi' for this if. Make sure it's preceeded by a ; or \\n." fail "lol" ) return $ T_IfExpression id ((condition, action):elifs) elses checkIfNotSpecial pos key stuff = do eof - let f (T_Literal id str) | str == key = parseProblemAt pos ErrorC $ "You need a \\n or ; before '"++ key ++ "' to make it special" + let f (T_Literal id str) | str == key = parseProblemAt pos ErrorC $ "You need a \\n or ; before '"++ key ++ "' to make it special." f t = return () mapM (doAnalysis f) stuff fail "lol" @@ -875,7 +875,7 @@ readIfPart = do pos <- getPosition condition <- readTerm g_Then <|> (checkIfNotSpecial pos "then" condition) - acceptButWarn g_Semi ErrorC "No semicolons directly after 'then'" + acceptButWarn g_Semi ErrorC "No semicolons directly after 'then'." allspacing action <- readTerm return (condition, action) @@ -886,14 +886,14 @@ readElifPart = do allspacing condition <- readTerm g_Then <|> (checkIfNotSpecial pos "then" condition) - acceptButWarn g_Semi ErrorC "No semicolons directly after 'then'" + acceptButWarn g_Semi ErrorC "No semicolons directly after 'then'." allspacing action <- readTerm return (condition, action) readElsePart = do g_Else - acceptButWarn g_Semi ErrorC "No semicolons directly after 'else'" + acceptButWarn g_Semi ErrorC "No semicolons directly after 'else'." allspacing readTerm @@ -946,12 +946,12 @@ readDoGroup = do disregard g_Done <|> (do eof case hasFinal "done" commands of - Nothing -> parseProblemAt pos ErrorC "Couldn't find a 'done' for this 'do'" - Just (id) -> addNoteFor id $ Note ErrorC "Put a ; or \\n before the done" + Nothing -> parseProblemAt pos ErrorC "Couldn't find a 'done' for this 'do'." + Just (id) -> addNoteFor id $ Note ErrorC "Put a ; or \\n before the done." ) return commands <|> do - parseProblemAt pos ErrorC "Can't find the 'done' for this 'do'" + parseProblemAt pos ErrorC "Can't find the 'done' for this 'do'." fail "No done" hasFinal s [] = Nothing @@ -979,7 +979,7 @@ readForClause = do group <- readDoGroup <|> ( allspacing >> eof >> - parseProblem ErrorC "Missing 'do'" >> + parseProblem ErrorC "Missing 'do'." >> return []) return $ T_ForIn id name values group @@ -990,7 +990,7 @@ readInClause = do do { lookAhead (g_Do); - parseNote ErrorC "You need a line feed or semicolon before the 'do'"; + parseNote ErrorC "You need a line feed or semicolon before the 'do'."; } <|> do { optional $ g_Semi; disregard allspacing; @@ -1030,7 +1030,7 @@ readFunctionDefinition = do id <- getNextId name <- try readFunctionSignature allspacing - (disregard (lookAhead g_Lbrace) <|> parseProblem ErrorC "Expected a { to open the function definition") + (disregard (lookAhead g_Lbrace) <|> parseProblem ErrorC "Expected a { to open the function definition.") group <- readBraceGroup return $ T_Function id name group @@ -1068,7 +1068,7 @@ prop_readAssignmentWord5 = isOk readAssignmentWord "b+=lol" prop_readAssignmentWord6 = isWarning readAssignmentWord "b += (1 2 3)" readAssignmentWord = try $ do id <- getNextId - optional (char '$' >> parseNote ErrorC "Don't use $ on the left side of assignments") + optional (char '$' >> parseNote ErrorC "Don't use $ on the left side of assignments.") variable <- readVariableName space <- spacing pos <- getPosition @@ -1076,7 +1076,7 @@ readAssignmentWord = try $ do space2 <- spacing value <- readArray <|> readNormalWord spacing - when (space ++ space2 /= "") $ parseNoteAt pos ErrorC "Don't put spaces around the = in assignments" + when (space ++ space2 /= "") $ parseNoteAt pos ErrorC "Don't put spaces around the = in assignments." return $ T_Assignment id variable value readArray = do @@ -1156,7 +1156,7 @@ readScript = do eof <|> (parseProblem ErrorC "Parsing stopped here because of parsing errors."); return $ T_Script id commands; } <|> do { - parseProblem WarningC "Couldn't read any commands"; + parseProblem WarningC "Couldn't read any commands."; return $ T_Script id $ [T_EOF id]; }