Skip to content

Commit 5722018

Browse files
committed
Fix hlint and ormolu problems
1 parent 675f5e8 commit 5722018

File tree

3 files changed

+158
-140
lines changed

3 files changed

+158
-140
lines changed

.github/workflows/hlint.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ on:
77
- 'message-index/helper-tool.hs'
88
branches:
99
- main
10+
<<<<<<< HEAD
11+
=======
12+
pull_request:
13+
paths:
14+
- '**/site.hs'
15+
- '**/helper-tool.hs'
16+
types:
17+
- opened
18+
- synchronize
19+
- reopened
20+
>>>>>>> cafdc4c (Fix hlint and ormolu problems)
1021

1122
jobs:
1223
hlint:

.github/workflows/ormolu.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
paths:
66
- '**/site.hs'
7+
- '**/helper-tool.hs'
78
branches:
89
- main
910
pull_request:

message-index/helper-tool.hs

Lines changed: 146 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
module Main where
22

3-
import Control.Monad (forM_, forM)
4-
import Data.Char (toLower, isSpace)
5-
import Text.Read (readMaybe)
3+
import Control.Monad (forM, forM_)
4+
import Data.Char (isSpace, toLower)
65
import System.Directory (createDirectory)
76
import System.FilePath ((</>))
7+
import Text.Read (readMaybe)
88

99
-------------------------------------------------------------------------------
1010
-- Querying the user about the diagnostic
@@ -19,100 +19,99 @@ normalize = fmap toLower . strip
1919

2020
-- Querying for the system: GHC / GHCup / Stack
2121

22-
data System = GHC | GHCup | Stack deriving Show
22+
data System = GHC | GHCup | Stack deriving (Show)
2323

2424
readSystem :: IO System
2525
readSystem = do
26-
putStrLn "For which system do you want to generate a message?"
27-
putStrLn " 1) GHC"
28-
putStrLn " 2) GHCup"
29-
putStrLn " 3) Stack"
30-
putStr "Input (Default = GHC): "
31-
ln <- getLine
32-
case normalize ln of
33-
"1" -> pure GHC
34-
"ghc" -> pure GHC
35-
"2" -> pure GHCup
36-
"ghcup" -> pure GHCup
37-
"3" -> pure Stack
38-
"stack" -> pure Stack
39-
_ -> pure GHC
26+
putStrLn "For which system do you want to generate a message?"
27+
putStrLn " 1) GHC"
28+
putStrLn " 2) GHCup"
29+
putStrLn " 3) Stack"
30+
putStr "Input (Default = GHC): "
31+
ln <- getLine
32+
case normalize ln of
33+
"1" -> pure GHC
34+
"ghc" -> pure GHC
35+
"2" -> pure GHCup
36+
"ghcup" -> pure GHCup
37+
"3" -> pure Stack
38+
"stack" -> pure Stack
39+
_ -> pure GHC
4040

4141
-- Querying for the error code
4242

43-
-- | We need to encode the error code as a string in order
43+
-- | We need to encode the error code as a string in order
4444
-- to preserve leading 0's.
4545
type ErrorCode = String
4646

4747
readCode :: IO ErrorCode
4848
readCode = do
49-
putStrLn "What is the numeric code that you want to document."
50-
putStrLn "For example, enter \"01234\" if you want to document GHC-01234."
51-
putStr "Input: "
52-
ln <- getLine
53-
case (readMaybe ln) :: Maybe Int of
54-
Nothing -> do
55-
putStrLn "Could not parse the input as an integer. Only enter the numeric part of the error."
56-
readCode
57-
Just _ -> pure ln
49+
putStrLn "What is the numeric code that you want to document."
50+
putStrLn "For example, enter \"01234\" if you want to document GHC-01234."
51+
putStr "Input: "
52+
ln <- getLine
53+
case readMaybe ln :: Maybe Int of
54+
Nothing -> do
55+
putStrLn "Could not parse the input as an integer. Only enter the numeric part of the error."
56+
readCode
57+
Just _ -> pure ln
5858

5959
-- Title
6060
type Title = String
6161

6262
readTitle :: IO Title
6363
readTitle = do
64-
putStrLn "What is the title of the error message."
65-
putStr "Input: "
66-
getLine
64+
putStrLn "What is the title of the error message."
65+
putStr "Input: "
66+
getLine
6767

6868
-- Summary
6969
type Summary = String
7070

7171
readSummary :: IO Summary
7272
readSummary = do
73-
putStrLn "Give a short summary of the error message."
74-
putStr "Input: "
75-
getLine
73+
putStrLn "Give a short summary of the error message."
74+
putStr "Input: "
75+
getLine
7676

7777
-- Severity
78-
data Severity = Error | Warning deriving Show
78+
data Severity = Error | Warning deriving (Show)
7979

8080
readSeverity :: IO Severity
8181
readSeverity = do
82-
putStrLn "What is the severity of the diagnostic."
83-
putStrLn " 1) Error"
84-
putStrLn " 2) Warning"
85-
putStr "Input (Default = Error): "
86-
ln <- getLine
87-
case normalize ln of
88-
"1" -> pure Error
89-
"error" -> pure Error
90-
"2" -> pure Warning
91-
"warning" -> pure Warning
92-
_ -> pure Error
82+
putStrLn "What is the severity of the diagnostic."
83+
putStrLn " 1) Error"
84+
putStrLn " 2) Warning"
85+
putStr "Input (Default = Error): "
86+
ln <- getLine
87+
case normalize ln of
88+
"1" -> pure Error
89+
"error" -> pure Error
90+
"2" -> pure Warning
91+
"warning" -> pure Warning
92+
_ -> pure Error
9393

9494
-- Warning flag
9595
type WarningFlag = String
9696

9797
-- | Only ask for a warning flag if Severity = Warning.
9898
readWarningFlag :: Severity -> IO (Maybe WarningFlag)
9999
readWarningFlag Warning = do
100-
putStrLn "What is the warning flag which enables this warning."
101-
putStrLn "For example, enter \"-Wtabs\" if you are documenting GHC's warning about tabs in your source file."
102-
putStr "Input: "
103-
ln <- getLine
104-
pure (Just ln)
100+
putStrLn "What is the warning flag which enables this warning."
101+
putStrLn "For example, enter \"-Wtabs\" if you are documenting GHC's warning about tabs in your source file."
102+
putStr "Input: "
103+
Just <$> getLine
105104
readWarningFlag _ = pure Nothing
106105

107106
-- Version
108107
type Version = String
109108

110109
readVersion :: IO Version
111110
readVersion = do
112-
putStrLn "Which version of the tool emitted the numeric code (not the message) for the first time?"
113-
putStrLn "Note: For GHC this is most likely 9.6.1."
114-
putStr "Input: "
115-
getLine
111+
putStrLn "Which version of the tool emitted the numeric code (not the message) for the first time?"
112+
putStrLn "Note: For GHC this is most likely 9.6.1."
113+
putStr "Input: "
114+
getLine
116115

117116
-- Examples
118117
type Examples = [String]
@@ -124,111 +123,118 @@ validateExampleName str = not (any isSpace str)
124123
-- | Only ask for examples if the system is GHC.
125124
readExamples :: System -> IO Examples
126125
readExamples GHC = do
127-
putStrLn "How many examples should be generated?"
128-
putStr "Input: "
129-
ln <- getLine
130-
case (readMaybe ln) :: Maybe Int of
131-
Nothing -> pure []
132-
(Just n) -> forM [1..n] readExample
126+
putStrLn "How many examples should be generated?"
127+
putStr "Input: "
128+
ln <- getLine
129+
case readMaybe ln :: Maybe Int of
130+
Nothing -> pure []
131+
(Just n) -> forM [1 .. n] readExample
133132
readExamples _ = pure []
134133

135134
readExample :: Int -> IO String
136135
readExample i = do
137-
putStrLn ("Give a name for example " <> show i)
138-
putStr "Input: "
139-
ln <- getLine
140-
if validateExampleName ln then pure ln else readExample i
136+
putStrLn ("Give a name for example " <> show i)
137+
putStr "Input: "
138+
ln <- getLine
139+
if validateExampleName ln then pure ln else readExample i
141140

142141
-- Template
143-
data Template =
144-
MkTemplate { system :: System
145-
, code :: ErrorCode
146-
, title :: Title
147-
, summary :: Summary
148-
, severity :: Severity
149-
, warningflag :: Maybe WarningFlag
150-
, introduced :: Version
151-
, examples :: Examples
152-
} deriving Show
153-
142+
data Template = MkTemplate
143+
{ system :: System,
144+
code :: ErrorCode,
145+
title :: Title,
146+
summary :: Summary,
147+
severity :: Severity,
148+
warningflag :: Maybe WarningFlag,
149+
introduced :: Version,
150+
examples :: Examples
151+
}
152+
deriving (Show)
154153

155154
readTemplate :: IO Template
156155
readTemplate = do
157-
putStrLn "This tool helps you create the scaffolding for a new error message on the error-message-index."
158-
putStrLn "You can leave any of the text fields blank and fill them in by hand later."
159-
putStrLn ""
160-
sys <- readSystem
161-
putStrLn ""
162-
code <- readCode
163-
putStrLn ""
164-
title <- readTitle
165-
putStrLn ""
166-
summary <- readSummary
167-
putStrLn ""
168-
severity <- readSeverity
169-
putStrLn ""
170-
warningflag <- readWarningFlag severity
171-
putStrLn ""
172-
version <- readVersion
173-
putStrLn ""
174-
examples <- readExamples sys
175-
pure (MkTemplate sys code title summary severity warningflag version examples)
156+
putStrLn "This tool helps you create the scaffolding for a new error message on the error-message-index."
157+
putStrLn "You can leave any of the text fields blank and fill them in by hand later."
158+
putStrLn ""
159+
sys <- readSystem
160+
putStrLn ""
161+
code <- readCode
162+
putStrLn ""
163+
title <- readTitle
164+
putStrLn ""
165+
summary <- readSummary
166+
putStrLn ""
167+
severity <- readSeverity
168+
putStrLn ""
169+
warningflag <- readWarningFlag severity
170+
putStrLn ""
171+
version <- readVersion
172+
putStrLn ""
173+
examples <- readExamples sys
174+
pure (MkTemplate sys code title summary severity warningflag version examples)
176175

177176
-------------------------------------------------------------------------------
178177
-- Creating the files and directories from the template
179178
-------------------------------------------------------------------------------
180179

181180
createFiles :: Template -> IO ()
182181
createFiles tmpl = do
183-
putStrLn "Creating scaffolding for the following configuration:"
184-
print tmpl
185-
putStrLn ""
186-
187-
-- Create the new directory "messages/XXX-NNNNNN/" and "messages/XXX-NNNNNN/index.md"
188-
let message_dir = "messages" </> case system tmpl of { GHC -> "GHC-"; GHCup -> "GHCup-"; Stack -> "S-" } ++ code tmpl
189-
createDirectory message_dir
190-
let toplvl_index = unlines [ "---"
191-
, "title: " <> title tmpl
192-
, "summary: " <> summary tmpl
193-
, "severity: " <> case severity tmpl of { Warning -> "warning"; Error -> "error" }
194-
, "introduced: " <> introduced tmpl
195-
, "---"
196-
, ""
197-
, "Insert your error message here."
198-
]
199-
writeFile (message_dir </> "index.md") toplvl_index
200-
201-
-- Create the example directories and entries:
202-
-- - "messages/XXX-NNNNNN/" and "messages/XXX-NNNNNN/index.md"
203-
-- - "messages/XXX-NNNNNN/before/" and "messages/XXX-NNNNNN/before/Module.hs"
204-
-- - "messages/XXX-NNNNNN/after/" and "messages/XXX-NNNNNN/after/Module.hs"
205-
forM_ (examples tmpl) $ \example -> do
206-
let example_dir = message_dir </> example
207-
createDirectory example_dir
208-
createDirectory (example_dir </> "before")
209-
createDirectory (example_dir </> "after")
210-
let example_index = unlines [ "---"
211-
, "title: <insert a title for this example here>"
212-
, "---"
213-
]
214-
writeFile (example_dir </> "index.md") example_index
215-
let before_module = unlines [ "module Example where"
216-
, ""
217-
, "-- Insert the example containing a bug here."
218-
]
219-
writeFile (example_dir </> "before" </> "Example.hs") before_module
220-
let after_module = unlines [ "module Example where"
221-
, ""
222-
, "-- Insert the fixed example here."
223-
]
224-
writeFile (example_dir </> "after" </> "Example.hs") after_module
225-
182+
putStrLn "Creating scaffolding for the following configuration:"
183+
print tmpl
184+
putStrLn ""
185+
186+
-- Create the new directory "messages/XXX-NNNNNN/" and "messages/XXX-NNNNNN/index.md"
187+
let message_dir = "messages" </> case system tmpl of { GHC -> "GHC-"; GHCup -> "GHCup-"; Stack -> "S-" } ++ code tmpl
188+
createDirectory message_dir
189+
let toplvl_index =
190+
unlines
191+
[ "---",
192+
"title: " <> title tmpl,
193+
"summary: " <> summary tmpl,
194+
"severity: " <> case severity tmpl of Warning -> "warning"; Error -> "error",
195+
"introduced: " <> introduced tmpl,
196+
"---",
197+
"",
198+
"Insert your error message here."
199+
]
200+
writeFile (message_dir </> "index.md") toplvl_index
201+
202+
-- Create the example directories and entries:
203+
-- - "messages/XXX-NNNNNN/" and "messages/XXX-NNNNNN/index.md"
204+
-- - "messages/XXX-NNNNNN/before/" and "messages/XXX-NNNNNN/before/Module.hs"
205+
-- - "messages/XXX-NNNNNN/after/" and "messages/XXX-NNNNNN/after/Module.hs"
206+
forM_ (examples tmpl) $ \example -> do
207+
let example_dir = message_dir </> example
208+
createDirectory example_dir
209+
createDirectory (example_dir </> "before")
210+
createDirectory (example_dir </> "after")
211+
let example_index =
212+
unlines
213+
[ "---",
214+
"title: <insert a title for this example here>",
215+
"---"
216+
]
217+
writeFile (example_dir </> "index.md") example_index
218+
let before_module =
219+
unlines
220+
[ "module Example where",
221+
"",
222+
"-- Insert the example containing a bug here."
223+
]
224+
writeFile (example_dir </> "before" </> "Example.hs") before_module
225+
let after_module =
226+
unlines
227+
[ "module Example where",
228+
"",
229+
"-- Insert the fixed example here."
230+
]
231+
writeFile (example_dir </> "after" </> "Example.hs") after_module
226232

227233
-------------------------------------------------------------------------------
228234
-- Main
229235
-------------------------------------------------------------------------------
230236

231237
main :: IO ()
232238
main = do
233-
tmpl <- readTemplate
234-
createFiles tmpl
239+
tmpl <- readTemplate
240+
createFiles tmpl

0 commit comments

Comments
 (0)