From 2b09c892fe9879e89fb64aed8747d31df9750826 Mon Sep 17 00:00:00 2001 From: James Carlson Date: Tue, 13 Aug 2024 09:36:02 -0400 Subject: [PATCH] Rule name change: insertFunction -> function --- README.md | 16 +++++++++++----- preview/src/ReviewConfig.elm | 6 +++--- src/Install.elm | 30 +++++++++++++++--------------- tests/Install/FunctionTest.elm | 16 ++++++++-------- 4 files changed, 37 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 7075a7e..61553ef 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/preview/src/ReviewConfig.elm b/preview/src/ReviewConfig.elm index 7b11481..25c2642 100644 --- a/preview/src/ReviewConfig.elm +++ b/preview/src/ReviewConfig.elm @@ -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 @@ -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 ] diff --git a/src/Install.elm b/src/Install.elm index 8e917b0..d4b7f0c 100644 --- a/src/Install.elm +++ b/src/Install.elm @@ -1,7 +1,7 @@ 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 ) {-| @@ -9,7 +9,7 @@ module Install exposing @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 -} @@ -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 @@ -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 @@ -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 @@ -249,8 +249,8 @@ initContext installations = ) { importContexts = [] , elementToList = [] - , insertFunction = [] , function = [] + , replaceFunction = [] , clauseInCase = [] , fieldInTypeAlias = [] , initializer = [] @@ -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 @@ -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 )) @@ -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 diff --git a/tests/Install/FunctionTest.elm b/tests/Install/FunctionTest.elm index 155bbf3..1681d1b 100644 --- a/tests/Install/FunctionTest.elm +++ b/tests/Install/FunctionTest.elm @@ -44,7 +44,7 @@ rule1 = "view" """view model = Html.text "This is a test\"""" - |> Install.function + |> Install.replaceFunction src1 : String @@ -134,7 +134,7 @@ rule1b = "View.Main" "makeLinks" makeLinks - |> Install.function + |> Install.replaceFunction under1b : String @@ -215,7 +215,7 @@ rule2 = "newFunction" """newFunction model = Html.text "This is a test\"""" - |> Install.insertFunction + |> Install.function under2 : String @@ -267,7 +267,7 @@ rule2a = "Frontend" "makeLinks" makeLinks - |> Install.insertFunction + |> Install.function fixed2a : String @@ -332,7 +332,7 @@ rule3 = "newFunction" """newFunction model = Html.text "This is a test\"""" - |> Install.insertFunction + |> Install.function under3 : String @@ -377,7 +377,7 @@ rule4 = """newFunction model = Html.text "This is a test\"""" |> InsertFunction.withInsertAfter "view" - |> Install.insertFunction + |> Install.function under4 : String @@ -424,7 +424,7 @@ rule4a = """newFunction model = Html.text "This is a test\"""" |> InsertFunction.withInsertAfter "Model" - |> Install.insertFunction + |> Install.function under4a : String @@ -470,7 +470,7 @@ rule4b = """newFunction model = Html.text "This is a test\"""" |> InsertFunction.withInsertAfter "Model" - |> Install.insertFunction + |> Install.function under4b : String