Tweaked some messages and added more badcases

This commit is contained in:
Vidar Holen 2012-11-04 21:44:48 -08:00
parent 279e972b61
commit 67d27ea42d
22 changed files with 60 additions and 16 deletions

View File

@ -1,7 +1,7 @@
all: .tests shpell
true
shpell:
shpell: regardless
ghc --make shpell #GHC handles the dependencies
.tests: *.hs */*.hs
@ -9,3 +9,7 @@ shpell:
clean:
rm -f .tests shpell *.hi *.o Shpell/*.hi Shpell/*.o
regardless:
:

View File

@ -67,7 +67,7 @@ checkBasic f s = case parseShell "-" s of
prop_checkUuoc = verify checkUuoc "cat foo | grep bar"
checkUuoc (T_Pipeline _ (T_Redirecting _ _ f@(T_SimpleCommand id _ _):_:_)) =
case deadSimple f of ["cat", _] -> addNoteFor id $ Note InfoC "UUOC: 'cat foo | bar | baz' is better written as 'bar < foo | baz'"
case deadSimple f of ["cat", _] -> addNoteFor id $ Note StyleC "Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead."
_ -> return ()
checkUuoc _ = return ()

View File

@ -318,12 +318,13 @@ readSingleQuoted = do
id <- getNextId
singleQuote
s <- readSingleQuotedPart `reluctantlyTill` singleQuote
pos <- getPosition
singleQuote <?> "End single quoted string"
let string = concat s
return (T_SingleQuoted id string) `attempting` do
x <- lookAhead anyChar
when (isAlpha x && isAlpha (last string)) $ parseProblem WarningC "This apostrophe terminated the single quoted string."
when (isAlpha x && isAlpha (last string)) $ parseProblemAt pos WarningC "This apostrophe terminated the single quoted string!"
readSingleQuotedLiteral = do
singleQuote
@ -338,7 +339,7 @@ readSingleQuotedPart =
prop_readBackTicked = isWarning readBackTicked "`ls *.mp3`"
readBackTicked = do
id <- getNextId
parseNote StyleC "Ignoring deprecated `..` backtick expansion. Use $(..) instead."
parseNote InfoC "Ignoring deprecated `..` backtick expansion. Use $(..) instead."
pos <- getPosition
char '`'
f <- readGenericLiteral (char '`')
@ -381,15 +382,15 @@ readNormalLiteralPart = do
readNormalEscaped <|> (anyChar `reluctantlyTill1` quotable)
readNormalEscaped = do
backslash
pos <- getPosition
backslash
do
next <- (quotable <|> oneOf "?*[]")
return $ if next == '\n' then "" else [next]
<|>
do
next <- anyChar <?> "No character after \\"
parseNoteAt pos WarningC $ "This character doesn't need escaping here, the \\ is ignored"
parseNoteAt pos WarningC $ "Did you mean \"$(printf \"\\" ++ [next] ++ "\")\"? The shell just ignores the \\ here."
return [next]
readSingleEscaped = do
@ -502,8 +503,7 @@ readDollarVariable = do
name <- readVariableName
return $ T_DollarVariable id (name)
char '$'
positional <|> special <|> regular
try $ char '$' >> (positional <|> special <|> regular)
readVariableName = do
f <- variableStart
@ -512,7 +512,7 @@ readVariableName = do
readDollarLonely = do
id <- getNextId
parseNote ErrorC "$ is not used specially and should therefore be escaped"
parseNote StyleC "$ is not used specially and should therefore be escaped"
char '$'
return $ T_Literal id "$"
@ -543,15 +543,15 @@ readHereDoc = do
`attempting` (eof >> debugHereDoc tokenPosition endToken hereInfo)
verifyHereDoc dashed quoted spacing hereInfo = do
when (not dashed && spacing /= "") $ parseNote ErrorC "When using << instead of <<-, the end tokens can't be indented"
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 (endToken ++ " was part of the here document, 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 (endToken ++ " appears in the here document, but with different case")
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 ")
@ -797,7 +797,7 @@ readInClause = do
do {
lookAhead (g_Do);
parseNote ErrorC "You need a line feed or semicolon before the 'do' (in Bash)";
parseNote ErrorC "You need a line feed or semicolon before the 'do'";
} <|> do {
optional $ g_Semi;
disregard allspacing;
@ -843,7 +843,7 @@ readFunctionDefinition = do
readFunctionSignature = do
acceptButWarn (string "function" >> linewhitespace >> spacing) StyleC "Drop the keyword 'function'. It's optional in Bash but illegal in others."
acceptButWarn (string "function" >> linewhitespace >> spacing) InfoC "Drop the keyword 'function'. It's optional in Bash but invalid in other shells."
name <- readVariableName
spacing
g_Lparen

1
badcase/ampersemi Normal file
View File

@ -0,0 +1 @@
wget url &; echo "It's backgrounded."

1
badcase/apostrophecked Normal file
View File

@ -0,0 +1 @@
echo 'Shpell... It's the best!'

3
badcase/badKnR Normal file
View File

@ -0,0 +1,3 @@
for f in * do
echo "$f"
done

1
badcase/badescape Normal file
View File

@ -0,0 +1 @@
echo hello\nword

7
badcase/badindenting Normal file
View File

@ -0,0 +1,7 @@
# Caution, white space sensitive file!
if true
then
cat <<- FOO
Some text
FOO
fi

3
badcase/heredoccasefault Normal file
View File

@ -0,0 +1,3 @@
cat << EOF
Hello world
Eof

2
badcase/heredoclinefault Normal file
View File

@ -0,0 +1,2 @@
cat << EOF
Hello world EOF

View File

@ -1 +1 @@
cat compile.sh |tr -d '\r' > compile.sh
sed 's/foo/bar/g' myfile > myfile

1
badcase/largepositionals Normal file
View File

@ -0,0 +1 @@
ls ... "9" "$10" # DOS 4ever

1
badcase/lolbackticks Normal file
View File

@ -0,0 +1 @@
echo `ls`

1
badcase/lonelydollar Normal file
View File

@ -0,0 +1 @@
echo "$ is special now?"

4
badcase/mvmp3s Normal file
View File

@ -0,0 +1,4 @@
for f in *.mp3
do
mv $f /music
done

5
badcase/mvmp3sfixed Normal file
View File

@ -0,0 +1,5 @@
# There, I fixed it!
for f in "$(ls *.mp3)"
do
mv "$f" /music
done

View File

@ -0,0 +1 @@
echo 'Shpell... It\'s the best!'

View File

@ -0,0 +1 @@
function foo() { echo bar; }

View File

@ -0,0 +1 @@
echo Your locales: $(locale)

1
badcase/uuoc Normal file
View File

@ -0,0 +1 @@
cat foo | grep bar

6
badcase/worseindenting Normal file
View File

@ -0,0 +1,6 @@
if true
then
cat << FOO
Some text
FOO
fi

View File

@ -14,7 +14,7 @@ ansi n = "\x1B[" ++ (show n) ++ "m"
colorForLevel "error" = 31 -- red
colorForLevel "warning" = 33 -- yellow
colorForLevel "info" = 33 -- yellow
colorForLevel "style" = 31 -- green
colorForLevel "style" = 32 -- green
colorForLevel "message" = 1 -- bold
colorForLevel "source" = 0 -- none
colorForLevel _ = 0 -- none