Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rule for concept exercise lucians-luscious-lasagna #80

Merged
merged 2 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/Exercise/LuciansLusciousLasagna.elm
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions src/ReviewConfig.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -47,6 +48,7 @@ ruleConfigs =
, Exercise.TisburyTreasureHunt.ruleConfig
, Exercise.GottaSnatchEmAll.ruleConfig
, Exercise.AnnalynsInfiltration.ruleConfig
, Exercise.LuciansLusciousLasagna.ruleConfig

-- Practice Exercises
, Exercise.Strain.ruleConfig
Expand Down
69 changes: 69 additions & 0 deletions tests/Exercise/LuciansLusciousLasagnaTest.elm
Original file line number Diff line number Diff line change
@@ -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 } }
]
Loading