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..e885c4e --- /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 "elapsedTimeInMinutes does not use preparationTimeInMinutes" <| + \() -> + """ +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 } } + ]