-
-
Notifications
You must be signed in to change notification settings - Fork 4
Add analysis for practice exercise for split-second-stopwatch
#97
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| module Exercise.SplitSecondStopwatch exposing (forbidStopwatchExportAll, forbidStopwatchTypeAlias, ruleConfig) | ||
|
|
||
| import Comment exposing (Comment, CommentType(..)) | ||
| import Dict | ||
| import Elm.Syntax.Declaration exposing (Declaration(..)) | ||
| import Elm.Syntax.Exposing as Exposing exposing (TopLevelExpose(..)) | ||
| import Elm.Syntax.Module exposing (Module(..)) | ||
| import Elm.Syntax.Node as Node exposing (Node(..)) | ||
| import List.Extra | ||
| import Review.Rule exposing (Error, Rule) | ||
| import RuleConfig exposing (AnalyzerRule(..), RuleConfig) | ||
|
|
||
|
|
||
| ruleConfig : RuleConfig | ||
| ruleConfig = | ||
| { restrictToFiles = Just [ "src/SplitSecondStopwatch.elm" ] | ||
| , rules = | ||
| [ CustomRule forbidStopwatchTypeAlias | ||
| (Comment "elm.split-second-stopwatch.no_stopwatch_type_alias" Essential Dict.empty) | ||
| , CustomRule forbidStopwatchExportAll | ||
| (Comment "elm.split-second-stopwatch.no_stopwatch_export_all" Essential Dict.empty) | ||
| ] | ||
| } | ||
|
|
||
|
|
||
| forbidStopwatchTypeAlias : Comment -> Rule | ||
| forbidStopwatchTypeAlias comment = | ||
| Review.Rule.newModuleRuleSchema comment.path () | ||
| |> Review.Rule.withSimpleDeclarationVisitor (hasStopwatchTypeAliasVisitor comment) | ||
| |> Review.Rule.fromModuleRuleSchema | ||
|
|
||
|
|
||
| hasStopwatchTypeAliasVisitor : Comment -> Node Declaration -> List (Error {}) | ||
| hasStopwatchTypeAliasVisitor comment node = | ||
| case Node.value node of | ||
| AliasDeclaration { name } -> | ||
| if Node.value name == "Stopwatch" then | ||
| [ Comment.createError comment (Node.range name) ] | ||
|
|
||
| else | ||
| [] | ||
|
|
||
| _ -> | ||
| [] | ||
|
|
||
|
|
||
| forbidStopwatchExportAll : Comment -> Rule | ||
| forbidStopwatchExportAll comment = | ||
| Review.Rule.newModuleRuleSchema comment.path () | ||
| |> Review.Rule.withSimpleModuleDefinitionVisitor (hasStopwatchExportAllVisitor comment) | ||
| |> Review.Rule.fromModuleRuleSchema | ||
|
|
||
|
|
||
| hasStopwatchExportAllVisitor : Comment -> Node Module -> List (Error {}) | ||
| hasStopwatchExportAllVisitor comment node = | ||
| let | ||
| hasStopwatchExposed = | ||
| List.Extra.findMap | ||
| (\(Node range expose) -> | ||
| case expose of | ||
| TypeExpose { name } -> | ||
| if name == "Stopwatch" then | ||
| Just range | ||
|
|
||
| else | ||
| Nothing | ||
|
|
||
| _ -> | ||
| Nothing | ||
| ) | ||
|
|
||
| checkExposing exposingList = | ||
| case Node.value exposingList of | ||
| Exposing.All _ -> | ||
| [] | ||
|
|
||
| Exposing.Explicit exposed -> | ||
| case hasStopwatchExposed exposed of | ||
| Just range -> | ||
| [ Comment.createError comment range ] | ||
|
|
||
| Nothing -> | ||
| [] | ||
| in | ||
| case Node.value node of | ||
| NormalModule { exposingList } -> | ||
| checkExposing exposingList | ||
|
|
||
| PortModule { exposingList } -> | ||
| checkExposing exposingList | ||
|
|
||
| EffectModule { exposingList } -> | ||
| checkExposing exposingList | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ tests = | |
| describe "BettysBikeShopTest" | ||
| [ exemplar | ||
| , otherSolutions | ||
| , noFuctionSignature | ||
| , noFunctionSignature | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like these are whitespace changes, but probably better to remove them from the PR
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a fly-by typo fix. "Fuction" was missing its N. I'll leave it in. |
||
| , noImportString | ||
| ] | ||
|
|
||
|
|
@@ -103,8 +103,8 @@ addPoundsSymbol = | |
| ] | ||
|
|
||
|
|
||
| noFuctionSignature : Test | ||
| noFuctionSignature = | ||
| noFunctionSignature : Test | ||
| noFunctionSignature = | ||
| let | ||
| comment = | ||
| Comment "elm.bettys-bike-shop.use_signature" Essential Dict.empty | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might we want to make helper functions for these for future rules?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do it when we have a second use case for it