Use lookup table

This commit is contained in:
Jeroen Engels 2020-08-19 23:38:27 +02:00
parent 988a543f87
commit 2b12cebd9c
2 changed files with 12 additions and 8 deletions

View File

@ -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" ]

View File

@ -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." ]