Skip to content

Commit

Permalink
fix elm-review warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
decioferreira committed Dec 11, 2024
1 parent 0ce32ec commit 5ac4451
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 430 deletions.
5 changes: 2 additions & 3 deletions review/src/ReviewConfig.elm
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ config =
[ Docs.ReviewAtDocs.rule
, NoConfusingPrefixOperator.rule
, NoDebug.Log.rule

-- , NoDebug.TodoOrToString.rule
-- |> Rule.ignoreErrorsForDirectories [ "tests/" ]
, NoDebug.TodoOrToString.rule
|> Rule.ignoreErrorsForDirectories [ "tests/" ]
, NoExposingEverything.rule
, NoImportingEverything.rule []
, NoMissingTypeAnnotation.rule
Expand Down
37 changes: 0 additions & 37 deletions src/Builder/Elm/Outline.elm
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ module Builder.Elm.Outline exposing
, flattenExposed
, read
, srcDirCodec
, srcDirDecoder
, srcDirEncoder
, write
)

Expand All @@ -29,8 +27,6 @@ import Compiler.Json.Decode as D
import Compiler.Json.Encode as E
import Compiler.Parse.Primitives as P
import Data.Map as Dict exposing (Dict)
import Json.Decode as Decode
import Json.Encode as Encode
import Serialize exposing (Codec)
import System.IO as IO exposing (IO)
import Utils.Main as Utils exposing (FilePath)
Expand Down Expand Up @@ -423,39 +419,6 @@ boundParser bound tooLong =
Err (P.PErr P.Consumed row newCol (\_ _ -> tooLong))


srcDirEncoder : SrcDir -> Encode.Value
srcDirEncoder srcDir =
case srcDir of
AbsoluteSrcDir dir ->
Encode.object
[ ( "type", Encode.string "AbsoluteSrcDir" )
, ( "dir", Encode.string dir )
]

RelativeSrcDir dir ->
Encode.object
[ ( "type", Encode.string "RelativeSrcDir" )
, ( "dir", Encode.string dir )
]


srcDirDecoder : Decode.Decoder SrcDir
srcDirDecoder =
Decode.field "type" Decode.string
|> Decode.andThen
(\type_ ->
case type_ of
"AbsoluteSrcDir" ->
Decode.map AbsoluteSrcDir (Decode.field "dir" Decode.string)

"RelativeSrcDir" ->
Decode.map RelativeSrcDir (Decode.field "dir" Decode.string)

_ ->
Decode.fail ("Failed to decode SrcDir's type: " ++ type_)
)


srcDirCodec : Codec e SrcDir
srcDirCodec =
Serialize.customType
Expand Down
49 changes: 0 additions & 49 deletions src/Compiler/AST/Utils/Binop.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@ module Compiler.AST.Utils.Binop exposing
( Associativity(..)
, Precedence
, associativityCodec
, associativityDecoder
, associativityEncoder
, precedenceCodec
, precedenceDecoder
, precedenceEncoder
)

import Json.Decode as Decode
import Json.Encode as Encode
import Serialize exposing (Codec)


Expand All @@ -28,54 +22,11 @@ type Associativity
| Right


precedenceEncoder : Precedence -> Encode.Value
precedenceEncoder =
Encode.int


precedenceDecoder : Decode.Decoder Precedence
precedenceDecoder =
Decode.int


precedenceCodec : Codec e Precedence
precedenceCodec =
Serialize.int


associativityEncoder : Associativity -> Encode.Value
associativityEncoder associativity =
case associativity of
Left ->
Encode.string "Left"

Non ->
Encode.string "Non"

Right ->
Encode.string "Right"


associativityDecoder : Decode.Decoder Associativity
associativityDecoder =
Decode.string
|> Decode.andThen
(\str ->
case str of
"Left" ->
Decode.succeed Left

"Non" ->
Decode.succeed Non

"Right" ->
Decode.succeed Right

_ ->
Decode.fail ("Unknown Associativity: " ++ str)
)


associativityCodec : Codec e Associativity
associativityCodec =
Serialize.customType
Expand Down
73 changes: 0 additions & 73 deletions src/Compiler/Json/Decode.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,107 +7,34 @@ module Compiler.Json.Decode exposing
, Problem(..)
, StringProblem(..)
, apply
, assocListDict
, bind
, customString
, dict
, everySet
, failure
, field
, fmap
, fromByteString
, int
, jsonPair
, list
, mapError
, nonEmptyList
, nonempty
, oneOf
, oneOrMore
, pair
, pairs
, pure
, result
, string
)

import Compiler.Data.NonEmptyList as NE
import Compiler.Data.OneOrMore as OneOrMore exposing (OneOrMore)
import Compiler.Json.String as Json
import Compiler.Parse.Keyword as K
import Compiler.Parse.Primitives as P exposing (Col, Row)
import Compiler.Reporting.Annotation as A
import Data.Map as Dict exposing (Dict)
import Data.Set as EverySet exposing (EverySet)
import Json.Decode as Decode
import Utils.Crash exposing (crash)



-- CORE HELPERS


assocListDict : (k -> comparable) -> Decode.Decoder k -> Decode.Decoder v -> Decode.Decoder (Dict comparable k v)
assocListDict toComparable keyDecoder valueDecoder =
Decode.list (jsonPair keyDecoder valueDecoder)
|> Decode.map (Dict.fromList toComparable)


jsonPair : Decode.Decoder a -> Decode.Decoder b -> Decode.Decoder ( a, b )
jsonPair firstDecoder secondDecoder =
Decode.map2 Tuple.pair
(Decode.field "a" firstDecoder)
(Decode.field "b" secondDecoder)


everySet : (a -> comparable) -> Decode.Decoder a -> Decode.Decoder (EverySet comparable a)
everySet toComparable decoder =
Decode.list decoder
|> Decode.map (EverySet.fromList toComparable)


nonempty : Decode.Decoder a -> Decode.Decoder (NE.Nonempty a)
nonempty decoder =
Decode.list decoder
|> Decode.andThen
(\values ->
case values of
x :: xs ->
Decode.succeed (NE.Nonempty x xs)

[] ->
Decode.fail "Empty list when it should have at least one element (non-empty list)!"
)


oneOrMore : Decode.Decoder a -> Decode.Decoder (OneOrMore a)
oneOrMore decoder =
Decode.oneOf
[ Decode.map OneOrMore.one (Decode.field "one" decoder)
, Decode.map2 OneOrMore.more
(Decode.field "left" (Decode.lazy (\_ -> oneOrMore decoder)))
(Decode.field "right" (Decode.lazy (\_ -> oneOrMore decoder)))
]


result : Decode.Decoder x -> Decode.Decoder a -> Decode.Decoder (Result x a)
result errDecoder successDecoder =
Decode.field "type" Decode.string
|> Decode.andThen
(\type_ ->
case type_ of
"Err" ->
Decode.map Err (Decode.field "value" errDecoder)

"Ok" ->
Decode.map Ok (Decode.field "value" successDecoder)

_ ->
Decode.fail ("Failed to decode result's type: " ++ type_)
)



-- RUNNERS


Expand Down
113 changes: 0 additions & 113 deletions src/Compiler/Json/Encode.elm
Original file line number Diff line number Diff line change
@@ -1,104 +1,25 @@
module Compiler.Json.Encode exposing
( Value(..)
, array
, assocListDict
, bool
, chars
, dict
, encodeUgly
, everySet
, int
, jsonPair
, list
, maybe
, name
, nonempty
, null
, number
, object
, oneOrMore
, result
, string
, toJsonValue
, write
, writeUgly
)

import Compiler.Data.NonEmptyList as NE
import Compiler.Data.OneOrMore exposing (OneOrMore(..))
import Data.Map as Dict exposing (Dict)
import Data.Set as EverySet exposing (EverySet)
import Json.Encode as Encode
import System.IO as IO exposing (IO(..))



-- CORE HELPERS


assocListDict : (k -> k -> Order) -> (k -> Encode.Value) -> (v -> Encode.Value) -> Dict c k v -> Encode.Value
assocListDict keyComparison keyEncoder valueEncoder =
Encode.list (jsonPair keyEncoder valueEncoder) << List.reverse << Dict.toList keyComparison


jsonPair : (a -> Encode.Value) -> (b -> Encode.Value) -> ( a, b ) -> Encode.Value
jsonPair firstEncoder secondEncoder ( a, b ) =
Encode.object
[ ( "a", firstEncoder a )
, ( "b", secondEncoder b )
]


everySet : (a -> a -> Order) -> (a -> Encode.Value) -> EverySet c a -> Encode.Value
everySet keyComparison encoder =
Encode.list encoder << List.reverse << EverySet.toList keyComparison


result : (x -> Encode.Value) -> (a -> Encode.Value) -> Result x a -> Encode.Value
result errEncoder successEncoder resultValue =
case resultValue of
Ok value ->
Encode.object
[ ( "type", Encode.string "Ok" )
, ( "value", successEncoder value )
]

Err err ->
Encode.object
[ ( "type", Encode.string "Err" )
, ( "value", errEncoder err )
]


maybe : (a -> Encode.Value) -> Maybe a -> Encode.Value
maybe encoder maybeValue =
case maybeValue of
Just value ->
encoder value

Nothing ->
Encode.null


nonempty : (a -> Encode.Value) -> NE.Nonempty a -> Encode.Value
nonempty encoder (NE.Nonempty x xs) =
Encode.list encoder (x :: xs)


oneOrMore : (a -> Encode.Value) -> OneOrMore a -> Encode.Value
oneOrMore encoder oneOrMore_ =
case oneOrMore_ of
One value ->
Encode.object [ ( "one", encoder value ) ]

More left right ->
Encode.object
[ ( "left", oneOrMore encoder left )
, ( "right", oneOrMore encoder right )
]



-- VALUES


Expand Down Expand Up @@ -142,11 +63,6 @@ int =
Integer


number : Float -> Value
number =
Number


null : Value
null =
Null
Expand Down Expand Up @@ -359,32 +275,3 @@ encodeObject indent first rest =
encodeField : String -> ( String, Value ) -> String
encodeField indent ( key, value ) =
"\"" ++ key ++ "\": " ++ encodeHelp indent value



-- JSON VALUE


toJsonValue : Value -> Encode.Value
toJsonValue value =
case value of
Array arr ->
Encode.list toJsonValue arr

Object obj ->
Encode.object (List.map (Tuple.mapSecond toJsonValue) obj)

StringVal builder ->
Encode.string builder

Boolean boolean ->
Encode.bool boolean

Integer n ->
Encode.int n

Number scientific ->
Encode.float scientific

Null ->
Encode.null
Loading

0 comments on commit 5ac4451

Please sign in to comment.