@@ -2,17 +2,24 @@
22{-# LANGUAGE OverloadedStrings #-}
33module Reporting.Error.Docs
44 ( Error(..)
5− , toReport
5+ , SyntaxProblem(..)
6+ , NameProblem(..)
7+ , DefProblem(..)
8+ , toReports
69 )
710 where
811
912
1013import qualified Data.Name as Name
14+import qualified Data.NonEmptyList as NE
1115
16+import Parse.Primitives (Row, Col)
17+import Parse.Symbol (BadOperator(..))
1218import qualified Reporting.Annotation as A
1319import Reporting.Doc ((<>))
1420import qualified Reporting.Doc as D
1521import qualified Reporting.Render.Code as Code
22+import qualified Reporting.Error.Syntax as E
1623import qualified Reporting.Report as Report
1724
1825
@@ -20,36 +27,56 @@ import qualified Reporting.Report as Report
2027data Error
2128 = NoDocs A.Region
2229 | ImplicitExposing A.Region
23− | Duplicate Name.Name A.Region A.Region
24− | OnlyInDocs Name.Name A.Region
25− | OnlyInExports Name.Name A.Region
26− | NoComment Name.Name A.Region
30+ | SyntaxProblem SyntaxProblem
31+ | NameProblems (NE.List NameProblem)
32+ | DefProblems (NE.List DefProblem)
33+
34+
35+data SyntaxProblem
36+ = Op Row Col
37+ | OpBad BadOperator Row Col
38+ | Export Row Col
39+ | Space E.Space Row Col
40+ | Comma Row Col
41+ | BadEnd Row Col
42+
43+
44+data NameProblem
45+ = NameDuplicate Name.Name A.Region A.Region
46+ | NameOnlyInDocs Name.Name A.Region
47+ | NameOnlyInExports Name.Name A.Region
48+
49+
50+data DefProblem
51+ = NoComment Name.Name A.Region
2752 | NoAnnotation Name.Name A.Region
2853
2954
3055
31−-- TO REPORT
56+-- TO REPORTS
3257
3358
34−toReport :: Code.Source -> Error -> Report.Report
35−toReport source err =
59+toReports :: Code.Source -> Error -> NE.List Report.Report
60+toReports source err =
3661 case err of
3762 NoDocs region ->
63+ NE.singleton $
3864 Report.Report "NO DOCS" region [] $
39− D.stack
40− [
65+ Code.toSnippet source region Nothing
66+ (
4167 D.reflow $
4268 "You must have a documentation comment between the module\
4369 \ declaration and the imports."
4470 ,
4571 D.reflow
4672 "Learn more at <http://package.elm-lang.org/help/documentation-format>"
47− ]
73+ )
4874
4975 ImplicitExposing region ->
76+ NE.singleton $
5077 Report.Report "IMPLICIT EXPOSING" region [] $
51− D.stack
52− [
78+ Code.toSnippet source region Nothing
79+ (
5380 D.reflow $
5481 "I need you to be explicit about what this module exposes:"
5582 ,
@@ -59,9 +86,22 @@ toReport source err =
5986 \ to be explicit about this is a way of adding another quality check before\
6087 \ code gets published. So as you write out the public API, ask yourself if\
6188 \ it will be easy to understand as people read the documentation!"
62− ]
89+ )
90+
91+ SyntaxProblem _ ->
92+ error "TODO SyntaxProblem in docs"
6393
64− Duplicate name r1 r2 ->
94+ NameProblems problems ->
95+ fmap (toNameProblemReport source) problems
96+
97+ DefProblems problems ->
98+ fmap (toDefProblemReport source) problems
99+
100+
101+toNameProblemReport :: Code.Source -> NameProblem -> Report.Report
102+toNameProblemReport source problem =
103+ case problem of
104+ NameDuplicate name r1 r2 ->
65105 Report.Report "DUPLICATE DOCS" r2 [] $
66106 Code.toPair source r1 r2
67107 (
@@ -81,7 +121,7 @@ toReport source err =
81121 "Remove one of them!"
82122 )
83123
84− OnlyInDocs name region ->
124+ NameOnlyInDocs name region ->
85125 Report.Report "DOCS MISTAKE" region [] $
86126 Code.toSnippet source region Nothing
87127 (
@@ -94,7 +134,7 @@ toReport source err =
94134 <> Name.toChars name <> "` and forgot to delete it here?"
95135 )
96136
97− OnlyInExports name region ->
137+ NameOnlyInExports name region ->
98138 Report.Report "DOCS MISTAKE" region [] $
99139 Code.toSnippet source region Nothing
100140 (
@@ -110,6 +150,10 @@ toReport source err =
110150 ]
111151 )
112152
153+
154+toDefProblemReport :: Code.Source -> DefProblem -> Report.Report
155+toDefProblemReport source problem =
156+ case problem of
113157 NoComment name region ->
114158 Report.Report "NO DOCS" region [] $
115159 Code.toSnippet source region Nothing