mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-11-23 14:55:35 +03:00
Add elements in the lookup table
This commit is contained in:
parent
08a3cbf7a7
commit
3e85e3709a
1221
src/Review/Rule.elm
1221
src/Review/Rule.elm
File diff suppressed because it is too large
Load Diff
@ -4,23 +4,18 @@ import Elm.Syntax.Expression exposing (Expression(..))
|
||||
import Elm.Syntax.Node as Node exposing (Node)
|
||||
import Review.ModuleNameLookupTable as ModuleNameLookupTable exposing (ModuleNameLookupTable)
|
||||
import Review.Rule as Rule exposing (Error, Rule)
|
||||
import Scope
|
||||
|
||||
|
||||
rule : Rule
|
||||
rule =
|
||||
Rule.newModuleRuleSchemaUsingContextCreator "NoHtmlButton" contextCreator
|
||||
-- Scope.addModuleVisitors should be added before your own visitors
|
||||
--|> Scope.addModuleVisitors
|
||||
|> Rule.withExpressionEnterVisitor expressionVisitor
|
||||
|> Rule.fromModuleRuleSchema
|
||||
|> Rule.ignoreErrorsForFiles [ "src/Button.elm" ]
|
||||
|
||||
|
||||
type alias Context =
|
||||
-- Scope expects a context with a record, containing the `scope` field.
|
||||
{ scope : Scope.ModuleContext
|
||||
, moduleNameLookupTable : ModuleNameLookupTable
|
||||
{ moduleNameLookupTable : ModuleNameLookupTable
|
||||
}
|
||||
|
||||
|
||||
@ -28,8 +23,7 @@ contextCreator : Rule.ContextCreator () Context
|
||||
contextCreator =
|
||||
Rule.initContextCreator
|
||||
(\moduleNameLookupTable () ->
|
||||
{ scope = Scope.initialModuleContext
|
||||
, moduleNameLookupTable = moduleNameLookupTable
|
||||
{ moduleNameLookupTable = moduleNameLookupTable
|
||||
}
|
||||
)
|
||||
|> Rule.withModuleNameLookupTable
|
||||
@ -40,8 +34,6 @@ expressionVisitor node context =
|
||||
case Node.value node of
|
||||
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." ]
|
||||
|
@ -48,20 +48,19 @@ b = Foo.bar 1
|
||||
c = baz
|
||||
"""
|
||||
|> Review.Test.expectNoErrors
|
||||
, Test.only <|
|
||||
test "should report the use of `Html.button` as an expression" <|
|
||||
\() ->
|
||||
testRule """
|
||||
, test "should report the use of `Html.button` as an expression" <|
|
||||
\() ->
|
||||
testRule """
|
||||
import Html
|
||||
a = Html.button
|
||||
"""
|
||||
|> Review.Test.expectErrors
|
||||
[ Review.Test.error
|
||||
{ message = message
|
||||
, details = details
|
||||
, under = "Html.button"
|
||||
}
|
||||
]
|
||||
|> Review.Test.expectErrors
|
||||
[ Review.Test.error
|
||||
{ message = message
|
||||
, details = details
|
||||
, under = "Html.button"
|
||||
}
|
||||
]
|
||||
, test "should report the use of `Html.button` even if it is not imported" <|
|
||||
\() ->
|
||||
testRule """
|
||||
|
@ -882,7 +882,7 @@ registerImportAlias import_ innerContext =
|
||||
{ innerContext
|
||||
| importAliases =
|
||||
Dict.update
|
||||
(Node.value alias_ |> getModuleName)
|
||||
(Node.value alias_ |> joinModuleName)
|
||||
(\previousValue -> Just <| Node.value import_.moduleName :: Maybe.withDefault [] previousValue)
|
||||
innerContext.importAliases
|
||||
}
|
||||
@ -902,7 +902,7 @@ registerImportExposed import_ innerContext =
|
||||
|
||||
module_ : Elm.Docs.Module
|
||||
module_ =
|
||||
(case Dict.get (getModuleName moduleName) innerContext.dependenciesModules of
|
||||
(case Dict.get (joinModuleName moduleName) innerContext.dependenciesModules of
|
||||
Just m ->
|
||||
Just m
|
||||
|
||||
@ -910,7 +910,7 @@ registerImportExposed import_ innerContext =
|
||||
Dict.get moduleName innerContext.modules
|
||||
)
|
||||
|> Maybe.withDefault
|
||||
{ name = getModuleName moduleName
|
||||
{ name = joinModuleName moduleName
|
||||
, comment = ""
|
||||
, unions = []
|
||||
, values = []
|
||||
@ -1287,7 +1287,7 @@ moduleNameForValue (ModuleContext context) valueName moduleName =
|
||||
|> Maybe.withDefault []
|
||||
|
||||
_ :: [] ->
|
||||
case Dict.get (getModuleName moduleName) context.importAliases of
|
||||
case Dict.get (joinModuleName moduleName) context.importAliases of
|
||||
Just [ aliasedModuleName ] ->
|
||||
aliasedModuleName
|
||||
|
||||
@ -1337,7 +1337,7 @@ moduleNameForType (ModuleContext context) typeName moduleName =
|
||||
|> Maybe.withDefault []
|
||||
|
||||
_ :: [] ->
|
||||
case Dict.get (getModuleName moduleName) context.importAliases of
|
||||
case Dict.get (joinModuleName moduleName) context.importAliases of
|
||||
Just [ aliasedModuleName ] ->
|
||||
aliasedModuleName
|
||||
|
||||
@ -1392,8 +1392,8 @@ isInScope name scopes =
|
||||
-- MISC
|
||||
|
||||
|
||||
getModuleName : List String -> String
|
||||
getModuleName name =
|
||||
joinModuleName : List String -> String
|
||||
joinModuleName name =
|
||||
String.join "." name
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user