mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-12-25 02:34:36 +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 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" ]
|
|
||||||
|
@ -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." ]
|
||||||
|
Loading…
Reference in New Issue
Block a user