Skip to content
This repository was archived by the owner on Feb 5, 2023. It is now read-only.

Commit 9e6e401

Browse files
committed
Add info, help and --all-errors flag
1 parent 4d2de14 commit 9e6e401

File tree

4 files changed

+115
-21
lines changed

4 files changed

+115
-21
lines changed

.editorconfig

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[*.hs]
2+
indent_size = 4

bin/Main.hs

+57-21
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,54 @@ import Flow
66
import Proofread
77
import Protolude hiding (state)
88
import System.Console.Pretty
9-
import System.Environment (getArgs)
9+
import System.Console.CmdArgs
1010

1111
import qualified Data.List as List
1212
import qualified Data.Text as Text
1313

1414

15+
-- 🌳
16+
17+
18+
data Flags = Flags
19+
{ filePath :: Maybe [Char]
20+
, showAllErrors :: Bool
21+
}
22+
deriving (Data, Show, Typeable)
23+
24+
25+
flagsConfig = Flags
26+
{ filePath = Nothing &= args &= typFile
27+
28+
--
29+
, showAllErrors = False
30+
&= name "all-errors"
31+
&= explicit
32+
&= help "Show all errors instead of one"
33+
}
34+
35+
-- Summary
36+
----------
37+
&= summary "\nProofread your Elm files.\n\
38+
\See https://github.com/icidasset/elm-proofread for examples."
39+
40+
-- Program
41+
----------
42+
&= program "elm-proofread"
43+
44+
45+
1546
-- 🍯
1647

1748

1849
main :: IO ()
1950
main = do
20-
args <- getArgs
21-
22-
-- Fun w/ flags
23-
let maybeFilePath = listToMaybe (excludeFlags args)
51+
flags <- cmdArgs flagsConfig
2452

25-
-- Format!
26-
case maybeFilePath of
27-
Just filePath -> processFile filePath
28-
Nothing -> processStdin
53+
-- Proofread!
54+
case filePath flags of
55+
Just filePath -> processFile filePath flags
56+
Nothing -> processStdin flags
2957

3058

3159

@@ -34,50 +62,58 @@ main = do
3462

3563
{-| Proofread a single file.
3664
-}
37-
processFile :: [Char] -> IO ()
38-
processFile filePath = do
65+
processFile :: [Char] -> Flags -> IO ()
66+
processFile filePath flags = do
3967
putStrLn (Text.concat [ "Proofreading ", Text.pack filePath ])
4068

4169
contents <- readFile filePath
4270
result <- Proofread.proofread contents
4371

44-
handleResult result
72+
handleResult result flags
4573

4674

4775
{-| Proofread stdin.
4876
-}
49-
processStdin :: IO ()
50-
processStdin = do
77+
processStdin :: Flags -> IO ()
78+
processStdin flags = do
5179
putStrLn ("Proofreading stdin" :: Text)
5280

5381
contents <- getContents
5482
result <- Proofread.proofread contents
5583

56-
handleResult result
84+
handleResult result flags
5785

5886

5987

6088
-- 📮 ~ Generic
6189

6290

63-
handleResult :: Result Document Text -> IO ()
64-
handleResult (Err err) = putErrorLn err >> exitFailure
65-
handleResult (Ok (Document _ tests)) = do
91+
handleResult :: Result Document Text -> Flags -> IO ()
92+
handleResult (Err err) _ = putErrorLn err >> exitFailure
93+
handleResult (Ok (Document _ tests)) flags = do
6694
_ <- tests
6795
|> map renderTest
6896
|> sequence
6997

70-
-- Render first error, hide others
98+
-- Render first error, hide others (unless all-errors flag is provided)
7199
-- Does nothing if no errors are present
72100
_ <- tests
73-
|> List.find
101+
|> List.filter
74102
(\t ->
75103
case state t of
76104
Error _ -> True
77105
Unequal _ -> True
78106
_ -> False
79107
)
80-
|> maybe (return ()) renderTestError
108+
|> (
109+
if showAllErrors flags then
110+
identity
111+
112+
else
113+
List.take 1
114+
)
115+
|> map renderTestError
116+
|> sequence
81117

82118
-- Did all tests pass?
83119
let passedTests = filter (state .> (==) Equal) tests

package.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ category: Development
99

1010

1111
default-extensions:
12+
DeriveDataTypeable
1213
DisambiguateRecordFields
1314
DuplicateRecordFields
1415
NamedFieldPuns
@@ -24,10 +25,12 @@ ghc-options:
2425
-Wincomplete-record-updates
2526
-Wincomplete-uni-patterns
2627
-Wredundant-constraints
28+
-fno-cse
2729

2830

2931
dependencies:
3032
- base >= 4.7 && < 5
33+
- cmdargs == 0.10.*
3134
- flow == 1.*
3235
- megaparsec == 6.5.*
3336
- parser-combinators == 1.*

tests/fixtures/Errors.elm

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
module Errors exposing (AdventureTime(..), add)
2+
3+
import Dict
4+
5+
6+
{-| Adventure time.
7+
8+
>>> import Dict
9+
10+
>>> testPrep =
11+
..> Dict.empty
12+
13+
>>> Finn
14+
Jake
15+
16+
>>> "428a2f98 71374491 b5c0fbcf e9b5dba5 3956c25b 59f111f1 923f82a4 ab1c5ed5
17+
..> d807aa98 12835b01 243185be 550c7dc3 72be5d74 80deb1fe 9bdc06a7 c19bf174
18+
..> e49b69c1 efbe4786 0fc19dc6 240ca1cc 2de92c6f 4a7484aa 5cb0a9dc 76f988da
19+
..> 983e5152 a831c66d b00327c8 bf597fc7 c6e00bf3 d5a79147 06ca6351 14292967
20+
..> 27b70a85 2e1b2138 4d2c6dfc 53380d13 650a7354 766a0abb 81c2c92e 92722c85
21+
..> a2bfe8a1 a81a664b c24b8b70 c76c51a3 d192e819 d6990624 f40e3585 106aa070
22+
..> 19a4c116 1e376c08 2748774c 34b0bcb5 391c0cb3 4ed8aa4a 5b9cca4f 682e6ff3
23+
..> 748f82ee 78a5636f 84c87814 8cc70208 90befffa a4506ceb bef9a3f7 c67178f2"
24+
"42"
25+
26+
-}
27+
type AdventureTime
28+
= Finn
29+
| Jake
30+
31+
32+
{-|
33+
34+
>>> add 1 2
35+
4
36+
37+
>>> import Tuple
38+
>>> nine =
39+
..> Tuple.first ( 9, True )
40+
41+
>>> 1.0
42+
..> |> round
43+
..> |> add nine
44+
add
45+
(round 5.0)
46+
6
47+
48+
Hello ✌️
49+
50+
-}
51+
add : number -> number -> number
52+
add x y =
53+
Debug.log "ignoreThis" (x + y)

0 commit comments

Comments
 (0)