mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-09-11 16:16:09 +03:00
Read CSS files
This commit is contained in:
parent
c9f3524885
commit
6ed6b6e4d3
@ -1,6 +1,6 @@
|
||||
module NoUnknownCssClasses exposing
|
||||
( rule
|
||||
, defaults, withHardcodedKnownClasses
|
||||
, defaults, withCssFiles, withHardcodedKnownClasses
|
||||
)
|
||||
|
||||
{-|
|
||||
@ -56,26 +56,34 @@ elm-review --template jfmengels/elm-review/example --rules NoUnknownCssClasses
|
||||
rule : Configuration -> Rule
|
||||
rule (Configuration configuration) =
|
||||
Rule.newProjectRuleSchema "NoUnknownCssClasses" (initialProjectContext configuration.knownClasses)
|
||||
|> Rule.withExtraFilesProjectVisitor configuration.cssFiles cssFilesVisitor
|
||||
|> Rule.withModuleVisitor moduleVisitor
|
||||
|> Rule.withModuleContextUsingContextCreator
|
||||
{ fromProjectToModule = fromProjectToModule
|
||||
, fromModuleToProject = fromModuleToProject
|
||||
, foldProjectContexts = foldProjectContexts
|
||||
}
|
||||
-- Enable this if modules need to get information from other modules
|
||||
-- |> Rule.withContextFromImportedModules
|
||||
|> Rule.fromProjectRuleSchema
|
||||
|
||||
|
||||
type Configuration
|
||||
= Configuration
|
||||
{ knownClasses : Set String
|
||||
, cssFiles : List String
|
||||
}
|
||||
|
||||
|
||||
defaults : Configuration
|
||||
defaults =
|
||||
Configuration { knownClasses = Set.empty }
|
||||
Configuration
|
||||
{ knownClasses = Set.empty
|
||||
, cssFiles = []
|
||||
}
|
||||
|
||||
|
||||
cssFilesVisitor : List { fileKey : Rule.ExtraFileKey, path : String, content : String } -> ProjectContext -> ( List empty, ProjectContext )
|
||||
cssFilesVisitor files context =
|
||||
( [], context )
|
||||
|
||||
|
||||
withHardcodedKnownClasses : List String -> Configuration -> Configuration
|
||||
@ -83,6 +91,11 @@ withHardcodedKnownClasses list (Configuration configuration) =
|
||||
Configuration { configuration | knownClasses = List.foldl Set.insert configuration.knownClasses list }
|
||||
|
||||
|
||||
withCssFiles : List String -> Configuration -> Configuration
|
||||
withCssFiles list (Configuration configuration) =
|
||||
Configuration { configuration | cssFiles = list ++ configuration.cssFiles }
|
||||
|
||||
|
||||
type alias ProjectContext =
|
||||
{ knownClasses : Set String
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
module NoUnknownCssClassesTest exposing (all)
|
||||
|
||||
import NoUnknownCssClasses exposing (defaults, rule, withHardcodedKnownClasses)
|
||||
import NoUnknownCssClasses exposing (defaults, rule, withCssFiles, withHardcodedKnownClasses)
|
||||
import Review.Project as Project exposing (Project)
|
||||
import Review.Test
|
||||
import Review.Test.Dependencies
|
||||
import Test exposing (Test, describe, test)
|
||||
|
||||
|
||||
@ -81,4 +83,32 @@ view model =
|
||||
, under = "unknown"
|
||||
}
|
||||
]
|
||||
, test "should not report an error when encountering CSS classes found in specified files" <|
|
||||
\() ->
|
||||
"""module A exposing (..)
|
||||
import Html
|
||||
import Html.Attributes as Attr
|
||||
|
||||
view model =
|
||||
Html.span [ "known red" |> Attr.class ] []
|
||||
"""
|
||||
|> Review.Test.runWithProjectData projectWithCssClasses (defaults |> withCssFiles [ "*.css" ] |> rule)
|
||||
|> Review.Test.expectNoErrors
|
||||
]
|
||||
|
||||
|
||||
projectWithCssClasses : Project
|
||||
projectWithCssClasses =
|
||||
Project.addExtraFiles
|
||||
[ { path = "some-file.css"
|
||||
, content = """
|
||||
.known {
|
||||
color: blue;
|
||||
}
|
||||
.red {
|
||||
color: red;
|
||||
}
|
||||
"""
|
||||
}
|
||||
]
|
||||
Review.Test.Dependencies.projectWithElmCore
|
||||
|
Loading…
Reference in New Issue
Block a user