Skip to content

Commit

Permalink
the only imports we care about are Html and Html.Extra
Browse files Browse the repository at this point in the history
  • Loading branch information
perkee committed Feb 6, 2025
1 parent 197651d commit 5c2c2a2
Showing 1 changed file with 55 additions and 48 deletions.
103 changes: 55 additions & 48 deletions src/UseHtmlExtraNothing.elm
Original file line number Diff line number Diff line change
Expand Up @@ -81,37 +81,35 @@ type Exposed
| SomeExposed (List String)


toImportContext : Import -> ( List String, ImportContext )
toImportContext : Import -> ImportContext
toImportContext import_ =
( import_.moduleName |> Node.value
, { moduleName = import_.moduleName |> Node.value
, moduleAlias = import_.moduleAlias |> Maybe.map Node.value
, exposedFunctions =
import_.exposingList
|> Maybe.map Node.value
|> Maybe.map
(\exposingList ->
case exposingList of
Elm.Syntax.Exposing.All _ ->
AllExposed

Elm.Syntax.Exposing.Explicit nodes ->
List.filterMap
(\exposition ->
case Node.value exposition of
Elm.Syntax.Exposing.FunctionExpose s ->
Just s

_ ->
-- we do not care about exposed types, aliases, or infixes.
Nothing
)
nodes
|> SomeExposed
)
|> Maybe.withDefault (SomeExposed [])
}
)
{ moduleName = import_.moduleName |> Node.value
, moduleAlias = import_.moduleAlias |> Maybe.map Node.value
, exposedFunctions =
import_.exposingList
|> Maybe.map Node.value
|> Maybe.map
(\exposingList ->
case exposingList of
Elm.Syntax.Exposing.All _ ->
AllExposed

Elm.Syntax.Exposing.Explicit nodes ->
List.filterMap
(\exposition ->
case Node.value exposition of
Elm.Syntax.Exposing.FunctionExpose s ->
Just s

_ ->
-- we do not care about exposed types, aliases, or infixes.
Nothing
)
nodes
|> SomeExposed
)
|> Maybe.withDefault (SomeExposed [])
}


initialContext : Rule.ContextCreator () Context
Expand All @@ -129,26 +127,35 @@ initialContext =
importVisitor : Node Import -> Context -> ( List (Rule.Error {}), Context )
importVisitor node context =
let
( key, value ) =
value =
Node.value node
|> toImportContext

moduleName =
Node.value value.moduleName
in
( []
, { context
| importContext =
context.importContext |> Dict.insert key value
, firstImport =
case ( context.firstImport, key ) of
( _, [ "Html" ] ) ->
Just (Node.range node)

( Nothing, _ ) ->
Just (Node.range node)

( Just _, _ ) ->
context.firstImport
}
)
if moduleName == [ "Html" ] || moduleName == [ "Html", "Extra" ] then
( []
, { context
| importContext =
Dict.insert
moduleName
(toImportContext value)
context.importContext
, firstImport =
case ( context.firstImport, moduleName ) of
( _, [ "Html" ] ) ->
Just (Node.range node)

( Nothing, _ ) ->
Just (Node.range node)

( Just _, _ ) ->
context.firstImport
}
)

else
( [], context )


expressionVisitor : Node Expression -> Context -> ( List (Rule.Error {}), Context )
Expand Down

0 comments on commit 5c2c2a2

Please sign in to comment.