diff --git a/README.md b/README.md index 61553ef..30da88b 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,9 @@ # elm-review-codeinstaller -**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.* +**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 [codeinstaller-rulesets](https://github.com/jxxcarlson/codeinstaller-rulesets) 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 @@ -59,12 +58,12 @@ addResetCounter = addResetCounterVariant : Rule addResetCounterVariant = - Install.TypeVariant.makeRule "Counter" "Msg" "ResetCounter" + Install.typeVariant "Counter" "Msg" "ResetCounter" addResetCounterClause : Rule addResetCounterClause = Install.ClauseInCase.config "Counter" "update" "ResetCounter" "( { model | counter = 0 }, Cmd.none )" - |> Install.ClauseInCase.makeRule + |> Install.clauseInCase ``` After running `elm-review --fix`, your `Counter` module will be updated as follows: @@ -115,14 +114,13 @@ For this to succeed, your Lamdera project must have a notion of "page," as in th 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. We also thank Jeroen Engels for his +[James Carlson](https://github.com/jxxcarlson) and [Mateus Leite](https://github.com/mateusfpleite). We also thank [Jeroen Engels](https://github.com/jfmengels) for his contributions to making our API much better. ## License diff --git a/src/Install/ClauseInCase.elm b/src/Install/ClauseInCase.elm index 977e789..dce35c6 100644 --- a/src/Install/ClauseInCase.elm +++ b/src/Install/ClauseInCase.elm @@ -15,7 +15,7 @@ in a specified module. For example, if you put the code below in your "updateFromFrontend" "ResetCounter" "( { model | counter = 0 }, broadcast (CounterNewValue 0 clientId) )" - |> Install.ClauseInCase.makeRule + |> Install.clauseInCase Thus we will have @@ -56,7 +56,7 @@ type alias Config = "updateFromFrontend" "ResetCounter" "( { model | counter = 0 }, broadcast (CounterNewValue 0 clientId) )" - |> Install.ClauseInCase.makeRule + |> Install.clauseInCase If you need additional configuration, check the `withInsertAfter` and `withCustomErrorMessage` functions. @@ -110,7 +110,7 @@ To add the clause `Aspasia` after the clause `Aristotle`, you can use the follow "Aspasia" "Just Aspasia" |> Install.ClauseInCase.withInsertAfter "Aristotle" - |> Install.ClauseInCase.makeRule + |> Install.clauseInCase This will add the clause `Aspasia` after the clause `Aristotle` in the `stringToPhilosopher` function, resulting in: @@ -151,7 +151,7 @@ You also can add the clause after another clause of choice with the `withInsertA "ResetCounter" "( { model | counter = 0 }, broadcast (CounterNewValue 0 clientId) )" |> Install.ClauseInCase.withInsertAtBeginning - |> Install.ClauseInCase.makeRule + |> Install.clauseInCase In this case we will have @@ -184,7 +184,7 @@ withInsertAtBeginning (Internal.Config config_) = "ResetCounter" "( { model | counter = 0 }, broadcast (CounterNewValue 0 clientId) )" |> Install.ClauseInCase.withCustomErrorMessage "Add handler for ResetCounter" [] - |> Install.ClauseInCase.makeRule + |> Install.clauseInCase -} withCustomErrorMessage : String -> List String -> Config -> Config diff --git a/src/Install/FieldInTypeAlias.elm b/src/Install/FieldInTypeAlias.elm index 21e05c9..7d176fe 100644 --- a/src/Install/FieldInTypeAlias.elm +++ b/src/Install/FieldInTypeAlias.elm @@ -6,7 +6,8 @@ in a specified module. For example, if you put the code below in your `quot: String` to the type alias `FrontendModel` in the `Types` module. -- code for ReviewConfig.elm: - Install.FieldInTypeAlias.makeRule "Types" "FrontendModel" [ "clientName: String", "quot: String" ] + Install.FieldInTypeAlias.config "Types" "FrontendModel" [ "clientName: String", "quot: String" ] + |> Install.fieldInTypeAlias Thus we will have @@ -42,7 +43,8 @@ type alias Config = After running the rule with the following code: - Install.FieldInTypeAlias.makeRule "Types" "FrontendModel" [ "clientName: String", "quot: String" ] + Install.FieldInTypeAlias.config "Types" "FrontendModel" [ "clientName: String", "quot: String" ] + |> Install.fieldInTypeAlias we will have diff --git a/src/Install/Function/ReplaceFunction.elm b/src/Install/Function/ReplaceFunction.elm index 3f46d5d..4d153cb 100644 --- a/src/Install/Function/ReplaceFunction.elm +++ b/src/Install/Function/ReplaceFunction.elm @@ -9,7 +9,7 @@ module Install.Function.ReplaceFunction exposing (Config, config) "view" """view model = Html.text "This is a test\"""" - |> Install.Function.ReplaceFunction.makeRule + |> Install.replaceFunction Running this rule will replace the function `view` in the module `Frontend` with the provided implementation. @@ -20,7 +20,7 @@ The form of the rule is the same for nested modules: "Foo.Bar" "earnInterest" "hoho model = { model | interest = 1.03 * model.interest }" - |> Install.Function.ReplaceFunction.makeRule + |> Install.replaceFunction @docs Config, config diff --git a/src/Install/Initializer.elm b/src/Install/Initializer.elm index d0737fd..a12a16f 100644 --- a/src/Install/Initializer.elm +++ b/src/Install/Initializer.elm @@ -6,9 +6,10 @@ the `ReviewConfig` item below, you specify the module name, the function name, as well as a list of item `{field = , value = }` to be added to the function. - Install.Initializer.makeRule "Main" + Install.Initializer.config "Main" "init" [ { field = "message", value = "\"hohoho!\"" }, { field = "counter", value = "0" } ] + |> Install.initializer Thus we will have @@ -40,9 +41,10 @@ As in the `ReviewConfig` item below, you specify the module name, the function name, as well as the field name and value to be added to the function: - Install.Initializer.makeRule "Main" + Install.Initializer.config "Main" "init" [ { field = "message", value = "\"hohoho!\"" }, { field = "counter", value = "0" } ] + |> Install.initializer -} config : String -> String -> List { field : String, value : String } -> Config