From 1e22728b1722cfb50aa266d854c9fcee3d096303 Mon Sep 17 00:00:00 2001 From: James Carlson Date: Thu, 13 Jun 2024 01:47:09 +0200 Subject: [PATCH] Expose the Install.Import module --- elm.json | 3 ++- src/Install/Import.elm | 49 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/elm.json b/elm.json index 01c6171..4fc7fb6 100644 --- a/elm.json +++ b/elm.json @@ -9,7 +9,8 @@ "Install.FieldInTypeAlias", "Install.Initializer", "Install.TypeVariant", - "Install.Function" + "Install.Function", + "Install.Import" ], "elm-version": "0.19.0 <= v < 0.20.0", "dependencies": { diff --git a/src/Install/Import.elm b/src/Install/Import.elm index 3660982..fd44058 100644 --- a/src/Install/Import.elm +++ b/src/Install/Import.elm @@ -1,4 +1,36 @@ -module Install.Import exposing (..) +module Install.Import exposing + ( Config + , CustomError + , init + , makeRule + , withAlias + , withExposedValues + ) + +{-| Add import statements to a given module. + +Exammples: + + ``` + Install.Import.init "Frontend" "Foo.Bar" + |> Install.Import.makeRule + ``` + + This adds `import Foo.Bar` to the `Frontend` module. + + + ``` + Install.Import.init "Frontend" "Foo.Bar" + |> Install.Import.withAlias "FB" + |> Install.Import.withExposedValues [ "a", "b", "c" ] + |> Install.Import.makeRule + ``` + + This adds `import Foo.Bar as FB exposing (a, b, c)` to the `Frontend` module. + + ``` + +-} import Elm.Syntax.Import exposing (Import) import Elm.Syntax.ModuleName exposing (ModuleName) @@ -9,6 +41,11 @@ import Review.Rule as Rule exposing (Error, Rule) import Set exposing (Set) +{-| + + Configuratioh for the rule. + +-} type alias Config = { hostModuleName : List String , importedModuleName : List String @@ -36,20 +73,22 @@ init hostModuleName_ importedModuleName_ = } +{-| Add an alias to the imported module. +-} withAlias : String -> Config -> Config withAlias alias config = { config | importedModuleAlias = Just alias } +{-| Add an exposing list to the imported module. +-} withExposedValues : List String -> Config -> Config withExposedValues exposedValues config = { config | exposedValues = Just exposedValues } -{-| Create a rule that adds an import for a given module in a given module. For example: - - Install.Import.makeRule "Frontend" "Foo.Bar" "add: import module Foo." - +{-| Create a rule that adds an import for a given module in a given module. +See above for examples. -} makeRule : Config -> Rule makeRule config =