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 Dict
import Elm.Syntax.ModuleName exposing (ModuleName) import Elm.Syntax.ModuleName exposing (ModuleName)
import Elm.Syntax.Range exposing (Range) import Elm.Syntax.Node exposing (Node(..))
import Review.ModuleNameLookupTable.Internal as Internal import Review.ModuleNameLookupTable.Internal as Internal
@ -10,7 +13,6 @@ type alias ModuleNameLookupTable =
Internal.ModuleNameLookupTable Internal.ModuleNameLookupTable
moduleName : ModuleNameLookupTable -> Range -> ModuleName moduleNameFor : ModuleNameLookupTable -> Node a -> Maybe ModuleName
moduleName (Internal.ModuleNameLookupTable dict) range = moduleNameFor (Internal.ModuleNameLookupTable dict) (Node range _) =
Dict.get (Internal.toRangeLike range) dict 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.Expression exposing (Expression(..))
import Elm.Syntax.Node as Node exposing (Node) 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 Review.Rule as Rule exposing (Error, Rule)
import Scope import Scope
@ -38,8 +38,10 @@ contextCreator =
expressionVisitor : Node Expression -> Context -> ( List (Error {}), Context ) expressionVisitor : Node Expression -> Context -> ( List (Error {}), Context )
expressionVisitor node context = expressionVisitor node context =
case Node.value node of case Node.value node of
FunctionOrValue moduleName "button" -> FunctionOrValue _ "button" ->
if Scope.moduleNameForValue context.scope "button" moduleName == [ "Html" ] then if ModuleNameLookupTable.moduleNameFor context.moduleNameLookupTable node == Just [ "Html" ] then
-- TODO Remove
--if Scope.moduleNameForValue context.scope "button" moduleName == [ "Html" ] then
( [ Rule.error ( [ Rule.error
{ message = "Do not use `Html.button` directly" { 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." ] , 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." ]