Skip to content

Commit fd12b4e

Browse files
committed
fix elm-review!
1 parent 4238fb6 commit fd12b4e

File tree

8 files changed

+222
-142
lines changed

8 files changed

+222
-142
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 Niklas Holmgren
3+
Copyright © 2024 Scrive
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

src/Json/Schema/Form.elm

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ module Json.Schema.Form exposing
1717
1818
@docs init, update
1919
20-
21-
# View
22-
2320
@docs view, submit
2421
2522
@@ -30,8 +27,8 @@ module Json.Schema.Form exposing
3027
-}
3128

3229
import Dict exposing (Dict)
33-
import Form as F exposing (Msg(..))
34-
import Html exposing (..)
30+
import Form as F exposing (Msg)
31+
import Html exposing (Html)
3532
import Json.Schema.Definitions exposing (Schema)
3633
import Json.Schema.Form.Default exposing (default)
3734
import Json.Schema.Form.Error exposing (ErrorValue, Errors)
@@ -81,6 +78,7 @@ init options schema =
8178
update : Msg -> State -> State
8279
update msg state =
8380
let
81+
form : F.Form ErrorValue Value
8482
form =
8583
F.update
8684
(validation state.options.formats state.schema)

src/Json/Schema/Form/Default.elm

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Json.Schema.Form.Default exposing (default)
22

3-
import Form.Field exposing (..)
3+
import Form.Field exposing (Field, bool, group, list, string)
44
import Json.Decode
55
import Json.Schema.Definitions
66
exposing
@@ -16,12 +16,8 @@ import Json.Schema.Definitions
1616
default : Schema -> List ( String, Field )
1717
default schema =
1818
case schema of
19-
BooleanSchema bool ->
20-
if bool then
21-
[]
22-
23-
else
24-
[]
19+
BooleanSchema _ ->
20+
[]
2521

2622
ObjectSchema objectSchema ->
2723
subSchema objectSchema
@@ -63,8 +59,7 @@ field ( name, schema ) =
6359
|> Maybe.withDefault []
6460

6561
UnionType types ->
66-
List.map (singleType schema_ value) types
67-
|> List.filterMap identity
62+
List.filterMap (singleType schema_ value) types
6863
|> List.map (\f -> ( name, f ))
6964

7065
Nothing ->
@@ -88,8 +83,7 @@ anyType value =
8883
|> Result.map (List.map string)
8984
|> Result.map list
9085
]
91-
|> List.map Result.toMaybe
92-
|> List.filterMap identity
86+
|> List.filterMap Result.toMaybe
9387
|> List.head
9488

9589

@@ -163,16 +157,8 @@ asString : Json.Decode.Decoder String
163157
asString =
164158
Json.Decode.oneOf
165159
[ Json.Decode.string
166-
, Json.Decode.int
167-
|> Json.Decode.andThen
168-
(\a ->
169-
Json.Decode.succeed (String.fromInt a)
170-
)
171-
, Json.Decode.float
172-
|> Json.Decode.andThen
173-
(\a ->
174-
Json.Decode.succeed (String.fromFloat a)
175-
)
160+
, Json.Decode.int |> Json.Decode.map String.fromInt
161+
, Json.Decode.float |> Json.Decode.map String.fromFloat
176162
]
177163

178164

src/Json/Schema/Form/Encode.elm

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,51 @@ module Json.Schema.Form.Encode exposing (encode)
22

33
{-| Encode form values as JSON.
44
5-
6-
# Encode
7-
85
@docs encode
96
107
-}
118

12-
import Json.Encode exposing (..)
9+
import Json.Encode as Encode
1310
import Json.Schema.Form.Value exposing (Value(..))
1411

1512

1613
{-| Encode a form value (the output of a valid form) as JSON.
1714
-}
18-
encode : Value -> Json.Encode.Value
15+
encode : Value -> Encode.Value
1916
encode value =
2017
case value of
2118
IntValue intValue ->
22-
int intValue
19+
Encode.int intValue
2320

2421
FloatValue floatValue ->
25-
float floatValue
22+
Encode.float floatValue
2623

2724
StringValue stringValue ->
28-
string stringValue
25+
Encode.string stringValue
2926

3027
BoolValue boolValue ->
31-
bool boolValue
28+
Encode.bool boolValue
3229

3330
ListValue valueList ->
34-
list encode valueList
31+
Encode.list encode valueList
3532

3633
ObjectValue objectValue ->
3734
let
35+
item : ( String, Value ) -> Maybe ( String, Encode.Value )
3836
item ( name, val ) =
3937
if val == EmptyValue then
4038
Nothing
4139

4240
else
4341
Just ( name, encode val )
4442
in
45-
object (List.filterMap item objectValue)
43+
Encode.object (List.filterMap item objectValue)
4644

4745
NullValue ->
48-
null
46+
Encode.null
4947

5048
EmptyValue ->
51-
object []
49+
Encode.object []
5250

5351
JsonValue jsonValue ->
5452
jsonValue

0 commit comments

Comments
 (0)