Skip to content

Warn if -- token is found. Don't warn if it's "--". #4973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cabal/Cabal.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ extra-source-files:
tests/ParserTests/warnings/bom.cabal
tests/ParserTests/warnings/bool.cabal
tests/ParserTests/warnings/deprecatedfield.cabal
tests/ParserTests/warnings/doubledash.cabal
tests/ParserTests/warnings/extratestmodule.cabal
tests/ParserTests/warnings/gluedop.cabal
tests/ParserTests/warnings/nbsp.cabal
Expand Down
14 changes: 12 additions & 2 deletions Cabal/Distribution/Parsec/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,21 @@ instance Parsec Bool where

-- | @[^ ,]@
parsecToken :: CabalParsing m => m String
parsecToken = parsecHaskellString <|> (P.munch1 (\x -> not (isSpace x) && x /= ',') P.<?> "identifier" )
parsecToken = parsecHaskellString <|> ((P.munch1 (\x -> not (isSpace x) && x /= ',') P.<?> "identifier" ) >>= checkNotDoubleDash)

-- | @[^ ]@
parsecToken' :: CabalParsing m => m String
parsecToken' = parsecHaskellString <|> (P.munch1 (not . isSpace) P.<?> "token")
parsecToken' = parsecHaskellString <|> ((P.munch1 (not . isSpace) P.<?> "token") >>= checkNotDoubleDash)

checkNotDoubleDash :: CabalParsing m => String -> m String
checkNotDoubleDash s = do
when (s == "--") $ parsecWarning PWTDoubleDash $ unwords
[ "Double-dash token found."
, "Note: there are no end-of-line comments in .cabal files, only whole line comments."
, "Use \"--\" (quoted double dash) to silence this warning, if you actually want -- token"
]

return s

parsecFilePath :: CabalParsing m => m FilePath
parsecFilePath = parsecToken
Expand Down
1 change: 1 addition & 0 deletions Cabal/Distribution/Parsec/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ data PWarnType
| PWTLexNBSP
| PWTLexBOM
| PWTQuirkyCabalFile -- ^ legacy cabal file that we know how to patch
| PWTDoubleDash -- ^ Double dash token, most likely it's a mistake - it's not a comment
deriving (Eq, Ord, Show, Enum, Bounded)

-- | Parser warning.
Expand Down
1 change: 1 addition & 0 deletions Cabal/tests/ParserTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ warningTests = testGroup "warnings triggered"
, warningTest PWTUnknownField "unknownfield.cabal"
, warningTest PWTUnknownSection "unknownsection.cabal"
, warningTest PWTTrailingFields "trailingfield.cabal"
, warningTest PWTDoubleDash "doubledash.cabal"
-- TODO: not implemented yet
-- , warningTest PWTExtraTestModule "extratestmodule.cabal"
]
Expand Down
5 changes: 5 additions & 0 deletions Cabal/tests/ParserTests/regressions/encoding-0.8.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Name: encoding
Version: 0.8
cabal-version: >=1.12
-- double-dash files
extra-source-files:
-- this is comment
README.md "--"
"--"

custom-setup
setup-depends:
Expand Down
4 changes: 4 additions & 0 deletions Cabal/tests/ParserTests/regressions/encoding-0.8.format
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: encoding
version: 0.8
cabal-version: >=1.12
extra-source-files:
README.md
"--"
"--"

custom-setup
setup-depends: base <5,
Expand Down
9 changes: 9 additions & 0 deletions Cabal/tests/ParserTests/warnings/doubledash.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: bool
version: 1
cabal-version: >= 1.6
extra-source-files:
README.md -- we include it

library
build-depends: base >= 4.9 && <4.10
hs-source-dirs: .