Skip to content
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
8 changes: 4 additions & 4 deletions .github/workflows/elm_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
# Re-use node_modules between runs until package.json or package-lock.json changes.
- name: Cache node_modules
id: cache-node_modules
uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7
uses: actions/cache@7de21022a7b6824c106a9847befcbd8154b45b6a
with:
path: node_modules
key: node_modules-${{ hashFiles('package.json', 'package-lock.json') }}
Expand All @@ -28,7 +28,7 @@ jobs:
# review/elm.json changes. The Elm compiler saves downloaded Elm packages
# to ~/.elm, and elm-tooling saves downloaded tool executables there.
- name: Cache ~/.elm
uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7
uses: actions/cache@7de21022a7b6824c106a9847befcbd8154b45b6a
with:
path: ~/.elm
key: elm-${{ hashFiles('elm-tooling.json', 'elm.json', 'review/elm.json') }}
Expand Down Expand Up @@ -83,7 +83,7 @@ jobs:

- name: Cache node_modules
id: cache-node_modules
uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7
uses: actions/cache@7de21022a7b6824c106a9847befcbd8154b45b6a
with:
path: node_modules
key: node_modules-${{ hashFiles('package.json', 'package-lock.json') }}
Expand All @@ -92,7 +92,7 @@ jobs:
node_modules-

- name: Cache ~/.elm
uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7
uses: actions/cache@7de21022a7b6824c106a9847befcbd8154b45b6a
with:
path: ~/.elm
key: elm-${{ hashFiles('elm-tooling.json', 'elm.json', 'review/elm.json') }}
Expand Down
93 changes: 93 additions & 0 deletions src/Exercise/SplitSecondStopwatch.elm
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 {})
Copy link
Contributor

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?

Copy link
Contributor Author

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

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
2 changes: 2 additions & 0 deletions src/ReviewConfig.elm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Exercise.MariosMarvellousLasagna
import Exercise.MazeMaker
import Exercise.RolePlayingGame
import Exercise.Sieve
import Exercise.SplitSecondStopwatch
import Exercise.Strain
import Exercise.TicketPlease
import Exercise.TisburyTreasureHunt
Expand Down Expand Up @@ -63,6 +64,7 @@ ruleConfigs =
, Exercise.ListOps.ruleConfig
, Exercise.ZebraPuzzle.ruleConfig
, Exercise.Sieve.ruleConfig
, Exercise.SplitSecondStopwatch.ruleConfig
]


Expand Down
6 changes: 3 additions & 3 deletions tests/Exercise/BettysBikeShopTest.elm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tests =
describe "BettysBikeShopTest"
[ exemplar
, otherSolutions
, noFuctionSignature
, noFunctionSignature
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
]

Expand Down Expand Up @@ -103,8 +103,8 @@ addPoundsSymbol =
]


noFuctionSignature : Test
noFuctionSignature =
noFunctionSignature : Test
noFunctionSignature =
let
comment =
Comment "elm.bettys-bike-shop.use_signature" Essential Dict.empty
Expand Down
Loading