diff --git a/src/Review/ModuleNameLookupTable.elm b/src/Review/ModuleNameLookupTable.elm index 41beddb5..916892b8 100644 --- a/src/Review/ModuleNameLookupTable.elm +++ b/src/Review/ModuleNameLookupTable.elm @@ -1,8 +1,11 @@ -module Review.ModuleNameLookupTable exposing (..) +module Review.ModuleNameLookupTable exposing + ( ModuleNameLookupTable + , moduleNameFor + ) import Dict import Elm.Syntax.ModuleName exposing (ModuleName) -import Elm.Syntax.Range exposing (Range) +import Elm.Syntax.Node exposing (Node(..)) import Review.ModuleNameLookupTable.Internal as Internal @@ -10,7 +13,6 @@ type alias ModuleNameLookupTable = Internal.ModuleNameLookupTable -moduleName : ModuleNameLookupTable -> Range -> ModuleName -moduleName (Internal.ModuleNameLookupTable dict) range = +moduleNameFor : ModuleNameLookupTable -> Node a -> Maybe ModuleName +moduleNameFor (Internal.ModuleNameLookupTable dict) (Node range _) = Dict.get (Internal.toRangeLike range) dict - |> Maybe.withDefault [ "UNKNOWN" ] diff --git a/tests/MiscRules/NoHtmlButton.elm b/tests/MiscRules/NoHtmlButton.elm index d69d0503..c18eea82 100644 --- a/tests/MiscRules/NoHtmlButton.elm +++ b/tests/MiscRules/NoHtmlButton.elm @@ -2,7 +2,7 @@ module MiscRules.NoHtmlButton exposing (rule) import Elm.Syntax.Expression exposing (Expression(..)) import Elm.Syntax.Node as Node exposing (Node) -import Review.ModuleNameLookupTable exposing (ModuleNameLookupTable) +import Review.ModuleNameLookupTable as ModuleNameLookupTable exposing (ModuleNameLookupTable) import Review.Rule as Rule exposing (Error, Rule) import Scope @@ -38,8 +38,10 @@ contextCreator = expressionVisitor : Node Expression -> Context -> ( List (Error {}), Context ) expressionVisitor node context = case Node.value node of - FunctionOrValue moduleName "button" -> - if Scope.moduleNameForValue context.scope "button" moduleName == [ "Html" ] then + FunctionOrValue _ "button" -> + if ModuleNameLookupTable.moduleNameFor context.moduleNameLookupTable node == Just [ "Html" ] then + -- TODO Remove + --if Scope.moduleNameForValue context.scope "button" moduleName == [ "Html" ] then ( [ Rule.error { message = "Do not use `Html.button` directly" , details = [ "At fruits.com, we've built a nice `Button` module that suits our needs better. Using this module instead of `Html.button` ensures we have a consistent button experience across the website." ]