Skip to content

Commit bd5cb3c

Browse files
cgohlabgohla
authored andcommitted
fix test cases, caveat descrition, a little refactor
1 parent dcce769 commit bd5cb3c

File tree

2 files changed

+37
-31
lines changed

2 files changed

+37
-31
lines changed

hints.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,12 +1189,12 @@ Does not support refactoring.
11891189
<td>
11901190
Example:
11911191
<code>
1192-
type WarpTLSException = ()
1192+
getFOO = _
11931193
</code>
11941194
<br>
11951195
Found:
11961196
<code>
1197-
type WarpTLSException = ()
1197+
getFOO = ...
11981198
</code>
11991199
<br>
12001200
Suggestion:
@@ -1204,7 +1204,7 @@ Suggestion:
12041204
<br>
12051205
Does not support refactoring.
12061206
</td>
1207-
<td>Suggestion</td>
1207+
<td>Ignore</td>
12081208
</tr>
12091209
</table>
12101210

src/Hint/NoCapitalisms.hs

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,48 @@
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 -- ???
1315
data 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
1820
data Foo = Bar | B_AAZ
19-
data OTPToken = OTPToken -- ???
21+
data OTPToken = OTPToken -- @Ignore
2022
data OTP_Token = Foo
21-
sendSMS = ... -- ???
22-
runTLS = ... -- ???
23-
runTLSSocket = ... -- ???
23+
sendSMS = _ -- @Ignore
24+
runTLS = _ -- @Ignore
25+
runTLSSocket = _ -- @Ignore
2426
runTLS_Socket
25-
newtype TLSSettings = ... -- ???
27+
newtype TLSSettings = TLSSettings -- @Ignore
2628
tlsSettings
2729
data CertSettings = CertSettings
2830
tlsServerHooks
29-
tlsServerDHEParams = ... -- ???
30-
type WarpTLSException = () -- ???
31+
tlsServerDHEParams = _ -- @Ignore
32+
type WarpTLSException = () -- @Ignore
3133
get_SMS
3234
runCI
3335
foreign 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-
3943
module 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
4448
import Data.Char
4549
import Data.Maybe
4650

@@ -71,29 +75,31 @@ hasCapitalism :: String -> Bool
7175
hasCapitalism 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

8086
shorten :: LHsDecl GhcPs -> LHsDecl GhcPs
8187
shorten (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}})
8591
shorten x = x
8692

8793
shortenMatch :: LMatch GhcPs (LHsExpr GhcPs) -> LMatch GhcPs (LHsExpr GhcPs)
8894
shortenMatch (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

9197
shortenLGRHS :: LGRHS GhcPs (LHsExpr GhcPs) -> LGRHS GhcPs (LHsExpr GhcPs)
9298
shortenLGRHS (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

98104
getNames :: LHsDecl GhcPs -> [String]
99105
getNames 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

Comments
 (0)