From 6039aed3e83a0f3dd2f2ed41fa81a4058d255bd7 Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Sat, 23 Mar 2024 09:38:09 +0100 Subject: [PATCH] Take globs by default --- tests/NoUnknownCssClasses.elm | 13 ++++--------- tests/NoUnknownCssClassesTest.elm | 26 +++++++++++++------------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/tests/NoUnknownCssClasses.elm b/tests/NoUnknownCssClasses.elm index f82a9b65..72bab40f 100644 --- a/tests/NoUnknownCssClasses.elm +++ b/tests/NoUnknownCssClasses.elm @@ -1,6 +1,6 @@ module NoUnknownCssClasses exposing ( rule - , CssArgument(..), defaults, fromLiteral, withCssFiles, withCssUsingFunctions, withHardcodedKnownClasses + , CssArgument(..), cssFiles, fromLiteral, withCssUsingFunctions, withHardcodedKnownClasses ) {-| @@ -77,11 +77,11 @@ type Configuration } -defaults : Configuration -defaults = +cssFiles : List String -> Configuration +cssFiles globs = Configuration { knownClasses = Set.empty - , cssFiles = [] + , cssFiles = globs , cssFunctions = baseCssFunctions } @@ -110,11 +110,6 @@ withCssUsingFunctions newFunctions (Configuration configuration) = Configuration { configuration | cssFunctions = Dict.union newFunctions configuration.cssFunctions } -withCssFiles : List String -> Configuration -> Configuration -withCssFiles list (Configuration configuration) = - Configuration { configuration | cssFiles = list ++ configuration.cssFiles } - - type alias ProjectContext = { knownClasses : Set String } diff --git a/tests/NoUnknownCssClassesTest.elm b/tests/NoUnknownCssClassesTest.elm index 0c8491ae..379bfbf7 100644 --- a/tests/NoUnknownCssClassesTest.elm +++ b/tests/NoUnknownCssClassesTest.elm @@ -3,7 +3,7 @@ module NoUnknownCssClassesTest exposing (all) import Dict import Elm.Syntax.Expression exposing (Expression) import Elm.Syntax.Node exposing (Node) -import NoUnknownCssClasses exposing (CssArgument, defaults, fromLiteral, rule, withCssFiles, withCssUsingFunctions, withHardcodedKnownClasses) +import NoUnknownCssClasses exposing (CssArgument, cssFiles, fromLiteral, rule, withCssUsingFunctions, withHardcodedKnownClasses) import Review.Project as Project exposing (Project) import Review.Test import Review.Test.Dependencies @@ -22,7 +22,7 @@ import Html.Attributes as Attr view model = Html.span [] [ Html.text "ok" ] """ - |> Review.Test.run (rule defaults) + |> Review.Test.run (cssFiles [ "*.css" ] |> rule) |> Review.Test.expectNoErrors , test "should report an error when encountering an unknown CSS class through Html.Attributes.class" <| \() -> @@ -33,7 +33,7 @@ import Html.Attributes as Attr view model = Html.span [ Attr.class "unknown" ] [] """ - |> Review.Test.run (defaults |> withHardcodedKnownClasses [ "known", "bar", "unknown2" ] |> rule) + |> Review.Test.run (cssFiles [ "*.css" ] |> withHardcodedKnownClasses [ "known", "bar", "unknown2" ] |> rule) |> Review.Test.expectErrors [ Review.Test.error { message = "Unknown CSS class \"unknown\"" @@ -53,7 +53,7 @@ import Html.Attributes as Attr view model = Html.span [ Attr.class "known" ] [] """ - |> Review.Test.run (defaults |> withHardcodedKnownClasses [ "known" ] |> rule) + |> Review.Test.run (cssFiles [ "*.css" ] |> withHardcodedKnownClasses [ "known" ] |> rule) |> Review.Test.expectNoErrors , test "should report an error when encountering an unknown CSS class through Html.Attributes.class in <| pipe" <| \() -> @@ -64,7 +64,7 @@ import Html.Attributes as Attr view model = Html.span [ Attr.class <| "unknown" ] [] """ - |> Review.Test.run (rule defaults) + |> Review.Test.run (cssFiles [ "*.css" ] |> rule) |> Review.Test.expectErrors [ Review.Test.error { message = "Unknown CSS class \"unknown\"" @@ -81,7 +81,7 @@ import Html.Attributes as Attr view model = Html.span [ "unknown" |> Attr.class ] [] """ - |> Review.Test.run (rule defaults) + |> Review.Test.run (cssFiles [ "*.css" ] |> rule) |> Review.Test.expectErrors [ Review.Test.error { message = "Unknown CSS class \"unknown\"" @@ -98,7 +98,7 @@ import Html.Attributes as Attr view model = Html.span [ "known red-faint under_score" |> Attr.class ] [] """ - |> Review.Test.runWithProjectData projectWithCssClasses (defaults |> withCssFiles [ "*.css" ] |> rule) + |> Review.Test.runWithProjectData projectWithCssClasses (cssFiles [ "*.css" ] |> rule) |> Review.Test.expectNoErrors , test "should report an error when encountering a non-literal argument for Html.Attributes.class" <| \() -> @@ -109,7 +109,7 @@ import Html.Attributes as Attr view model = Attr.class model.class """ - |> Review.Test.run (rule defaults) + |> Review.Test.run (cssFiles [ "*.css" ] |> rule) |> Review.Test.expectErrors [ Review.Test.error { message = "Non-literal argument to CSS class function" @@ -126,7 +126,7 @@ import Html.Attributes as Attr view model = Attr.classList model.classList """ - |> Review.Test.run (rule defaults) + |> Review.Test.run (cssFiles [ "*.css" ] |> rule) |> Review.Test.expectErrors [ Review.Test.error { message = "Non-literal argument to CSS class function" @@ -146,7 +146,7 @@ view model = , ( variable, model.b ) ] """ - |> Review.Test.run (defaults |> withHardcodedKnownClasses [ "known" ] |> rule) + |> Review.Test.run (cssFiles [ "*.css" ] |> withHardcodedKnownClasses [ "known" ] |> rule) |> Review.Test.expectErrors [ Review.Test.error { message = "Non-literal argument to CSS class function" @@ -163,7 +163,7 @@ view model = Class.fromString "known" """ |> Review.Test.run - (defaults + (cssFiles [ "*.css" ] |> withHardcodedKnownClasses [ "known" ] |> withCssUsingFunctions (Dict.fromList [ ( ( [ "Class" ], "fromString" ), classFromAttrFunction ) ]) |> rule @@ -178,7 +178,7 @@ view model = Class.fromString model.a """ |> Review.Test.run - (defaults + (cssFiles [ "*.css" ] |> withHardcodedKnownClasses [ "known" ] |> withCssUsingFunctions (Dict.fromList [ ( ( [ "Class" ], "fromString" ), classFromAttrFunction ) ]) |> rule @@ -198,7 +198,7 @@ import Class view model = Class.fromString model.a """ - |> Review.Test.runWithProjectData projectWithUnparsableCssClasses (defaults |> withCssFiles [ "*.css" ] |> rule) + |> Review.Test.runWithProjectData projectWithUnparsableCssClasses (cssFiles [ "*.css" ] |> rule) |> Review.Test.expectErrorsForModules [ ( "some-file.css" , [ Review.Test.error