Skip to content

Commit

Permalink
Rule name change: insertFunction -> function
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxcarlson committed Aug 13, 2024
1 parent 9ceb36d commit 2b09c89
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 31 deletions.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# elm-review-codeinstaller

**NOTE:** *This version is a breaking change from version 11.0. In case where you wrote `.init ... |> makeRule` you will need to write `.config ... |> makeRule` instead.*
**NOTE:** *This version is a breaking change from version 12.05. The visible part is an improved set of rule names. Please see the documentation,
both below and for the
A package designed to make it easy to add pieces of code to an existing codebase using `elm-review` rules. This package provides a set of tools to help you automatically insert clauses in case expressions, fields in type aliases, fields in initializer functions, and variants in custom types.*

A package designed to make it easy to add pieces of code to an existing codebase using `elm-review` rules. This package provides a set of tools to help you automatically insert clauses in case expressions, fields in type aliases, fields in initializer functions, and variants in custom types.

The project is still in development, so expect it to change a lot over the next weeks and likely months. For now, consider it to be an experiment.
*The project is still in development, so expect it to change a lot over the next weeks and likely months. For now, consider it to be an experiment.*

## Installation

Expand Down Expand Up @@ -111,13 +111,19 @@ To test the review code in its current state, try running this in a clean Lamder
npx elm-review --template jxxcarlson/elm-review-codeinstaller/example
```

For this to succeed, your Lamdera project must have a notion of "page," as in the counter app
that you will find in the folder `counter-original` of the
repo for this project. Try copying that folder.


## Contributing

Contributions are welcome! Please open an issue or submit a pull request if you have any improvements or bug fixes.

## Contributors

James Carlson and Mateus Leite.
James Carlson and Mateus Leite. We also thank Jeroen Engels for his
contributions to making our API much better.

## License

Expand Down
6 changes: 3 additions & 3 deletions preview/src/ReviewConfig.elm
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ configAuthFrontend =
[ Import.qualified "Frontend" [ "MagicLink.Types", "Auth.Common", "MagicLink.Frontend", "MagicLink.Auth", "Pages.SignIn", "Pages.Home", "Pages.Admin", "Pages.TermsOfService", "Pages.Notes" ]
|> Install.imports
, ReplaceFunction.config "Frontend" "tryLoading" tryLoading2
|> Install.function
|> Install.replaceFunction
, ClauseInCase.config "Frontend" "updateFromBackendLoaded" "AuthToFrontend authToFrontendMsg" "MagicLink.Auth.updateFromBackend authToFrontendMsg model.magicLinkModel |> Tuple.mapFirst (\\magicLinkModel -> { model | magicLinkModel = magicLinkModel })"
|> ClauseInCase.withInsertAtBeginning
|> Install.clauseInCase
Expand Down Expand Up @@ -344,9 +344,9 @@ configView =
, Import.qualified "View.Main" [ "MagicLink.Helper", "Pages.Counter", "Pages.SignIn", "Pages.Admin", "Pages.TermsOfService", "Pages.Notes", "User" ]
|> Install.imports
, ReplaceFunction.config "View.Main" "headerRow" headerRow
|> Install.function
|> Install.replaceFunction
, ReplaceFunction.config "View.Main" "makeLinks" makeLinks
|> Install.function
|> Install.replaceFunction
]


Expand Down
30 changes: 15 additions & 15 deletions src/Install.elm
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module Install exposing
( rule
, Installation
, imports, addElementToList, insertFunction, function, clauseInCase, insertFieldInTypeAlias, initializer, initializerCmd, subscription, addType, addTypeVariant
, imports, addElementToList, function, replaceFunction, clauseInCase, insertFieldInTypeAlias, initializer, initializerCmd, subscription, addType, addTypeVariant
)

{-|
@docs rule
@docs Installation
@docs imports, addElementToList, insertFunction, function, clauseInCase, insertFieldInTypeAlias, initializer, initializerCmd, subscription, addType, addTypeVariant
@docs imports, addElementToList, function, replaceFunction, clauseInCase, insertFieldInTypeAlias, initializer, initializerCmd, subscription, addType, addTypeVariant
-}

Expand Down Expand Up @@ -45,8 +45,8 @@ import Review.Rule as Rule exposing (Error, Rule)
type alias Context =
{ importContexts : List ( Install.Internal.Import.Config, Install.Internal.Import.Context )
, elementToList : List Install.ElementToList.Config
, insertFunction : List ( Install.Function.InsertFunction.Config, Install.Internal.InsertFunction.Context )
, function : List Install.Function.ReplaceFunction.Config
, function : List ( Install.Function.InsertFunction.Config, Install.Internal.InsertFunction.Context )
, replaceFunction : List Install.Function.ReplaceFunction.Config
, clauseInCase : List Install.ClauseInCase.Config
, fieldInTypeAlias : List Install.FieldInTypeAlias.Config
, initializer : List Install.Initializer.Config
Expand Down Expand Up @@ -89,15 +89,15 @@ addElementToList =

{-| Insert a function, defined by [`Install.Function.InsertFunction.config`](Install-Function-InsertFunction#config).
-}
insertFunction : Install.Function.InsertFunction.Config -> Installation
insertFunction =
function : Install.Function.InsertFunction.Config -> Installation
function =
InsertFunction


{-| Replace a function, defined by [`Install.Function.ReplaceFunction.config`](Install-Function-ReplaceFunction#config).
-}
function : Install.Function.ReplaceFunction.Config -> Installation
function =
replaceFunction : Install.Function.ReplaceFunction.Config -> Installation
replaceFunction =
ReplaceFunction


Expand Down Expand Up @@ -186,14 +186,14 @@ initContext installations =

InsertFunction ((Install.Internal.InsertFunction.Config { hostModuleName }) as config) ->
if moduleName == hostModuleName then
{ context | insertFunction = ( config, Install.Internal.InsertFunction.init ) :: context.insertFunction }
{ context | function = ( config, Install.Internal.InsertFunction.init ) :: context.function }

else
context

ReplaceFunction ((Install.Internal.ReplaceFunction.Config { hostModuleName }) as config) ->
if moduleName == hostModuleName then
{ context | function = config :: context.function }
{ context | replaceFunction = config :: context.replaceFunction }

else
context
Expand Down Expand Up @@ -249,8 +249,8 @@ initContext installations =
)
{ importContexts = []
, elementToList = []
, insertFunction = []
, function = []
, replaceFunction = []
, clauseInCase = []
, fieldInTypeAlias = []
, initializer = []
Expand Down Expand Up @@ -303,7 +303,7 @@ declarationVisitor node context =
context.elementToList
, List.concatMap
(\config -> Install.Internal.ReplaceFunction.declarationVisitor config node)
context.function
context.replaceFunction
, List.concatMap
(\config -> Install.Internal.ClauseInCase.declarationVisitor config node)
context.clauseInCase
Expand All @@ -326,10 +326,10 @@ declarationVisitor node context =
in
( errors
, { context
| insertFunction =
| function =
List.map
(\( config, ctx ) -> ( config, Install.Internal.InsertFunction.declarationVisitor config node ctx ))
context.insertFunction
context.function
, addType =
List.map
(\( config, ctx ) -> ( config, Install.Internal.Type.declarationVisitor config node ctx ))
Expand All @@ -346,7 +346,7 @@ finalEvaluation context =
context.importContexts
, List.concatMap
(\( config, ctx ) -> Install.Internal.InsertFunction.finalEvaluation config ctx)
context.insertFunction
context.function
, List.concatMap
(\( config, ctx ) -> Install.Internal.Type.finalEvaluation config ctx)
context.addType
Expand Down
16 changes: 8 additions & 8 deletions tests/Install/FunctionTest.elm
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ rule1 =
"view"
"""view model =
Html.text "This is a test\""""
|> Install.function
|> Install.replaceFunction
src1 : String
Expand Down Expand Up @@ -134,7 +134,7 @@ rule1b =
"View.Main"
"makeLinks"
makeLinks
|> Install.function
|> Install.replaceFunction
under1b : String
Expand Down Expand Up @@ -215,7 +215,7 @@ rule2 =
"newFunction"
"""newFunction model =
Html.text "This is a test\""""
|> Install.insertFunction
|> Install.function


under2 : String
Expand Down Expand Up @@ -267,7 +267,7 @@ rule2a =
"Frontend"
"makeLinks"
makeLinks
|> Install.insertFunction
|> Install.function


fixed2a : String
Expand Down Expand Up @@ -332,7 +332,7 @@ rule3 =
"newFunction"
"""newFunction model =
Html.text "This is a test\""""
|> Install.insertFunction
|> Install.function
under3 : String
Expand Down Expand Up @@ -377,7 +377,7 @@ rule4 =
"""newFunction model =
Html.text "This is a test\""""
|> InsertFunction.withInsertAfter "view"
|> Install.insertFunction
|> Install.function
under4 : String
Expand Down Expand Up @@ -424,7 +424,7 @@ rule4a =
"""newFunction model =
Html.text "This is a test\""""
|> InsertFunction.withInsertAfter "Model"
|> Install.insertFunction
|> Install.function


under4a : String
Expand Down Expand Up @@ -470,7 +470,7 @@ rule4b =
"""newFunction model =
Html.text "This is a test\""""
|> InsertFunction.withInsertAfter "Model"
|> Install.insertFunction
|> Install.function
under4b : String
Expand Down

0 comments on commit 2b09c89

Please sign in to comment.