diff --git a/tests/Docs/ReviewLinksAndSections.elm b/tests/Docs/ReviewLinksAndSections.elm index 25ed9530..e8ccbd25 100644 --- a/tests/Docs/ReviewLinksAndSections.elm +++ b/tests/Docs/ReviewLinksAndSections.elm @@ -192,12 +192,7 @@ type alias MaybeExposedLinkData = fromProjectToModule : Rule.ContextCreator ProjectContext ModuleContext fromProjectToModule = Rule.initContextCreator - (\metadata projectContext -> - let - moduleName : ModuleName - moduleName = - Rule.moduleNameFromMetadata metadata - in + (\moduleName projectContext -> { isModuleExposed = Set.member moduleName projectContext.exposedModules , exposedElements = Set.empty , moduleName = moduleName @@ -206,7 +201,7 @@ fromProjectToModule = , links = [] } ) - |> Rule.withMetadata + |> Rule.withModuleName fromModuleToProject : Rule.ContextCreator ModuleContext ProjectContext diff --git a/tests/NoDeprecated.elm b/tests/NoDeprecated.elm index 368afd7a..22eeaa05 100644 --- a/tests/NoDeprecated.elm +++ b/tests/NoDeprecated.elm @@ -158,12 +158,7 @@ type DeprecationReason fromProjectToModule : StableConfiguration -> Rule.ContextCreator ProjectContext ModuleContext fromProjectToModule (StableConfiguration configuration) = Rule.initContextCreator - (\metadata lookupTable projectContext -> - let - moduleName : ModuleName - moduleName = - Rule.moduleNameFromMetadata metadata - in + (\moduleName lookupTable projectContext -> { lookupTable = lookupTable , currentModuleName = moduleName , deprecatedModules = Dict.fromList projectContext.deprecatedModules @@ -172,24 +167,24 @@ fromProjectToModule (StableConfiguration configuration) = , localDeprecatedElements = [] } ) - |> Rule.withMetadata + |> Rule.withModuleName |> Rule.withModuleNameLookupTable fromModuleToProject : Rule.ContextCreator ModuleContext ProjectContext fromModuleToProject = Rule.initContextCreator - (\metadata moduleContext -> + (\moduleName moduleContext -> { deprecatedModules = if moduleContext.isModuleDeprecated then - [ ( Rule.moduleNameFromMetadata metadata, DeprecatedModule ) ] + [ ( moduleName, DeprecatedModule ) ] else [] , deprecatedElements = moduleContext.localDeprecatedElements } ) - |> Rule.withMetadata + |> Rule.withModuleName foldProjectContexts : ProjectContext -> ProjectContext -> ProjectContext diff --git a/tests/NoMissingSubscriptionsCall.elm b/tests/NoMissingSubscriptionsCall.elm index 30f30c0d..bddacb05 100644 --- a/tests/NoMissingSubscriptionsCall.elm +++ b/tests/NoMissingSubscriptionsCall.elm @@ -122,16 +122,16 @@ fromProjectToModule = fromModuleToProject : Rule.ContextCreator ModuleContext ProjectContext fromModuleToProject = Rule.initContextCreator - (\metadata moduleContext -> + (\moduleName moduleContext -> { modulesThatExposeSubscriptionsAndUpdate = if moduleContext.definesSubscriptions && moduleContext.definesUpdate then - Set.singleton (Rule.moduleNameFromMetadata metadata) + Set.singleton moduleName else Set.empty } ) - |> Rule.withMetadata + |> Rule.withModuleName foldProjectContexts : ProjectContext -> ProjectContext -> ProjectContext diff --git a/tests/NoMissingTypeExpose.elm b/tests/NoMissingTypeExpose.elm index fbcc72c5..0eb28b8e 100644 --- a/tests/NoMissingTypeExpose.elm +++ b/tests/NoMissingTypeExpose.elm @@ -610,11 +610,11 @@ formatTypeName ( moduleName, name ) = fromProjectToModuleContext : Rule.ContextCreator ProjectContext ModuleContext fromProjectToModuleContext = Rule.initContextCreator - (\lookupTable metadata { exposedModules, moduleTypes } -> + (\lookupTable moduleName { exposedModules, moduleTypes } -> let moduleType : ModuleType moduleType = - if isModuleExposed exposedModules (Rule.moduleNameFromMetadata metadata) then + if isModuleExposed exposedModules moduleName then initialExposedModuleType exposedModules moduleTypes else @@ -626,21 +626,21 @@ fromProjectToModuleContext = } ) |> Rule.withModuleNameLookupTable - |> Rule.withMetadata + |> Rule.withModuleName fromModuleToProjectContext : Rule.ContextCreator ModuleContext ProjectContext fromModuleToProjectContext = Rule.initContextCreator - (\metadata context -> + (\moduleName context -> case context.moduleType of InternalModule { exposedTypes } -> - { initialProjectContext | moduleTypes = Dict.singleton (Rule.moduleNameFromMetadata metadata) exposedTypes } + { initialProjectContext | moduleTypes = Dict.singleton moduleName exposedTypes } ExposedModule _ -> initialProjectContext ) - |> Rule.withMetadata + |> Rule.withModuleName foldProjectContexts : ProjectContext -> ProjectContext -> ProjectContext diff --git a/tests/NoTestValuesInProductionCode.elm b/tests/NoTestValuesInProductionCode.elm index ce758fa8..359aa898 100644 --- a/tests/NoTestValuesInProductionCode.elm +++ b/tests/NoTestValuesInProductionCode.elm @@ -130,12 +130,12 @@ type alias Context = initialContext : Rule.ContextCreator () Context initialContext = Rule.initContextCreator - (\metadata () -> + (\isInSourceDirectories () -> { inDeclarationOfNonTestValue = False - , isInSourceDirectories = Rule.isInSourceDirectories metadata + , isInSourceDirectories = isInSourceDirectories } ) - |> Rule.withMetadata + |> Rule.withIsInSourceDirectories diff --git a/tests/NoUnsafeRegexFromLiteral.elm b/tests/NoUnsafeRegexFromLiteral.elm index c6b29e4c..ab39c9fb 100644 --- a/tests/NoUnsafeRegexFromLiteral.elm +++ b/tests/NoUnsafeRegexFromLiteral.elm @@ -195,11 +195,11 @@ fromProjectToModule = fromModuleToProject : Target -> Rule.ContextCreator ModuleContext ProjectContext fromModuleToProject target = Rule.initContextCreator - (\metadata moduleContext -> - { foundTargetFunction = moduleContext.foundTargetFunction && (Rule.moduleNameFromMetadata metadata == target.moduleName) + (\moduleName moduleContext -> + { foundTargetFunction = moduleContext.foundTargetFunction && (moduleName == target.moduleName) } ) - |> Rule.withMetadata + |> Rule.withModuleName foldProjectContexts : ProjectContext -> ProjectContext -> ProjectContext diff --git a/tests/NoUnused/CustomTypeConstructorArgs.elm b/tests/NoUnused/CustomTypeConstructorArgs.elm index 4ad54d73..94c47371 100644 --- a/tests/NoUnused/CustomTypeConstructorArgs.elm +++ b/tests/NoUnused/CustomTypeConstructorArgs.elm @@ -159,9 +159,9 @@ initialProjectContext = fromProjectToModule : Rule.ContextCreator ProjectContext ModuleContext fromProjectToModule = Rule.initContextCreator - (\lookupTable metadata projectContext -> + (\lookupTable moduleName projectContext -> { lookupTable = lookupTable - , isModuleExposed = Set.member (Rule.moduleNameFromMetadata metadata) projectContext.exposedModules + , isModuleExposed = Set.member moduleName projectContext.exposedModules , exposed = Exposing.Explicit [] , customTypeArgs = [] , usedArguments = Dict.empty @@ -169,26 +169,26 @@ fromProjectToModule = } ) |> Rule.withModuleNameLookupTable - |> Rule.withMetadata + |> Rule.withModuleName fromModuleToProject : Rule.ContextCreator ModuleContext ProjectContext fromModuleToProject = Rule.initContextCreator - (\moduleKey metadata moduleContext -> + (\moduleKey moduleName moduleContext -> { exposedModules = Set.empty , customTypeArgs = Dict.singleton - (Rule.moduleNameFromMetadata metadata) + moduleName { moduleKey = moduleKey , args = getNonExposedCustomTypes moduleContext } - , usedArguments = replaceLocalModuleNameForDict (Rule.moduleNameFromMetadata metadata) moduleContext.usedArguments - , customTypesNotToReport = replaceLocalModuleNameForSet (Rule.moduleNameFromMetadata metadata) moduleContext.customTypesNotToReport + , usedArguments = replaceLocalModuleNameForDict moduleName moduleContext.usedArguments + , customTypesNotToReport = replaceLocalModuleNameForSet moduleName moduleContext.customTypesNotToReport } ) |> Rule.withModuleKey - |> Rule.withMetadata + |> Rule.withModuleName replaceLocalModuleNameForSet : ModuleName -> Set ( ModuleName, comparable ) -> Set ( ModuleName, comparable ) diff --git a/tests/NoUnused/CustomTypeConstructors.elm b/tests/NoUnused/CustomTypeConstructors.elm index 43209ea9..765b5819 100644 --- a/tests/NoUnused/CustomTypeConstructors.elm +++ b/tests/NoUnused/CustomTypeConstructors.elm @@ -126,8 +126,8 @@ rule phantomTypes = |> Rule.withContextFromImportedModules |> Rule.withModuleVisitor moduleVisitor |> Rule.withModuleContextUsingContextCreator - { fromProjectToModule = Rule.initContextCreator fromProjectToModule |> Rule.withModuleNameLookupTable |> Rule.withMetadata - , fromModuleToProject = Rule.initContextCreator fromModuleToProject |> Rule.withModuleKey |> Rule.withMetadata + { fromProjectToModule = fromProjectToModule + , fromModuleToProject = fromModuleToProject , foldProjectContexts = foldProjectContexts } |> Rule.withElmJsonProjectVisitor elmJsonVisitor @@ -229,115 +229,121 @@ initialProjectContext phantomTypes = } -fromProjectToModule : ModuleNameLookupTable -> Rule.Metadata -> ProjectContext -> ModuleContext -fromProjectToModule lookupTable metadata projectContext = - { lookupTable = lookupTable - , exposedCustomTypesWithConstructors = Set.empty - , isExposed = Set.member (Rule.moduleNameFromMetadata metadata |> String.join ".") projectContext.exposedModules - , exposedConstructors = projectContext.declaredConstructors - , exposesEverything = False - , declaredTypesWithConstructors = Dict.empty - , usedFunctionsOrValues = Dict.empty - , phantomVariables = projectContext.phantomVariables - , constructorsToIgnore = [] - , wasUsedInLocationThatNeedsItself = Set.empty - , wasUsedInComparisons = Set.empty - , wasUsedInOtherModules = Set.empty - , fixesForRemovingConstructor = Dict.empty - , ignoredComparisonRanges = [] - } +fromProjectToModule : Rule.ContextCreator ProjectContext ModuleContext +fromProjectToModule = + Rule.initContextCreator + (\lookupTable moduleName projectContext -> + { lookupTable = lookupTable + , exposedCustomTypesWithConstructors = Set.empty + , isExposed = Set.member (String.join "." moduleName) projectContext.exposedModules + , exposedConstructors = projectContext.declaredConstructors + , exposesEverything = False + , declaredTypesWithConstructors = Dict.empty + , usedFunctionsOrValues = Dict.empty + , phantomVariables = projectContext.phantomVariables + , constructorsToIgnore = [] + , wasUsedInLocationThatNeedsItself = Set.empty + , wasUsedInComparisons = Set.empty + , wasUsedInOtherModules = Set.empty + , fixesForRemovingConstructor = Dict.empty + , ignoredComparisonRanges = [] + } + ) + |> Rule.withModuleNameLookupTable + |> Rule.withModuleName -fromModuleToProject : Rule.ModuleKey -> Rule.Metadata -> ModuleContext -> ProjectContext -fromModuleToProject moduleKey metadata moduleContext = - let - localUsed : Set ConstructorName - localUsed = - moduleContext.usedFunctionsOrValues - |> Dict.get "" - |> Maybe.withDefault Set.empty +fromModuleToProject : Rule.ContextCreator ModuleContext ProjectContext +fromModuleToProject = + Rule.initContextCreator + (\moduleKey moduleName moduleContext -> + let + localUsed : Set ConstructorName + localUsed = + moduleContext.usedFunctionsOrValues + |> Dict.get "" + |> Maybe.withDefault Set.empty - localPhantomTypes : List ( CustomTypeName, Int ) - localPhantomTypes = - moduleContext.phantomVariables - |> Dict.get [] - |> Maybe.withDefault [] + localPhantomTypes : List ( CustomTypeName, Int ) + localPhantomTypes = + moduleContext.phantomVariables + |> Dict.get [] + |> Maybe.withDefault [] - moduleName : ModuleName - moduleName = - Rule.moduleNameFromMetadata metadata + moduleNameAsString : ModuleNameAsString + moduleNameAsString = + String.join "." moduleName + in + { exposedModules = Set.empty + , declaredConstructors = + if moduleContext.isExposed then + if moduleContext.exposesEverything then + Dict.empty - moduleNameAsString : ModuleNameAsString - moduleNameAsString = - String.join "." moduleName - in - { exposedModules = Set.empty - , declaredConstructors = - if moduleContext.isExposed then - if moduleContext.exposesEverything then - Dict.empty + else + Dict.singleton + moduleNameAsString + (ExposedConstructors + { moduleKey = moduleKey + , customTypes = + moduleContext.declaredTypesWithConstructors + |> Dict.filter (\typeName _ -> not <| Set.member typeName moduleContext.exposedCustomTypesWithConstructors) + } + ) - else - Dict.singleton - moduleNameAsString - (ExposedConstructors - { moduleKey = moduleKey - , customTypes = - moduleContext.declaredTypesWithConstructors - |> Dict.filter (\typeName _ -> not <| Set.member typeName moduleContext.exposedCustomTypesWithConstructors) - } + else + Dict.singleton + moduleNameAsString + (ExposedConstructors + { moduleKey = moduleKey + , customTypes = moduleContext.declaredTypesWithConstructors + } + ) + , usedConstructors = + moduleContext.usedFunctionsOrValues + |> Dict.remove "" + |> Dict.insert moduleNameAsString localUsed + , phantomVariables = Dict.singleton moduleName localPhantomTypes + , wasUsedInLocationThatNeedsItself = + Set.map + (\(( moduleName_, constructorName ) as untouched) -> + if moduleName_ == "" then + ( moduleNameAsString, constructorName ) + + else + untouched ) + moduleContext.wasUsedInLocationThatNeedsItself + , wasUsedInComparisons = + Set.map + (\(( moduleName_, constructorName ) as untouched) -> + if moduleName_ == "" then + ( moduleNameAsString, constructorName ) - else - Dict.singleton - moduleNameAsString - (ExposedConstructors - { moduleKey = moduleKey - , customTypes = moduleContext.declaredTypesWithConstructors - } - ) - , usedConstructors = - moduleContext.usedFunctionsOrValues - |> Dict.remove "" - |> Dict.insert moduleNameAsString localUsed - , phantomVariables = Dict.singleton moduleName localPhantomTypes - , wasUsedInLocationThatNeedsItself = - Set.map - (\(( moduleName_, constructorName ) as untouched) -> - if moduleName_ == "" then - ( moduleNameAsString, constructorName ) - - else - untouched - ) - moduleContext.wasUsedInLocationThatNeedsItself - , wasUsedInComparisons = - Set.map - (\(( moduleName_, constructorName ) as untouched) -> - if moduleName_ == "" then - ( moduleNameAsString, constructorName ) - - else - untouched - ) - moduleContext.wasUsedInComparisons - , wasUsedInOtherModules = - List.foldl - (\( moduleName_, constructors ) acc -> - Set.union - (Set.map (Tuple.pair moduleName_) constructors) - acc - ) - moduleContext.wasUsedInOtherModules - -- TODO add test to make sure we don't fix something that is pattern matched in other modules - (Dict.toList <| Dict.remove "" moduleContext.usedFunctionsOrValues) - , fixesForRemovingConstructor = - mapDictKeys - (\constructorName -> - ( moduleNameAsString, constructorName ) - ) - moduleContext.fixesForRemovingConstructor - } + else + untouched + ) + moduleContext.wasUsedInComparisons + , wasUsedInOtherModules = + List.foldl + (\( moduleName_, constructors ) acc -> + Set.union + (Set.map (Tuple.pair moduleName_) constructors) + acc + ) + moduleContext.wasUsedInOtherModules + -- TODO add test to make sure we don't fix something that is pattern matched in other modules + (Dict.toList <| Dict.remove "" moduleContext.usedFunctionsOrValues) + , fixesForRemovingConstructor = + mapDictKeys + (\constructorName -> + ( moduleNameAsString, constructorName ) + ) + moduleContext.fixesForRemovingConstructor + } + ) + |> Rule.withModuleKey + |> Rule.withModuleName foldProjectContexts : ProjectContext -> ProjectContext -> ProjectContext diff --git a/tests/NoUnused/Dependencies.elm b/tests/NoUnused/Dependencies.elm index cdc078b7..ec0b7a1f 100644 --- a/tests/NoUnused/Dependencies.elm +++ b/tests/NoUnused/Dependencies.elm @@ -133,24 +133,19 @@ fromProjectToModule = fromModuleToProject : Rule.ContextCreator ModuleContext ProjectContext fromModuleToProject = Rule.initContextCreator - (\metadata { usedDependencies } -> - let - isSourceDir : Bool - isSourceDir = - Rule.isInSourceDirectories metadata - in + (\isInSourceDirectories { usedDependencies } -> { moduleNameToDependency = Dict.empty , dependencies = Dict.empty , directProjectDependencies = Set.empty , directTestDependencies = Set.empty , usedDependencies = - if isSourceDir then + if isInSourceDirectories then usedDependencies else Set.empty , usedDependenciesFromTest = - if isSourceDir then + if isInSourceDirectories then Set.empty else @@ -158,7 +153,7 @@ fromModuleToProject = , elmJsonKey = Nothing } ) - |> Rule.withMetadata + |> Rule.withIsInSourceDirectories foldProjectContexts : ProjectContext -> ProjectContext -> ProjectContext diff --git a/tests/NoUnused/Exports.elm b/tests/NoUnused/Exports.elm index c435c2f8..5b9c814a 100644 --- a/tests/NoUnused/Exports.elm +++ b/tests/NoUnused/Exports.elm @@ -57,8 +57,8 @@ rule = Rule.newProjectRuleSchema "NoUnused.Exports" initialProjectContext |> Rule.withModuleVisitor moduleVisitor |> Rule.withModuleContextUsingContextCreator - { fromProjectToModule = Rule.initContextCreator fromProjectToModule |> Rule.withModuleNameLookupTable - , fromModuleToProject = Rule.initContextCreator fromModuleToProject |> Rule.withModuleKey |> Rule.withMetadata + { fromProjectToModule = fromProjectToModule + , fromModuleToProject = fromModuleToProject , foldProjectContexts = foldProjectContexts } |> Rule.withContextFromImportedModules @@ -136,51 +136,55 @@ initialProjectContext = } -fromProjectToModule : ModuleNameLookupTable -> ProjectContext -> ModuleContext -fromProjectToModule lookupTable _ = - { lookupTable = lookupTable - , exposesEverything = False - , exposed = Dict.empty - , rawExposed = [] - , used = Set.empty - , elementsNotToReport = Set.empty - } - - -fromModuleToProject : Rule.ModuleKey -> Rule.Metadata -> ModuleContext -> ProjectContext -fromModuleToProject moduleKey metadata moduleContext = - let - moduleName : ModuleName - moduleName = - Rule.moduleNameFromMetadata metadata - in - { projectType = IsApplication ElmApplication - , modules = - Dict.singleton - moduleName - { moduleKey = moduleKey - , exposed = moduleContext.exposed +fromProjectToModule : Rule.ContextCreator ProjectContext ModuleContext +fromProjectToModule = + Rule.initContextCreator + (\lookupTable _ -> + { lookupTable = lookupTable + , exposesEverything = False + , exposed = Dict.empty + , rawExposed = [] + , used = Set.empty + , elementsNotToReport = Set.empty } - , used = - moduleContext.elementsNotToReport - |> Set.map (Tuple.pair moduleName) - |> Set.union moduleContext.used - , constructors = - Dict.foldl - (\name element acc -> - case element.elementType of - ExposedType constructorNames -> - List.foldl - (\constructorName listAcc -> Dict.insert ( moduleName, constructorName ) name listAcc) - acc - constructorNames + ) + |> Rule.withModuleNameLookupTable - _ -> - acc - ) - Dict.empty - moduleContext.exposed - } + +fromModuleToProject : Rule.ContextCreator ModuleContext ProjectContext +fromModuleToProject = + Rule.initContextCreator + (\moduleKey moduleName moduleContext -> + { projectType = IsApplication ElmApplication + , modules = + Dict.singleton + moduleName + { moduleKey = moduleKey + , exposed = moduleContext.exposed + } + , used = + moduleContext.elementsNotToReport + |> Set.map (Tuple.pair moduleName) + |> Set.union moduleContext.used + , constructors = + Dict.foldl + (\name element acc -> + case element.elementType of + ExposedType constructorNames -> + List.foldl + (\constructorName listAcc -> Dict.insert ( moduleName, constructorName ) name listAcc) + acc + constructorNames + + _ -> + acc + ) + Dict.empty + moduleContext.exposed + } + ) + |> Rule.withModuleKey + |> Rule.withModuleName foldProjectContexts : ProjectContext -> ProjectContext -> ProjectContext diff --git a/tests/NoUnused/Variables.elm b/tests/NoUnused/Variables.elm index cfb2084b..4219daa4 100644 --- a/tests/NoUnused/Variables.elm +++ b/tests/NoUnused/Variables.elm @@ -252,17 +252,17 @@ fromProjectToModule = fromModuleToProject : Rule.ContextCreator ModuleContext ProjectContext fromModuleToProject = Rule.initContextCreator - (\metadata moduleContext -> + (\moduleName moduleContext -> { customTypes = moduleContext.localTypes |> Dict.map (\_ customType -> customType.variants) - |> Dict.singleton (Rule.moduleNameFromMetadata metadata) + |> Dict.singleton moduleName -- Will be ignored in foldProjectContexts , isApplication = True } ) - |> Rule.withMetadata + |> Rule.withModuleName foldProjectContexts : ProjectContext -> ProjectContext -> ProjectContext diff --git a/tests/Simplify.elm b/tests/Simplify.elm index d2abaa02..65c4ae0b 100644 --- a/tests/Simplify.elm +++ b/tests/Simplify.elm @@ -770,9 +770,9 @@ fromModuleToProject = initialModuleContext : Rule.ContextCreator () ModuleContext initialModuleContext = Rule.initContextCreator - (\lookupTable metadata () -> + (\lookupTable moduleName () -> { lookupTable = lookupTable - , moduleName = Rule.moduleNameFromMetadata metadata + , moduleName = moduleName , rangesToIgnore = [] , rightSidesOfPlusPlus = [] , localIgnoredCustomTypes = [] @@ -781,15 +781,15 @@ initialModuleContext = } ) |> Rule.withModuleNameLookupTable - |> Rule.withMetadata + |> Rule.withModuleName fromProjectToModule : Rule.ContextCreator ProjectContext ModuleContext fromProjectToModule = Rule.initContextCreator - (\lookupTable metadata projectContext -> + (\lookupTable moduleName projectContext -> { lookupTable = lookupTable - , moduleName = Rule.moduleNameFromMetadata metadata + , moduleName = moduleName , rangesToIgnore = [] , rightSidesOfPlusPlus = [] , localIgnoredCustomTypes = [] @@ -798,7 +798,7 @@ fromProjectToModule = } ) |> Rule.withModuleNameLookupTable - |> Rule.withMetadata + |> Rule.withModuleName buildConstructorsToIgnore : List Constructor -> Set ( ModuleName, String )