Commit f6046c2e authored by Oleg Grenrus's avatar Oleg Grenrus
Browse files

cabal check flag names

parent 2e05ad31
......@@ -55,6 +55,7 @@ import Distribution.Simple.Utils hiding (findPackageDesc, notice)
import Distribution.Version
import Distribution.Package
import Distribution.Text
import Distribution.Utils.Generic (isAscii)
import Language.Haskell.Extension
import Control.Monad (mapM)
......@@ -146,6 +147,7 @@ checkPackage gpkg mpkg =
++ checkConditionals gpkg
++ checkPackageVersions gpkg
++ checkDevelopmentOnlyFlags gpkg
++ checkFlagNames gpkg
where
pkg = fromMaybe (flattenPackageDescription gpkg) mpkg
......@@ -1584,6 +1586,27 @@ checkConditionals pkg =
COr c1 c2 -> condfv c1 ++ condfv c2
CAnd c1 c2 -> condfv c1 ++ condfv c2
checkFlagNames ::GenericPackageDescription -> [PackageCheck]
checkFlagNames gpd
| null invalidFlagNames = []
| otherwise = [ PackageDistInexcusable
$ "Suspicious flag names: " ++ unwords invalidFlagNames ++ ". "
++ "To avoid ambiguity in command line interfaces, flag shouldn't "
++ "start with a dash. Also for better compatibility, flag names "
++ "shouldn't contain non-ascii characters."
]
where
invalidFlagNames =
[ fn
| flag <- genPackageFlags gpd
, let fn = unFlagName (flagName flag)
, invalidFlagName fn
]
-- starts with dash
invalidFlagName ('-':_) = True
-- mon ascii letter
invalidFlagName cs = any (not . isAscii) cs
checkDevelopmentOnlyFlagsBuildInfo :: BuildInfo -> [PackageCheck]
checkDevelopmentOnlyFlagsBuildInfo bi =
catMaybes [
......
......@@ -54,6 +54,9 @@ module Distribution.Utils.Generic (
isInfixOf,
intercalate,
lowercase,
isAscii,
isAsciiAlpha,
isAsciiAlphaNum,
listUnion,
listUnionRight,
ordNub,
......@@ -307,6 +310,18 @@ equating p x y = p x == p y
lowercase :: String -> String
lowercase = map toLower
isAscii :: Char -> Bool
isAscii c = fromEnum c < 0x80
-- | Ascii letters.
isAsciiAlpha :: Char -> Bool
isAsciiAlpha c = ('a' <= c && c <= 'z')
|| ('A' <= c && c <= 'Z')
-- | Ascii letters and digits.
isAsciiAlphaNum :: Char -> Bool
isAsciiAlphaNum c = isAscii c || isDigit c
unintersperse :: Char -> String -> [String]
unintersperse mark = unfoldr unintersperse1 where
unintersperse1 str
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment