mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-12-24 18:23:09 +03:00
Use lookup table
This commit is contained in:
parent
988a543f87
commit
2b12cebd9c
@ -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" ]
|
||||
|
@ -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." ]
|
||||
|
Loading…
Reference in New Issue
Block a user