From 66ee143b087b32a95eb37d1c6cd6b1f06658e8cb Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Tue, 20 Dec 2022 21:52:59 +0100 Subject: [PATCH] Fix withIsFileIgnored returning the wrong value --- src/Review/Rule.elm | 2 +- tests/Review/Rule/IgnoredFilesTest.elm | 73 ++++++++++++++++++++++++-- 2 files changed, 71 insertions(+), 4 deletions(-) diff --git a/src/Review/Rule.elm b/src/Review/Rule.elm index c2ec05a2..804b5a68 100644 --- a/src/Review/Rule.elm +++ b/src/Review/Rule.elm @@ -5079,7 +5079,7 @@ computeModuleAndCacheResult dataToComputeModules inputProjectContext moduleZippe isFileIgnored : Bool isFileIgnored = - Exceptions.isFileWeWantReportsFor dataToComputeModules.exceptions module_.path + not (Exceptions.isFileWeWantReportsFor dataToComputeModules.exceptions module_.path) in if reuseCache diff --git a/tests/Review/Rule/IgnoredFilesTest.elm b/tests/Review/Rule/IgnoredFilesTest.elm index 64a844a5..b1fb7476 100644 --- a/tests/Review/Rule/IgnoredFilesTest.elm +++ b/tests/Review/Rule/IgnoredFilesTest.elm @@ -1,9 +1,12 @@ -module Review.Rule.IgnoredFilesTest exposing (all) +module Review.Rule.IgnoredFilesTest exposing (ignoreFilesTests, isFileIgnoredTests) +import Elm.Syntax.ModuleName exposing (ModuleName) import Elm.Syntax.Node as Node +import Json.Encode as Encode import Review.Project import Review.Rule as Rule exposing (Rule) import Review.Test +import Set exposing (Set) import Test exposing (Test, describe, test) @@ -47,8 +50,8 @@ projectRule = |> Rule.fromProjectRuleSchema -all : Test -all = +ignoreFilesTests : Test +ignoreFilesTests = describe "should ignore files" [ test "Using ignoreErrorsForFiles" <| \() -> @@ -178,3 +181,67 @@ a = () ) ] ] + + +isFileIgnoredTests : Test +isFileIgnoredTests = + test "Rule.withIsFileIgnored" <| + \() -> + [ """module A exposing (a) +a = () +""" ] + |> Review.Test.runOnModulesWithProjectData + (Review.Project.new + |> Review.Project.addModule { path = "src/B.elm", source = """ +module B exposing (a) +a = () +""" } + |> Review.Project.addModule { path = "src-ignored/C.elm", source = """ +module C exposing (a) +a = () +""" } + |> Review.Project.addModule { path = "tests/D.elm", source = """ +module D exposing (a) +a = () +""" } + |> Review.Project.addModule { path = "tests/E.elm", source = """ +module E exposing (a) +a = () +""" } + |> Review.Project.addModule { path = "src-other-ignored/folder/F.elm", source = """ +module F exposing (a) +a = () +""" } + ) + (ruleThatListsIgnoredFiles + |> Rule.ignoreErrorsForDirectories [ "src-ignored/", "tests" ] + |> Rule.ignoreErrorsForDirectories [ "src-other-ignored\\folder\\" ] + ) + |> Review.Test.expectDataExtract """["C", "D", "E", "F"]""" + + +ruleThatListsIgnoredFiles : Rule +ruleThatListsIgnoredFiles = + Rule.newProjectRuleSchema "ListIgnoredFiles" Set.empty + |> Rule.withModuleVisitor (Rule.withSimpleExpressionVisitor (always [])) + |> Rule.withModuleContextUsingContextCreator + { fromProjectToModule = Rule.initContextCreator (\_ -> ()) + , fromModuleToProject = fromModuleToProject + , foldProjectContexts = Set.union + } + |> Rule.withDataExtractor (\set -> set |> Set.toList |> List.sort |> Encode.list (String.join "." >> Encode.string)) + |> Rule.fromProjectRuleSchema + + +fromModuleToProject : Rule.ContextCreator () (Set ModuleName) +fromModuleToProject = + Rule.initContextCreator + (\moduleName isIgnored () -> + if isIgnored then + Set.singleton moduleName + + else + Set.empty + ) + |> Rule.withModuleName + |> Rule.withIsFileIgnored