-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rule for concept exercise
lucians-luscious-lasagna
- Loading branch information
Showing
3 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "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 } } | ||
] |