Report stray classes

This commit is contained in:
Jeroen Engels 2024-03-23 21:55:51 +01:00
parent 7c2a0ff76b
commit 076884b912
2 changed files with 28 additions and 1 deletions

View File

@ -329,10 +329,37 @@ expressionVisitor cssFunctions node context =
Expression.OperatorApplication "<|" _ (Node fnRange (Expression.FunctionOrValue _ name)) firstArg ->
reportClasses cssFunctions context fnRange name firstArg []
Expression.FunctionOrValue _ name ->
( reportStrayCssFunction cssFunctions context (Node.range node) name
, context
)
_ ->
( [], context )
reportStrayCssFunction : CssFunctions -> ModuleContext -> Range -> String -> List (Rule.Error {})
reportStrayCssFunction cssFunctions context range name =
if RangeDict.member range context.functionOrValuesToIgnore then
[]
else
case
ModuleNameLookupTable.moduleNameAt context.lookupTable range
|> Maybe.andThen (\moduleName -> Dict.get ( moduleName, name ) cssFunctions)
of
Just _ ->
[ Rule.error
{ message = "Class using function is used without all of its class arguments"
, details = [ "REPLACEME" ]
}
range
]
Nothing ->
[]
type alias CssFunctions =
Dict
( ModuleName, String )

View File

@ -252,7 +252,7 @@ classListWithoutErrorsBeingReported =
|> Review.Test.run (cssFiles [ "*.css" ] |> rule)
|> Review.Test.expectErrors
[ Review.Test.error
{ message = "Class using function is used without all of its class functions"
{ message = "Class using function is used without all of its class arguments"
, details = [ "REPLACEME" ]
, under = "Html.Attributes.classList"
}