33{-
44 Detect uses of capitalisms
55
6- Only allow up to two consecutive capital letters in identifiers.
6+ Only allow up to two consecutive capital letters in top level
7+ identifiers.
78
89 Identifiers containing underscores are exempted from thus rule.
910 Identifiers of FFI bindings are exempted from thus rule.
1011
12+ Locally bound identifiers and module names are not checked.
13+
1114<TEST>
12- module SSL.Foo -- ???
1315data LHsDecl
14- class FOO a where -- ???
15- class Foo a where getFOO -- ???
16- data Foo = Bar | BAAZ -- ???
17- data Foo = B_ar | BAAZ -- ???
16+ class FOO a where -- @Ignore
17+ class Foo a where getFOO :: Bool
18+ data Foo = Bar | BAAZ -- @Ignore
19+ data Foo = B_ar | BAAZ -- @Ignore
1820data Foo = Bar | B_AAZ
19- data OTPToken = OTPToken -- ???
21+ data OTPToken = OTPToken -- @Ignore
2022data OTP_Token = Foo
21- sendSMS = ... -- ???
22- runTLS = ... -- ???
23- runTLSSocket = ... -- ???
23+ sendSMS = _ -- @Ignore
24+ runTLS = _ -- @Ignore
25+ runTLSSocket = _ -- @Ignore
2426runTLS_Socket
25- newtype TLSSettings = ... -- ???
27+ newtype TLSSettings = TLSSettings -- @Ignore
2628tlsSettings
2729data CertSettings = CertSettings
2830tlsServerHooks
29- tlsServerDHEParams = ... -- ???
30- type WarpTLSException = () -- ???
31+ tlsServerDHEParams = _ -- @Ignore
32+ type WarpTLSException = () -- @Ignore
3133get_SMS
3234runCI
3335foreign import ccall _FIREMISSLES :: IO ()
34- let getSMS = x in foo --- ???
36+ getSMS :: IO () -- @Ignore
37+ gFOO = _ -- @Ignore
38+ geFOO = _ -- @Ignore
39+ getFOO = _ -- @Ignore
3540</TEST>
3641-}
3742
38-
3943module Hint.NoCapitalisms (noCapitalismsHint ) where
4044
41- import Hint.Type ( DeclHint , remark , Severity ( Ignore ))
42- import Data.List.Extra ( nubOrd )
43- import Data.List.NonEmpty ( toList )
45+ import Hint.Type
46+ import Data.List.Extra as E
47+ import Data.List.NonEmpty as NE
4448import Data.Char
4549import Data.Maybe
4650
@@ -71,29 +75,31 @@ hasCapitalism :: String -> Bool
7175hasCapitalism s = any isAllUpper (trigrams s)
7276 where
7377 isAllUpper = all isUpper
74- trigrams = \ case
75- a: b: c: as -> [a,b,c] : trigrams (c: as)
76- _otherwise -> []
78+
79+ trigrams :: String -> [String ]
80+ trigrams = \ case
81+ a: b: c: as -> [a,b,c] : trigrams (b: c: as)
82+ _otherwise -> []
7783
7884--- these are copied from Hint.Naming ---
7985
8086shorten :: LHsDecl GhcPs -> LHsDecl GhcPs
8187shorten (L locDecl (ValD ttg0 bind@ (FunBind _ _ matchGroup@ (MG FromSource (L locMatches matches))))) =
82- L locDecl (ValD ttg0 bind {fun_matches = matchGroup {mg_alts = L locMatches $ map shortenMatch matches}})
83- shorten (L locDecl (ValD ttg0 bind@ (PatBind _ _ grhss@ (GRHSs _ rhss _)))) =
84- L locDecl (ValD ttg0 bind {pat_rhs = grhss {grhssGRHSs = map shortenLGRHS rhss}})
88+ L locDecl (ValD ttg0 bind {fun_matches = matchGroup {mg_alts = L locMatches $ E. map shortenMatch matches}})
89+ shorten (L locDecl (ValD ttg0 bind@ (PatBind _ _ _ grhss@ (GRHSs _ rhss _)))) =
90+ L locDecl (ValD ttg0 bind {pat_rhs = grhss {grhssGRHSs = E. map shortenLGRHS rhss}})
8591shorten x = x
8692
8793shortenMatch :: LMatch GhcPs (LHsExpr GhcPs ) -> LMatch GhcPs (LHsExpr GhcPs )
8894shortenMatch (L locMatch match@ (Match _ _ _ grhss@ (GRHSs _ rhss _))) =
89- L locMatch match {m_grhss = grhss {grhssGRHSs = map shortenLGRHS rhss}}
95+ L locMatch match {m_grhss = grhss {grhssGRHSs = E. map shortenLGRHS rhss}}
9096
9197shortenLGRHS :: LGRHS GhcPs (LHsExpr GhcPs ) -> LGRHS GhcPs (LHsExpr GhcPs )
9298shortenLGRHS (L locGRHS (GRHS ttg0 guards (L locExpr _))) =
9399 L locGRHS (GRHS ttg0 guards (L locExpr dots))
94100 where
95101 dots :: HsExpr GhcPs
96- dots = HsLit EpAnnNotUsed (HsString (SourceText (fsLit " ..." )) (fsLit " ..." ))
102+ dots = HsLit noExtField (HsString (SourceText (fsLit " ..." )) (fsLit " ..." ))
97103
98104getNames :: LHsDecl GhcPs -> [String ]
99105getNames decl = maybeToList (declName decl) ++ getConstructorNames (unLoc decl)
@@ -105,9 +111,9 @@ getConstructorNames tycld = case tycld of
105111 _ -> []
106112 where
107113 conNames :: [LConDecl GhcPs ] -> [String ]
108- conNames = concatMap (map unsafePrettyPrint . conNamesInDecl . unLoc)
114+ conNames = concatMap (E. map unsafePrettyPrint . conNamesInDecl . unLoc)
109115
110116 conNamesInDecl :: ConDecl GhcPs -> [LIdP GhcPs ]
111117 conNamesInDecl ConDeclH98 {con_name = name} = [name]
112- conNamesInDecl ConDeclGADT {con_names = names} = Data.List.NonEmpty . toList names
118+ conNamesInDecl ConDeclGADT {con_names = names} = NE . toList names
113119
0 commit comments