@@ -41,7 +41,6 @@ module Reporting.Exit
42import qualified Data.List as List
42import qualified Data.List as List
43import qualified Data.NonEmptyList as NE
43import qualified Data.NonEmptyList as NE
44−import qualified Data.Utf8 as Utf8
46import qualified Elm.Constraint as C
45import qualified Elm.Constraint as C
47import qualified Elm.Magnitude as M
46import qualified Elm.Magnitude as M
@@ -53,12 +52,14 @@ import qualified Json.Decode as Decode
53import qualified Json.Encode as Encode
52import qualified Json.Encode as Encode
54import qualified Json.String as Json
53import qualified Json.String as Json
55import Parse.Primitives (Row, Col)
54import Parse.Primitives (Row, Col)
55+import qualified Reporting.Annotation as A
56import Reporting.Doc ((<>))
56import Reporting.Doc ((<>))
57import qualified Reporting.Doc as D
57import qualified Reporting.Doc as D
58import qualified Reporting.Error.Import as Import
58import qualified Reporting.Error.Import as Import
59import qualified Reporting.Error.Json as Json
59import qualified Reporting.Error.Json as Json
60import qualified Reporting.Exit.Help as Help
60import qualified Reporting.Exit.Help as Help
61import qualified Reporting.Error as Error
61import qualified Reporting.Error as Error
62+import qualified Reporting.Render.Code as Code
@@ -608,7 +609,7 @@ installToReport exit =
608 Help.report "OLD DEPENDENCIES" (Just "elm.json")
609 Help.report "OLD DEPENDENCIES" (Just "elm.json")
609 ( "The following packages do not work with Elm " ++ V.toChars V.compiler ++ " right now:"
610 ( "The following packages do not work with Elm " ++ V.toChars V.compiler ++ " right now:"
611− [ D.indent 4 $ D.vcat $ map (D.red . D.fromUtf8 . Pkg.toString) badPackages
612+ [ D.indent 4 $ D.vcat $ map (D.red . D.fromPackage) badPackages
612 , D.reflow $
613 , D.reflow $
613 "This may be because it is not upgraded yet. It may be because a\
614 "This may be because it is not upgraded yet. It may be because a\
614 \ better solution came along, so there was no need to upgrade it.\
615 \ better solution came along, so there was no need to upgrade it.\
@@ -912,7 +913,7 @@ toOutlineReport :: Outline -> Help.Report
912toOutlineReport problem =
913toOutlineReport problem =
913 case problem of
914 case problem of
914 OutlineHasBadStructure decodeError ->
915 OutlineHasBadStructure decodeError ->
915− error "TODO OutlineHasBadStructure" decodeError toOutlineProblemReport
916+ Json.toReport "elm.json" (Json.FailureToReport toOutlineProblemReport) decodeError
917 OutlineHasBadSrcDirs dir dirs ->
918 OutlineHasBadSrcDirs dir dirs ->
918 case dirs of
919 case dirs of
@@ -953,36 +954,198 @@ toOutlineReport problem =
953 , D.reflow "It helps me handle flags and ports."
954 , D.reflow "It helps me handle flags and ports."
956−toOutlineProblemReport :: OutlineProblem -> Help.Report
958+toOutlineProblemReport :: FilePath -> Code.Source -> Json.Context -> A.Region -> OutlineProblem -> Help.Report
957−toOutlineProblemReport problem =
959+toOutlineProblemReport path source _ region problem =
961+ toHighlight row col =
962+ Just $ A.Region (A.Position row col) (A.Position row col)
964+ toSnippet title highlight pair =
965+ Help.jsonReport title (Just path) $
966+ Code.toSnippet source region highlight pair
958 case problem of
968 case problem of
959 OP_BadType ->
969 OP_BadType ->
960− error "TODO OP_BadType"
970+ toSnippet "UNEXPECTED TYPE" Nothing
972+ "I do not know how to process this type of elm.json file:"
974+ ["Try","changing","the","type","to"
975+ ,D.green "\"application\"","or",D.green "\"package\"","instead."
962 OP_BadPkgName row col ->
979 OP_BadPkgName row col ->
963− error "TODO OP_BadPkgName" row col
980+ toSnippet "INVALID PACKAGE NAME" (toHighlight row col)
982+ "I ran into trouble with this package name:"
985+ ["Package","names","are","always","written","as"
986+ ,D.green "\"author/project\""
987+ ,"so","I","am","expecting","to","see","something","like:"
989+ , D.dullyellow $ D.indent 4 $ D.vcat $
990+ [ "\"mdgriffith/elm-ui\""
991+ , "\"w0rm/elm-physics\""
992+ , "\"Microsoft/elm-json-tree-view\""
993+ , "\"FordLabs/elm-star-rating\""
994+ , "\"1602/json-schema\""
997+ "The author name should match your GitHub name exactly, and the project name\
998+ \ needs to follow these rules:"
999+ , D.indent 4 $ D.vcat $
1000+ [ "+--------------------------------------+-----------+-----------+"
1001+ , "| RULE | BAD | GOOD |"
1002+ , "+--------------------------------------+-----------+-----------+"
1003+ , "| only lower case, digits, and hyphens | elm-HTTP | elm-http |"
1004+ , "| no leading digits | 3D | elm-3d |"
1005+ , "| no non-ASCII characters | elm-bjørn | elm-bear |"
1006+ , "| no underscores | elm_ui | elm-ui |"
1007+ , "| no double hyphens | elm--hash | elm-hash |"
1008+ , "| no starting or ending hyphen | -elm-tar- | elm-tar |"
1009+ , "+--------------------------------------+-----------+-----------+"
1012+ "These rules only apply to the project name, so you should never need\
1013+ \ to change your GitHub name!"
965 OP_BadVersion row col ->
1017 OP_BadVersion row col ->
966− error "TODO OP_BadVersion" row col
1018+ toSnippet "PROBLEM WITH VERSION" (toHighlight row col)
1020+ "I was expecting a version number here:"
1022+ ["I","need","something","like",D.green "\"1.0.0\"","or",D.green "\"2.0.4\""
1023+ ,"that","explicitly","states","all","three","numbers!"
968 OP_BadConstraint constraintError ->
1027 OP_BadConstraint constraintError ->
969− error "TODO OP_BadConstraint" constraintError
1028+ case constraintError of
1029+ C.BadFormat row col ->
1030+ toSnippet "PROBLEM WITH CONSTRAINT" (toHighlight row col)
1032+ "I was expecting a version constraint here:"
1035+ ["I","need","something","like",D.green "\"1.0.0 <= v < 2.0.0\""
1036+ ,"that","explicitly","lists","the","lower","and","upper","bounds."
1039+ "The spaces in there are required! Taking them out will confuse me. Adding\
1040+ \ extra spaces confuses me too. I recommend starting with a valid example\
1041+ \ and just changing the version numbers."
1045+ C.InvalidRange before after ->
1046+ if before == after then
1047+ toSnippet "PROBLEM WITH CONSTRAINT" Nothing
1049+ "I ran into an invalid version constraint:"
1051+ ["Elm","checks","that","all","package","APIs","follow","semantic","versioning,"
1052+ ,"so","it","is","best","to","use","wide","constraints.","I","recommend"
1053+ ,D.green $ "\"" <> D.fromVersion before <> " <= v < " <> D.fromVersion (V.bumpMajor after) <> "\""
1054+ ,"since","it","is","guaranteed","that","breaking","API","changes","cannot"
1055+ ,"happen","in","any","of","the","versions","in","that","range."
1060+ toSnippet "PROBLEM WITH CONSTRAINT" Nothing
1062+ "I ran into an invalid version constraint:"
1064+ ["Maybe","you","want","something","like"
1065+ ,D.green $ "\"" <> D.fromVersion before <> " <= v < " <> D.fromVersion (V.bumpMajor before) <> "\""
1066+ ,"instead?","Elm","checks","that","all","package","APIs","follow","semantic"
1067+ ,"versioning,","so","it","is","guaranteed","that","breaking","API","changes"
1068+ ,"cannot","happen","in","any","of","the","versions","in","that","range."
971 OP_BadModuleName row col ->
1072 OP_BadModuleName row col ->
972− error "TODO OP_BadModuleName" row col
1073+ toSnippet "PROBLEM WITH MODULE NAME" (toHighlight row col)
1075+ "I was expecting a module name here:"
1077+ ["I","need","something","like",D.green "\"Html.Events\""
1078+ ,"or",D.green "\"Browser.Navigation\""
1079+ ,"where","each","segment","starts","with","a","capital"
1080+ ,"letter","and","the","segments","are","separated","by","dots."
974 OP_BadModuleHeaderTooLong ->
1084 OP_BadModuleHeaderTooLong ->
975− error "TODO OP_BadModuleHeaderTooLong"
1085+ toSnippet "HEADER TOO LONG" Nothing
1087+ "This section header is too long:"
1089+ ["I","need","it","to","be"
1090+ ,D.green "under",D.green "20",D.green "characters"
1091+ ,"so","it","renders","nicely","on","the","package","website!"
977 OP_BadDependencyName row col ->
1095 OP_BadDependencyName row col ->
978− error "TODO OP_BadDependencyName"
1096+ toSnippet "PROBLEM WITH DEPENDENCY NAME" (toHighlight row col)
1098+ "There is something wrong with this dependency name:"
1101+ ["Package","names","always","include","the","name","of","the","author,"
1102+ ,"so","I","am","expecting","to","see","dependencies","like"
1103+ ,D.dullyellow "\"mdgriffith/elm-ui\"","and"
1104+ ,D.dullyellow "\"Microsoft/elm-json-tree-view\"" <> "."
1107+ ["I","generally","recommend","finding","the","package","you","want","on"
1108+ ,"the","package","website,","and","installing","it","with","the"
1109+ ,D.green "elm install","command!"
980− OP_BadLicense badLicense suggestions ->
1114+ OP_BadLicense _ suggestions ->
981− error "TODO OP_BadLicense" badLicense suggestions
1115+ toSnippet "UNKNOWN LICENSE" Nothing
1117+ "I do not know about this type of license:"
1121+ ["Elm","packages","generally","use"
1122+ ,D.green "\"BSD-3-Clause\"","or",D.green "\"MIT\"" <> ","
1123+ ,"but","I","accept","any","OSI","approved","SPDX","license."
1124+ ,"Here","some","that","seem","close","to","what","you","wrote:"
1126+ , D.indent 4 $ D.dullyellow $ D.vcat $ map (D.fromChars . Json.toChars) suggestions
1128+ "Check out https://spdx.org/licenses/ for the full list of options."
983 OP_BadSummaryTooLong ->
1132 OP_BadSummaryTooLong ->
984− error "TODO OP_BadSummaryTooLong"
1133+ toSnippet "SUMMARY TOO LONG" Nothing
1135+ "Your \"summary\" is too long:"
1137+ ["I","need","it","to","be"
1138+ ,D.green "under",D.green "80",D.green "characters"
1139+ ,"so","it","renders","nicely","on","the","package","website!"
986 OP_NoSrcDirs ->
1143 OP_NoSrcDirs ->
987− error "TODO OP_NoSrcDirs"
1144+ toSnippet "NO SOURCE DIRECTORIES" Nothing
1146+ "You do not have any \"source-directories\" listed here:"
1148+ ["I","need","something","like",D.green "[\"src\"]"
1149+ ,"so","I","know","where","to","look","for","your","modules!"