1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Reporting.Warning
11import Data.Monoid ((<>))
13import qualified AST.Canonical as Can
14import qualified AST.Utils.Type as Type
15import qualified Elm.Name as N
16import qualified Reporting.Region as R
17import qualified Reporting.Report as Report
18import qualified Reporting.Render.Code as Code
19import qualified Reporting.Render.Type as RT
20import qualified Reporting.Helpers as H
24-- ALL POSSIBLE WARNINGS
28 = UnusedImport R.Region N.Name
29 | UnusedVariable R.Region Context N.Name
30 | MissingTypeAnnotation R.Region N.Name Can.Type
33data Context = Def | Pattern
40toReport :: Code.Source -> Warning -> Report.Report
41toReport source warning =
43 UnusedImport region moduleName ->
44 Report.Report "unused import" region [] $
45 Report.toCodeSnippet source region Nothing
48 "Nothing from the `" <> N.toString moduleName <> "` module is used in this file."
50 "I recommend removing unused imports."
53 UnusedVariable region context name ->
54 let title = defOrPat context "unused definition" "unused variable" in
55 Report.Report title region [] $
56 Report.toCodeSnippet source region Nothing
59 "You are not using `" <> N.toString name <> "` anywhere."
63 "Is there a typo? Maybe you intended to use `" <> N.toString name
64 <> "` somewhere but typed another name instead?"
67 ( "If you are sure there is no typo, remove the definition.\
68 \ This way future readers will not have to wonder why it is there!"
70 ( "If you are sure there is no typo, replace `" <> N.toString name
71 <> "` with _ so future readers will not have to wonder why it is there!"
76 MissingTypeAnnotation region name inferredType ->
77 Report.Report "missing type annotation" region [] $
78 Report.toCodeSnippet source region Nothing
81 case Type.deepDealias inferredType of
83 "The `" <> N.toString name <> "` function has no type annotation."
86 "The `" <> N.toString name <> "` definition has no type annotation."
89 [ "I inferred the type annotation myself though! You can copy it into your code:"
90 , H.green $ H.hang 4 $ H.sep $
91 [ H.nameToDoc name <> " :"
92 , RT.canToDoc RT.None inferredType
98defOrPat :: Context -> a -> a -> a
99defOrPat context def pat =
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list