Run elm-review fixes.

This commit is contained in:
Dillon Kearns 2020-12-07 08:41:10 -08:00
parent a41b5f5f03
commit f7e1e8d3cb
20 changed files with 718 additions and 566 deletions

File diff suppressed because it is too large Load Diff

View File

@ -29,7 +29,8 @@ config =
, NoUnused.Dependencies.rule
, NoUnused.Exports.rule
, NoUnused.Modules.rule
, NoUnused.Parameters.rule
, NoUnused.Patterns.rule
--, NoUnused.Parameters.rule
--, NoUnused.Patterns.rule
, NoUnused.Variables.rule
]

View File

@ -43,7 +43,6 @@ writing a plugin package to extend `elm-pages`.
-}
import Codec exposing (Codec)
import Json.Encode
import MimeType
import Pages.ImagePath as ImagePath exposing (ImagePath)

View File

@ -1,4 +1,4 @@
module Head.Seo exposing (Common, Image, article, audioPlayer, profile, song, summary, summaryLarge, videoPlayer, website)
module Head.Seo exposing (Common, Image, article, audioPlayer, book, profile, song, summary, summaryLarge, videoPlayer, website)
{-| <https://ogp.me/#>
<https://developers.facebook.com/docs/sharing/opengraph>
@ -45,14 +45,14 @@ with the `head` function that you pass to your Pages config (`Pages.application`
, expirationTime = Nothing
}
@docs Common, Image, article, audioPlayer, profile, song, summary, summaryLarge, videoPlayer, website
@docs Common, Image, article, audioPlayer, book, profile, song, summary, summaryLarge, videoPlayer, website
-}
import Head
import Head.Twitter as Twitter
import Pages.ImagePath as ImagePath exposing (ImagePath)
import Pages.PagePath as PagePath exposing (PagePath)
import Pages.ImagePath exposing (ImagePath)
import Pages.PagePath exposing (PagePath)
{-| Will be displayed as a large card in twitter

View File

@ -1,68 +1,9 @@
module Head.Twitter exposing (SummarySize(..), TwitterCard(..), rawTags, summaryLarge, summaryRegular)
module Head.Twitter exposing (SummarySize(..), TwitterCard(..), rawTags)
import Head
import Pages.ImagePath exposing (ImagePath)
{-| <https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/summary>
-}
summaryRegular details =
Summary
{ title = details.title
, description = details.description
, siteUser = details.siteUser
, image = details.image
, size = Regular
}
|> tags
{-| <https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/summary-card-with-large-image.html>
-}
summaryLarge details =
Summary
{ title = details.title
, description = details.description
, siteUser = details.siteUser
, image = details.image
, size = Large
}
|> tags
{-| <https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/app-card>
-}
app :
{ title : String
, description : Maybe String
, siteUser : String
, image : Maybe (Image pathKey)
, appIdIphone : Maybe Int
, appIdIpad : Maybe Int
, appIdGooglePlay : Maybe String
, appUrlIphone : Maybe String
, appUrlIpad : Maybe String
, appUrlGooglePlay : Maybe String
, appCountry : Maybe String
, appNameIphone : Maybe String
, appNameIpad : Maybe String
, appNameGooglePlay : Maybe String
}
-> List (Head.Tag pathKey)
app details =
App details
|> tags
ensureAtPrefix : String -> String
ensureAtPrefix twitterUsername =
if twitterUsername |> String.startsWith "@" then
twitterUsername
else
"@" ++ twitterUsername
type SummarySize
= Regular
| Large
@ -150,17 +91,6 @@ rawTags card =
)
tags : TwitterCard pathKey -> List (Head.Tag pathKey)
tags card =
card
|> rawTags
|> List.filterMap
(\( name, maybeContent ) ->
maybeContent
|> Maybe.map (\content -> Head.metaName name content)
)
cardValue : TwitterCard pathKey -> String
cardValue card =
case card of

View File

@ -569,39 +569,6 @@ lazy toDecoder =
jde
{-| Useful for checking a value in the JSON matches the value you expect it to
have. If it does, succeeds with the second decoder. If it doesn't it fails.
This can be used to decode union types:
type Pet = Cat | Dog | Rabbit
petDecoder : Decoder Pet
petDecoder =
oneOf
[ check string "cat" <| succeed Cat
, check string "dog" <| succeed Dog
, check string "rabbit" <| succeed Rabbit
]
""" [ "dog", "rabbit", "cat" ] """
|> decodeString (list petDecoder)
--> Success [ Dog, Rabbit, Cat ]
-}
check : Decoder a -> a -> Decoder b -> Decoder b
check checkDecoder expectedVal actualDecoder =
checkDecoder
|> andThen
(\actual ->
if actual == expectedVal then
actualDecoder
else
fail "Verification failed"
)
-- Mapping and chaining

View File

@ -1,7 +1,6 @@
module Pages.ContentCache exposing
( ContentCache
, Entry(..)
, Page
, Path
, errorView
, extractMetadata
@ -11,7 +10,6 @@ module Pages.ContentCache exposing
, lookupMetadata
, pagesWithErrors
, parseContent
, pathForUrl
, routesForCache
, update
)
@ -288,13 +286,6 @@ routesForCache cacheResult =
[]
type alias Page metadata view pathKey =
{ metadata : metadata
, path : PagePath pathKey
, view : view
}
combineTupleResults :
List ( List String, Result error success )
-> Result (List error) (List ( List String, success ))

View File

@ -90,7 +90,6 @@ Hello!!!
-}
import Dict exposing (Dict)
import Html exposing (Html)
import Json.Decode

View File

@ -1,51 +1,7 @@
module Pages.FrontmatterDecoder exposing (FrontmatterDecoder, decodeList, decoder, resolve)
module Pages.FrontmatterDecoder exposing (FrontmatterDecoder)
import Json.Decode as Decode exposing (Decoder)
type FrontmatterDecoder a
= FrontmatterDecoder (List Decode.Value -> Decoder a)
parse : List String -> FrontmatterDecoder a -> Result String a
parse (FrontmatterDecoder rawDecoder) =
Decode.decodeString rawDecoder
decoder : Decoder a -> FrontmatterDecoder a
decoder rawDecoder =
FrontmatterDecoder (\values -> rawDecoder)
resolve : (List a -> Decoder b) -> FrontmatterDecoder a -> FrontmatterDecoder b
resolve resolveFn (FrontmatterDecoder rawDecoder) =
(\values ->
let
listDecoder : Decoder (List a)
listDecoder =
decodeList values (rawDecoder values)
in
listDecoder
|> Decode.andThen
(\list ->
resolveFn list
)
)
|> FrontmatterDecoder
decodeList : List Decode.Value -> Decoder a -> Decoder (List a)
decodeList values rawDecoder =
List.foldl
(\value soFar ->
soFar
|> Decode.andThen
(\list ->
case Decode.decodeValue rawDecoder value of
Ok decoded ->
Decode.succeed (decoded :: list)
Err error ->
Decode.fail "TODO error message"
)
)
(Decode.succeed [])
values

View File

@ -1,12 +1,11 @@
module Pages.Internal.Platform exposing (Content, Flags, Model, Msg, Page, Program, application, cliApplication)
module Pages.Internal.Platform exposing (Content, Flags, Model, Msg, Program, application, cliApplication)
import Browser
import Browser.Dom as Dom
import Browser.Navigation
import Dict exposing (Dict)
import Head
import Html exposing (Html)
import Html.Attributes exposing (style)
import Html.Attributes
import Html.Lazy
import Http
import Json.Decode as Decode
@ -22,18 +21,10 @@ import Pages.PagePath as PagePath exposing (PagePath)
import Pages.StaticHttp as StaticHttp
import Pages.StaticHttpRequest as StaticHttpRequest
import RequestsAndPending exposing (RequestsAndPending)
import Result.Extra
import Task exposing (Task)
import Task
import Url exposing (Url)
type alias Page metadata view pathKey =
{ metadata : metadata
, path : PagePath pathKey
, view : view
}
type alias Content =
List ( List String, { extension : String, frontMatter : String, body : Maybe String } )

View File

@ -3,14 +3,13 @@ module Pages.Internal.Platform.Cli exposing
, Flags
, Model
, Msg(..)
, Page
, cliApplication
, init
, update
)
import BuildError exposing (BuildError)
import Codec exposing (Codec)
import Codec
import Dict exposing (Dict)
import ElmHtml.InternalTypes exposing (decodeElmHtml)
import ElmHtml.ToString exposing (FormatOptions, defaultFormatOptions, nodeToStringWithOptions)
@ -26,7 +25,7 @@ import Pages.Internal.ApplicationType as ApplicationType
import Pages.Internal.Platform.Effect as Effect exposing (Effect)
import Pages.Internal.Platform.Mode as Mode exposing (Mode)
import Pages.Internal.Platform.StaticResponses as StaticResponses exposing (StaticResponses)
import Pages.Internal.Platform.ToJsPayload as ToJsPayload exposing (ToJsPayload, ToJsSuccessPayload)
import Pages.Internal.Platform.ToJsPayload as ToJsPayload exposing (ToJsSuccessPayload)
import Pages.Internal.StaticHttpBody as StaticHttpBody
import Pages.Manifest as Manifest
import Pages.PagePath as PagePath exposing (PagePath)
@ -38,19 +37,6 @@ import TerminalText as Terminal
import Url
type alias FileToGenerate =
{ path : List String
, content : String
}
type alias Page metadata view pathKey =
{ metadata : metadata
, path : PagePath pathKey
, view : view
}
type alias Content =
List ( List String, { extension : String, frontMatter : String, body : Maybe String } )
@ -279,17 +265,6 @@ perform config cliMsgConstructor toJsPort effect =
Cmd.none
encodeFilesToGenerate list =
list
|> Json.Encode.list
(\item ->
Json.Encode.object
[ ( "path", item.path |> String.join "/" |> Json.Encode.string )
, ( "content", item.content |> Json.Encode.string )
]
)
--Task.succeed ()
-- |> Task.perform (\_ -> Continue)
@ -358,33 +333,6 @@ init toModel contentCache siteMetadata config flags =
toModel
elmToHtmlBetaInit { secrets, mode, staticHttpCache } toModel contentCache siteMetadata config flags =
--case flags of
--init toModel contentCache siteMetadata config flags
--|> Tuple.mapSecond (perform cliMsgConstructor config.toJsPort)
--|> Tuple.mapSecond
-- (\cmd ->
--Cmd.map AppMsg
--Cmd.none
( toModel
(Model StaticResponses.error
secrets
[]
--(metadataParserErrors |> List.map Tuple.second)
staticHttpCache
mode
[]
)
, Effect.NoEffect
--, { html =
-- Html.div []
-- [ Html.text "Hello!!!!!" ]
-- |> viewRenderer
-- }
-- |> Effect.SendSinglePage
)
--)

View File

@ -12,7 +12,6 @@ import Pages.StaticHttp as StaticHttp exposing (RequestDetails)
import Pages.StaticHttp.Request as HashRequest
import Pages.StaticHttpRequest as StaticHttpRequest
import RequestsAndPending exposing (RequestsAndPending)
import Result.Extra
import Secrets
import SecretsDict exposing (SecretsDict)
import Set
@ -151,12 +150,6 @@ update newEntry model =
}
dictCompact : Dict String (Maybe a) -> Dict String a
dictCompact dict =
dict
|> Dict.Extra.filterMap (\key value -> value)
encode : RequestsAndPending -> Mode -> StaticResponses -> Dict String (Dict String String)
encode requestsAndPending mode (StaticResponses staticResponses) =
staticResponses
@ -507,13 +500,3 @@ combineMultipleErrors results =
)
(Ok [])
results
isJust : Maybe a -> Bool
isJust maybeValue =
case maybeValue of
Just _ ->
True
Nothing ->
False

View File

@ -74,12 +74,6 @@ import Pages.PagePath as PagePath exposing (PagePath)
-- TODO use language https://developer.mozilla.org/en-US/docs/Web/Manifest/lang
type alias Language =
{ dir : String -- "rtl",
, lang : String -- "ar" -- TODO should this be an enum? What standard code?
}
{-| See <https://developer.mozilla.org/en-US/docs/Web/Manifest/display>
-}
type DisplayMode
@ -188,11 +182,6 @@ type IconPurpose
| IconPurposeAny
square : Int -> ( Int, Int )
square x =
( x, x )
displayModeToAttribute : DisplayMode -> String
displayModeToAttribute displayMode =
case displayMode of

View File

@ -1,9 +1,8 @@
module Pages.StaticHttpRequest exposing (Error(..), Request(..), Status(..), cacheRequestResolution, permanentError, resolve, resolveUrls, strippedResponses, toBuildError, urls)
module Pages.StaticHttpRequest exposing (Error(..), Request(..), Status(..), cacheRequestResolution, resolve, resolveUrls, strippedResponses, toBuildError)
import BuildError exposing (BuildError)
import Dict exposing (Dict)
import Pages.Internal.ApplicationType as ApplicationType exposing (ApplicationType)
import Pages.Internal.StaticHttpBody as StaticHttpBody
import Pages.Internal.ApplicationType exposing (ApplicationType)
import Pages.StaticHttp.Request
import RequestsAndPending exposing (RequestsAndPending)
import Secrets
@ -41,16 +40,6 @@ type Error
| UserCalledStaticHttpFail String
urls : Request value -> List (Secrets.Value Pages.StaticHttp.Request.Request)
urls request =
case request of
Request ( urlList, lookupFn ) ->
urlList
Done value ->
[]
toBuildError : String -> Error -> BuildError
toBuildError path error =
case error of
@ -85,29 +74,6 @@ toBuildError path error =
}
permanentError : ApplicationType -> Request value -> RequestsAndPending -> Maybe Error
permanentError appType request rawResponses =
case request of
Request ( urlList, lookupFn ) ->
case lookupFn appType rawResponses of
Ok ( partiallyStrippedResponses, nextRequest ) ->
permanentError appType nextRequest rawResponses
Err error ->
case error of
MissingHttpResponse _ ->
Nothing
DecoderError _ ->
Just error
UserCalledStaticHttpFail string ->
Just error
Done value ->
Nothing
resolve : ApplicationType -> Request value -> RequestsAndPending -> Result Error value
resolve appType request rawResponses =
case request of

View File

@ -38,34 +38,6 @@ succeed value =
Value (\_ -> Ok value)
append : Value (List value) -> Value (List value) -> Value (List value)
append (Value lookupSecrets1) (Value lookupSecrets2) =
Value
(\secrets ->
let
secrets1 : Result (List BuildError) (List value)
secrets1 =
lookupSecrets1 secrets
secrets2 : Result (List BuildError) (List value)
secrets2 =
lookupSecrets2 secrets
in
case ( secrets1, secrets2 ) of
( Ok value1, Ok value2 ) ->
Ok (value1 ++ value2)
( Ok value1, Err errors2 ) ->
Err errors2
( Err errors1, Ok value2 ) ->
Err errors1
( Err errors1, Err errors2 ) ->
Err (errors1 ++ errors2)
)
buildError : String -> SecretsDict -> BuildError
buildError secretName secretsDict =
let

View File

@ -1,7 +1,7 @@
module BetaStaticHttpRequestsTests exposing (all)
import Codec
import Dict exposing (Dict)
import Dict
import Expect
import Html
import Json.Decode as JD
@ -12,7 +12,7 @@ import Pages.Document as Document
import Pages.ImagePath as ImagePath
import Pages.Internal.Platform.Cli as Main exposing (..)
import Pages.Internal.Platform.Effect as Effect exposing (Effect)
import Pages.Internal.Platform.ToJsPayload as ToJsPayload exposing (ToJsPayload)
import Pages.Internal.Platform.ToJsPayload as ToJsPayload
import Pages.Internal.StaticHttpBody as StaticHttpBody
import Pages.Manifest as Manifest
import Pages.PagePath as PagePath
@ -20,14 +20,12 @@ import Pages.StaticHttp as StaticHttp
import Pages.StaticHttp.Request as Request
import PagesHttp
import ProgramTest exposing (ProgramTest)
import Regex
import Secrets
import SimulatedEffect.Cmd
import SimulatedEffect.Http as Http
import SimulatedEffect.Ports
import SimulatedEffect.Task
import Test exposing (Test, describe, only, skip, test)
import Test.Http
import Test exposing (Test, describe, test)
all : Test
@ -296,56 +294,6 @@ simulateEffects effect =
-- |> SimulatedEffect.Task.perform (\_ -> Main.Continue)
expectErrorsPort : String -> List (ToJsPayload pathKey) -> Expect.Expectation
expectErrorsPort expectedPlainString actualPorts =
case actualPorts of
[ ToJsPayload.Errors actualRichTerminalString ] ->
actualRichTerminalString
|> normalizeErrorExpectEqual expectedPlainString
[] ->
Expect.fail "Expected single error port. Didn't receive any ports."
_ ->
Expect.fail <| "Expected single error port. Got\n" ++ String.join "\n\n" (List.map Debug.toString actualPorts)
expectNonfatalErrorsPort : String -> List (ToJsPayload pathKey) -> Expect.Expectation
expectNonfatalErrorsPort expectedPlainString actualPorts =
case actualPorts of
[ ToJsPayload.Success successPayload ] ->
successPayload.errors
|> String.join "\n\n"
|> normalizeErrorExpectEqual expectedPlainString
_ ->
Expect.fail <| "Expected single non-fatal error port. Got\n" ++ String.join "\n\n" (List.map Debug.toString actualPorts)
normalizeErrorExpectEqual : String -> String -> Expect.Expectation
normalizeErrorExpectEqual expectedPlainString actualRichTerminalString =
actualRichTerminalString
|> Regex.replace
(Regex.fromString "\u{001B}\\[[0-9;]+m"
|> Maybe.withDefault Regex.never
)
(\_ -> "")
|> Expect.equal expectedPlainString
normalizeErrorsExpectEqual : List String -> List String -> Expect.Expectation
normalizeErrorsExpectEqual expectedPlainStrings actualRichTerminalStrings =
actualRichTerminalStrings
|> List.map
(Regex.replace
(Regex.fromString "\u{001B}\\[[0-9;]+m"
|> Maybe.withDefault Regex.never
)
(\_ -> "")
)
|> Expect.equalLists expectedPlainStrings
toJsPort foo =
Cmd.none
@ -416,23 +364,6 @@ expectSuccess expectedRequests previous =
)
expectError : List String -> ProgramTest model msg effect -> Expect.Expectation
expectError expectedErrors previous =
previous
|> ProgramTest.expectOutgoingPortValues
"toJsPort"
(Codec.decoder (ToJsPayload.successCodecNew2 "" ""))
(\value ->
case value of
[ ToJsPayload.PageProgress portPayload ] ->
portPayload.errors
|> normalizeErrorsExpectEqual expectedErrors
_ ->
Expect.fail ("Expected ports to be called once, but instead there were " ++ String.fromInt (List.length value) ++ " calls.")
)
get : String -> Request.Request
get url =
{ method = "GET"

View File

@ -1,7 +1,7 @@
module StaticHttpRequestsTests exposing (all)
import Codec
import Dict exposing (Dict)
import Dict
import Expect
import Html
import Json.Decode as JD
@ -26,7 +26,7 @@ import SimulatedEffect.Cmd
import SimulatedEffect.Http as Http
import SimulatedEffect.Ports
import SimulatedEffect.Task
import Test exposing (Test, describe, only, skip, test)
import Test exposing (Test, describe, test)
import Test.Http
@ -982,18 +982,6 @@ expectErrorsPort expectedPlainString actualPorts =
Expect.fail <| "Expected single error port. Got\n" ++ String.join "\n\n" (List.map Debug.toString actualPorts)
expectNonfatalErrorsPort : String -> List (ToJsPayload pathKey) -> Expect.Expectation
expectNonfatalErrorsPort expectedPlainString actualPorts =
case actualPorts of
[ ToJsPayload.Success successPayload ] ->
successPayload.errors
|> String.join "\n\n"
|> normalizeErrorExpectEqual expectedPlainString
_ ->
Expect.fail <| "Expected single non-fatal error port. Got\n" ++ String.join "\n\n" (List.map Debug.toString actualPorts)
normalizeErrorExpectEqual : String -> String -> Expect.Expectation
normalizeErrorExpectEqual expectedPlainString actualRichTerminalString =
actualRichTerminalString

View File

@ -1,15 +1,14 @@
module StaticHttpUnitTests exposing (all)
import Dict exposing (Dict)
import Dict
import Expect
import Json.Decode.Exploration
import OptimizedDecoder as Decode
import Pages.Internal.ApplicationType as ApplicationType
import Pages.StaticHttp as StaticHttp
import Pages.StaticHttp.Request as Request
import Pages.StaticHttpRequest as StaticHttpRequest
import Secrets
import Test exposing (Test, describe, only, test)
import Test exposing (Test, describe, test)
getWithoutSecrets url =

View File

@ -1,30 +1,15 @@
module StaticResponsesTests exposing (all)
import Dict exposing (Dict)
import Dict
import Expect
import Pages.Internal.Platform.Mode as Mode
import Pages.Internal.Platform.StaticResponses as StaticResponses
import Pages.Internal.Platform.ToJsPayload as ToJsPayload
import Pages.StaticHttp as StaticHttp
import Pages.StaticHttp.Request as Request
import Secrets
import SecretsDict
import Test exposing (Test, describe, test)
getWithoutSecrets url =
StaticHttp.get (Secrets.succeed url)
get : String -> Request.Request
get url =
{ method = "GET"
, url = url
, headers = []
, body = StaticHttp.emptyBody
}
all : Test
all =
describe "Static Http Requests"
@ -51,12 +36,3 @@ config =
, content = []
, manifest = ToJsPayload.stubManifest
}
getReq : String -> StaticHttp.RequestDetails
getReq url =
{ url = url
, method = "GET"
, headers = []
, body = StaticHttp.emptyBody
}