on master help sign in
Update warnings for unused arguments, bindings, etc.
e92c826Evan Czaplicki
src/Reporting/Warning.hs+36−6
@@ -1,13 +1,19 @@
1{-# OPTIONS_GHC -Wall #-}
1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3−module Reporting.Warning where
3+module Reporting.Warning
4+ ( Warning(..)
5+ , Unused(..)
6+ , toReport
7+ , toJson
8+ )
9+ where
4
10
5import Data.Aeson ((.=))
11import Data.Aeson ((.=))
6import qualified Data.Aeson as Json
12import qualified Data.Aeson as Json
7import Data.Text (Text)
13import Data.Text (Text)
8
14
9−import qualified AST.Module.Name as ModuleName
10import qualified AST.Type as Type
15import qualified AST.Type as Type
16+import qualified Elm.Name as N
11import qualified Reporting.Annotation as A
17import qualified Reporting.Annotation as A
12import qualified Reporting.Report as Report
18import qualified Reporting.Report as Report
13import qualified Reporting.Render.Type as RenderType
19import qualified Reporting.Render.Type as RenderType
@@ -20,8 +26,12 @@ import Reporting.Helpers ((<>), text)
20
26
21
27
22data Warning
28data Warning
23− = UnusedImport ModuleName.Raw
29+ = UnusedImport N.Name
30+ | UnusedVariable Unused N.Name
24− | MissingTypeAnnotation Text Type.Canonical
31+ | MissingTypeAnnotation Text Type.Canonical
32+
33+
34+data Unused = Argument | Binding
25
35
26
36
27
37
@@ -35,8 +45,28 @@ toReport localizer warning =
35 Report.report
45 Report.report
36 "unused import"
46 "unused import"
37 Nothing
47 Nothing
38− ("Module `" <> ModuleName.toText moduleName <> "` is unused.")
48+ ("Nothing from the `" <> moduleName <> "` module is used in this file.")
39− (text "Best to remove it. Don't save code quality for later!")
49+ (text "I recommend removing unused imports.")
50+
51+ UnusedVariable Argument name ->
52+ Report.report
53+ "unused argument"
54+ Nothing
55+ ("The `" <> name <> "` argument is unused.")
56+ ( Help.reflowParagraph $
57+ "Maybe this indicates there is a mistake around here? Switching the\
58+ \ argument to a _ will indicate that it is intentionally unused."
59+ )
60+
61+ UnusedVariable Binding name ->
62+ Report.report
63+ "unused binding"
64+ Nothing
65+ ("The `" <> name <> "` binding is unused.")
66+ ( Help.reflowParagraph $
67+ "Maybe this indicates there is a mistake around here? Or maybe it\
68+ \ just is not used anymore and should be removed?"
69+ )
40
70
41 MissingTypeAnnotation name inferredType ->
71 MissingTypeAnnotation name inferredType ->
42 Report.report
72 Report.report