From ca9ea44dbfc67afaf22d64c6c4d2df6308f8351e Mon Sep 17 00:00:00 2001 From: Jeremie Gillet Date: Thu, 23 Nov 2023 21:38:02 +0900 Subject: [PATCH 1/2] Add rule for concept exercise `lucians-luscious-lasagna` --- src/Exercise/LuciansLusciousLasagna.elm | 26 +++++++ src/ReviewConfig.elm | 2 + tests/Exercise/LuciansLusciousLasagnaTest.elm | 69 +++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 src/Exercise/LuciansLusciousLasagna.elm create mode 100644 tests/Exercise/LuciansLusciousLasagnaTest.elm diff --git a/src/Exercise/LuciansLusciousLasagna.elm b/src/Exercise/LuciansLusciousLasagna.elm new file mode 100644 index 0000000..236c76d --- /dev/null +++ b/src/Exercise/LuciansLusciousLasagna.elm @@ -0,0 +1,26 @@ +module Exercise.LuciansLusciousLasagna exposing (reuseFunctions, ruleConfig) + +import Analyzer exposing (CalledExpression(..), CalledFrom(..), Find(..)) +import Comment exposing (Comment, CommentType(..)) +import Dict +import Review.Rule exposing (Rule) +import RuleConfig exposing (AnalyzerRule(..), RuleConfig) + + +ruleConfig : RuleConfig +ruleConfig = + { restrictToFiles = Just [ "src/LuciansLusciousLasagna.elm" ] + , rules = + [ CustomRule reuseFunctions + (Comment "elm.lucians-luscious-lasagna.reuse_functions" Essential Dict.empty) + ] + } + + +reuseFunctions : Comment -> Rule +reuseFunctions = + Analyzer.functionCalls + { calledFrom = TopFunction "elapsedTimeInMinutes" + , findExpressions = [ FromSameModule "preparationTimeInMinutes" ] + , find = Some + } diff --git a/src/ReviewConfig.elm b/src/ReviewConfig.elm index f27215a..b981a9b 100644 --- a/src/ReviewConfig.elm +++ b/src/ReviewConfig.elm @@ -11,6 +11,7 @@ import Exercise.BlorkemonCards import Exercise.CustomSet import Exercise.GottaSnatchEmAll import Exercise.ListOps +import Exercise.LuciansLusciousLasagna import Exercise.MariosMarvellousLasagna import Exercise.MazeMaker import Exercise.Strain @@ -47,6 +48,7 @@ ruleConfigs = , Exercise.TisburyTreasureHunt.ruleConfig , Exercise.GottaSnatchEmAll.ruleConfig , Exercise.AnnalynsInfiltration.ruleConfig + , Exercise.LuciansLusciousLasagna.ruleConfig -- Practice Exercises , Exercise.Strain.ruleConfig diff --git a/tests/Exercise/LuciansLusciousLasagnaTest.elm b/tests/Exercise/LuciansLusciousLasagnaTest.elm new file mode 100644 index 0000000..3d69007 --- /dev/null +++ b/tests/Exercise/LuciansLusciousLasagnaTest.elm @@ -0,0 +1,69 @@ +module Exercise.LuciansLusciousLasagnaTest exposing (tests) + +import Comment exposing (Comment, CommentType(..)) +import Dict +import Exercise.LuciansLusciousLasagna as LuciansLusciousLasagna +import Review.Rule exposing (Rule) +import Review.Test +import RuleConfig +import Test exposing (Test, describe, test) +import TestHelper + + +tests : Test +tests = + describe "LuciansLusciousLasagnaTest" + [ exemplar + , doesNotReuseFunction + ] + + +rules : List Rule +rules = + LuciansLusciousLasagna.ruleConfig |> .rules |> List.map RuleConfig.analyzerRuleToRule + + +exemplar : Test +exemplar = + test "should not report anything for the exemplar" <| + \() -> + TestHelper.expectNoErrorsForRules rules + """ +module LuciansLusciousLasagna exposing (elapsedTimeInMinutes, expectedMinutesInOven, preparationTimeInMinutes) + +expectedMinutesInOven = + 40 + +preparationTimeInMinutes layers = + 2 * layers + +elapsedTimeInMinutes layers passedAlready = + passedAlready + preparationTimeInMinutes layers +""" + + +doesNotReuseFunction : Test +doesNotReuseFunction = + let + comment = + Comment "elm.lucians-luscious-lasagna.reuse_functions" Essential Dict.empty + in + test "canFreePrisoner doesn't use boolean operators" <| + \() -> + """ +module LuciansLusciousLasagna exposing (elapsedTimeInMinutes, expectedMinutesInOven, preparationTimeInMinutes) + +expectedMinutesInOven = + 40 + +preparationTimeInMinutes layers = + 2 * layers + +elapsedTimeInMinutes layers passedAlready = + passedAlready + 2 * layers +""" + |> Review.Test.run (LuciansLusciousLasagna.reuseFunctions comment) + |> Review.Test.expectErrors + [ TestHelper.createExpectedErrorUnder comment "elapsedTimeInMinutes" + |> Review.Test.atExactly { start = { row = 10, column = 1 }, end = { row = 10, column = 21 } } + ] From e3f927a59dc66f5957049ffda7592333bbf773fe Mon Sep 17 00:00:00 2001 From: Jeremie Gillet Date: Thu, 23 Nov 2023 22:05:01 +0900 Subject: [PATCH 2/2] fix test name --- tests/Exercise/LuciansLusciousLasagnaTest.elm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Exercise/LuciansLusciousLasagnaTest.elm b/tests/Exercise/LuciansLusciousLasagnaTest.elm index 3d69007..e885c4e 100644 --- a/tests/Exercise/LuciansLusciousLasagnaTest.elm +++ b/tests/Exercise/LuciansLusciousLasagnaTest.elm @@ -48,7 +48,7 @@ doesNotReuseFunction = comment = Comment "elm.lucians-luscious-lasagna.reuse_functions" Essential Dict.empty in - test "canFreePrisoner doesn't use boolean operators" <| + test "elapsedTimeInMinutes does not use preparationTimeInMinutes" <| \() -> """ module LuciansLusciousLasagna exposing (elapsedTimeInMinutes, expectedMinutesInOven, preparationTimeInMinutes)