Skip to content

Commit

Permalink
Special-case report for configuration errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jfmengels committed Nov 9, 2024
1 parent 150d870 commit 692b52e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
14 changes: 3 additions & 11 deletions template/src/Elm/Review/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -309,19 +309,11 @@ I recommend you take a look at the following documents:
abortForConfigurationErrors <|
case flags.reportMode of
HumanReadable ->
Reporter.formatReport
{ suppressedErrors = SuppressedErrors.empty
, unsuppressMode = flags.unsuppressMode
, originalNumberOfSuppressedErrors = 0
, detailsMode = flags.detailsMode
, errorsHaveBeenFixedPreviously = False
Reporter.formatConfigurationErrors
{ detailsMode = flags.detailsMode
, mode = Reporter.Reviewing
, configurationErrors = configurationErrors
}
[ { path = Reporter.ConfigurationError
, source = Reporter.Source ""
, errors = configurationErrors
}
]
|> encodeReport

Json ->
Expand Down
26 changes: 25 additions & 1 deletion template/src/Elm/Review/Reporter.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Elm.Review.Reporter exposing
( Error, File, FilePath(..), Source(..), TextContent
, Mode(..), DetailsMode(..), formatReport, formatIndividualError
, formatFixProposal, formatFixProposals
, FileWithError, Range
, FileWithError, Range, formatConfigurationErrors
)

{-| Formats the result of `elm-review` in a nice human-readable way.
Expand Down Expand Up @@ -196,6 +196,30 @@ formatReport { suppressedErrors, unsuppressMode, originalNumberOfSuppressedError
|> List.map Text.toRecord


{-| Reports configuration errors reported by `elm-review` in a nice human-readable way.
-}
formatConfigurationErrors : { detailsMode : DetailsMode, mode : Mode, configurationErrors : List Error } -> List TextContent
formatConfigurationErrors { detailsMode, mode, configurationErrors } =
let
filesWithErrors : List FileWithError
filesWithErrors =
[ { path = ConfigurationError
, source = Source ""
, errors = configurationErrors
}
]
in
[ formatReports detailsMode mode filesWithErrors
, [ Text.from "I found "
, pluralize (List.length configurationErrors) "configuration error" |> Text.from |> Text.inRed
, Text.from "."
]
]
|> Text.join "\n\n"
|> Text.simplify
|> List.map Text.toRecord


formatTally : List a -> Int -> Int -> List Text
formatTally filesWithErrors numberOfFileErrors numberOfGlobalErrors =
Text.join ""
Expand Down
2 changes: 1 addition & 1 deletion test/snapshots/review/config-configuration-error.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Some.Rule: This is a configuration error message

These are configuration error details

I found 1 error in 1 file.
I found 1 configuration error.

0 comments on commit 692b52e

Please sign in to comment.