mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-11-29 01:24:35 +03:00
57 lines
1.1 KiB
Elm
57 lines
1.1 KiB
Elm
module NoInconsistentAliases.Config exposing
|
|
( Config, config, noMissingAliases
|
|
, canMissAliases, lookupAlias
|
|
)
|
|
|
|
{-|
|
|
|
|
@docs Config, config, noMissingAliases
|
|
@docs canMissAliases, lookupAlias
|
|
|
|
-}
|
|
|
|
import Dict exposing (Dict)
|
|
import Elm.Syntax.ModuleName exposing (ModuleName)
|
|
|
|
|
|
type Config
|
|
= Config
|
|
{ aliases : Dict ModuleName String
|
|
, allowMissingAliases : Bool
|
|
}
|
|
|
|
|
|
config : List ( String, String ) -> Config
|
|
config aliases =
|
|
Config
|
|
{ aliases =
|
|
aliases
|
|
|> List.map (Tuple.mapFirst toModuleName)
|
|
|> Dict.fromList
|
|
, allowMissingAliases = True
|
|
}
|
|
|
|
|
|
noMissingAliases : Config -> Config
|
|
noMissingAliases (Config cfg) =
|
|
Config { cfg | allowMissingAliases = False }
|
|
|
|
|
|
canMissAliases : Config -> Bool
|
|
canMissAliases (Config cfg) =
|
|
cfg.allowMissingAliases
|
|
|
|
|
|
lookupAlias : Config -> ModuleName -> Maybe String
|
|
lookupAlias (Config { aliases }) moduleName =
|
|
Dict.get moduleName aliases
|
|
|
|
|
|
|
|
--- HELPERS
|
|
|
|
|
|
toModuleName : String -> ModuleName
|
|
toModuleName moduleName =
|
|
String.split "." moduleName
|