1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Reporting.Warning
11import Data.Aeson ((.=))
12import qualified Data.Aeson as Json
13import Data.Text (Text)
15import qualified AST.Canonical as Can
16import qualified Elm.Name as N
17import qualified Reporting.Annotation as A
18import qualified Reporting.Region as R
19import qualified Reporting.Report as Report
20import qualified Reporting.Render.Type as RenderType
21import qualified Reporting.Helpers as Help
22import Reporting.Helpers ((<>), text)
26-- ALL POSSIBLE WARNINGS
31 | UnusedVariable R.Region Context N.Name
32 | MissingTypeAnnotation Text Can.Type
35data Context = Def | Pattern
42toReport :: RenderType.Localizer -> Warning -> Report.Report
43toReport localizer warning =
45 UnusedImport moduleName ->
49 ("Nothing from the `" <> moduleName <> "` module is used in this file.")
50 (text "I recommend removing unused imports.")
52 UnusedVariable _ context name ->
54 (defOrPat context "unused definition" "unused variable")
56 ("You are not using `" <> name <> "` anywhere.")
58 [ Help.reflowParagraph $
59 "Is there a typo? Maybe you intended to use `" <> name
60 <> "` but typed a similar name instead?"
61 , Help.reflowParagraph $
63 ( "If you are sure there is no typo, remove the definition.\
64 \ This way future readers will not have to wonder!"
66 ( "If you are sure there is no typo, replace `" <> name
67 <> "` with _ so future readers will not have to wonder!"
72 MissingTypeAnnotation name inferredType ->
74 "missing type annotation"
76 ("Top-level value " <> Help.functionName name <> " does not have a type annotation.")
78 [ text "I inferred the type annotation so you can copy it into your code:"
79 , RenderType.annotation localizer name inferredType
84defOrPat :: Context -> a -> a -> a
85defOrPat context def pat =
95toJson :: RenderType.Localizer -> FilePath -> A.Located Warning -> Json.Value
96toJson localizer filePath (A.At region warning) =
98 (maybeRegion, additionalFields) =
99 Report.toJson [] (toReport localizer warning)
103 , "region" .= maybe region id maybeRegion
104 , "type" .= ("warning" :: Text)
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