Skip to content

Commit

Permalink
Expose the Install.Import module
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxcarlson committed Jun 12, 2024
1 parent 233973a commit 1e22728
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
3 changes: 2 additions & 1 deletion elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
49 changes: 44 additions & 5 deletions src/Install/Import.elm
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit 1e22728

Please sign in to comment.