Stop using Rule.withMetadata in plugin rules

This commit is contained in:
Jeroen Engels 2022-04-28 13:24:33 +02:00
parent 0fa1005f4d
commit dddba5c1cf
12 changed files with 201 additions and 206 deletions

View File

@ -192,12 +192,7 @@ type alias MaybeExposedLinkData =
fromProjectToModule : Rule.ContextCreator ProjectContext ModuleContext fromProjectToModule : Rule.ContextCreator ProjectContext ModuleContext
fromProjectToModule = fromProjectToModule =
Rule.initContextCreator Rule.initContextCreator
(\metadata projectContext -> (\moduleName projectContext ->
let
moduleName : ModuleName
moduleName =
Rule.moduleNameFromMetadata metadata
in
{ isModuleExposed = Set.member moduleName projectContext.exposedModules { isModuleExposed = Set.member moduleName projectContext.exposedModules
, exposedElements = Set.empty , exposedElements = Set.empty
, moduleName = moduleName , moduleName = moduleName
@ -206,7 +201,7 @@ fromProjectToModule =
, links = [] , links = []
} }
) )
|> Rule.withMetadata |> Rule.withModuleName
fromModuleToProject : Rule.ContextCreator ModuleContext ProjectContext fromModuleToProject : Rule.ContextCreator ModuleContext ProjectContext

View File

@ -158,12 +158,7 @@ type DeprecationReason
fromProjectToModule : StableConfiguration -> Rule.ContextCreator ProjectContext ModuleContext fromProjectToModule : StableConfiguration -> Rule.ContextCreator ProjectContext ModuleContext
fromProjectToModule (StableConfiguration configuration) = fromProjectToModule (StableConfiguration configuration) =
Rule.initContextCreator Rule.initContextCreator
(\metadata lookupTable projectContext -> (\moduleName lookupTable projectContext ->
let
moduleName : ModuleName
moduleName =
Rule.moduleNameFromMetadata metadata
in
{ lookupTable = lookupTable { lookupTable = lookupTable
, currentModuleName = moduleName , currentModuleName = moduleName
, deprecatedModules = Dict.fromList projectContext.deprecatedModules , deprecatedModules = Dict.fromList projectContext.deprecatedModules
@ -172,24 +167,24 @@ fromProjectToModule (StableConfiguration configuration) =
, localDeprecatedElements = [] , localDeprecatedElements = []
} }
) )
|> Rule.withMetadata |> Rule.withModuleName
|> Rule.withModuleNameLookupTable |> Rule.withModuleNameLookupTable
fromModuleToProject : Rule.ContextCreator ModuleContext ProjectContext fromModuleToProject : Rule.ContextCreator ModuleContext ProjectContext
fromModuleToProject = fromModuleToProject =
Rule.initContextCreator Rule.initContextCreator
(\metadata moduleContext -> (\moduleName moduleContext ->
{ deprecatedModules = { deprecatedModules =
if moduleContext.isModuleDeprecated then if moduleContext.isModuleDeprecated then
[ ( Rule.moduleNameFromMetadata metadata, DeprecatedModule ) ] [ ( moduleName, DeprecatedModule ) ]
else else
[] []
, deprecatedElements = moduleContext.localDeprecatedElements , deprecatedElements = moduleContext.localDeprecatedElements
} }
) )
|> Rule.withMetadata |> Rule.withModuleName
foldProjectContexts : ProjectContext -> ProjectContext -> ProjectContext foldProjectContexts : ProjectContext -> ProjectContext -> ProjectContext

View File

@ -122,16 +122,16 @@ fromProjectToModule =
fromModuleToProject : Rule.ContextCreator ModuleContext ProjectContext fromModuleToProject : Rule.ContextCreator ModuleContext ProjectContext
fromModuleToProject = fromModuleToProject =
Rule.initContextCreator Rule.initContextCreator
(\metadata moduleContext -> (\moduleName moduleContext ->
{ modulesThatExposeSubscriptionsAndUpdate = { modulesThatExposeSubscriptionsAndUpdate =
if moduleContext.definesSubscriptions && moduleContext.definesUpdate then if moduleContext.definesSubscriptions && moduleContext.definesUpdate then
Set.singleton (Rule.moduleNameFromMetadata metadata) Set.singleton moduleName
else else
Set.empty Set.empty
} }
) )
|> Rule.withMetadata |> Rule.withModuleName
foldProjectContexts : ProjectContext -> ProjectContext -> ProjectContext foldProjectContexts : ProjectContext -> ProjectContext -> ProjectContext

View File

@ -610,11 +610,11 @@ formatTypeName ( moduleName, name ) =
fromProjectToModuleContext : Rule.ContextCreator ProjectContext ModuleContext fromProjectToModuleContext : Rule.ContextCreator ProjectContext ModuleContext
fromProjectToModuleContext = fromProjectToModuleContext =
Rule.initContextCreator Rule.initContextCreator
(\lookupTable metadata { exposedModules, moduleTypes } -> (\lookupTable moduleName { exposedModules, moduleTypes } ->
let let
moduleType : ModuleType moduleType : ModuleType
moduleType = moduleType =
if isModuleExposed exposedModules (Rule.moduleNameFromMetadata metadata) then if isModuleExposed exposedModules moduleName then
initialExposedModuleType exposedModules moduleTypes initialExposedModuleType exposedModules moduleTypes
else else
@ -626,21 +626,21 @@ fromProjectToModuleContext =
} }
) )
|> Rule.withModuleNameLookupTable |> Rule.withModuleNameLookupTable
|> Rule.withMetadata |> Rule.withModuleName
fromModuleToProjectContext : Rule.ContextCreator ModuleContext ProjectContext fromModuleToProjectContext : Rule.ContextCreator ModuleContext ProjectContext
fromModuleToProjectContext = fromModuleToProjectContext =
Rule.initContextCreator Rule.initContextCreator
(\metadata context -> (\moduleName context ->
case context.moduleType of case context.moduleType of
InternalModule { exposedTypes } -> InternalModule { exposedTypes } ->
{ initialProjectContext | moduleTypes = Dict.singleton (Rule.moduleNameFromMetadata metadata) exposedTypes } { initialProjectContext | moduleTypes = Dict.singleton moduleName exposedTypes }
ExposedModule _ -> ExposedModule _ ->
initialProjectContext initialProjectContext
) )
|> Rule.withMetadata |> Rule.withModuleName
foldProjectContexts : ProjectContext -> ProjectContext -> ProjectContext foldProjectContexts : ProjectContext -> ProjectContext -> ProjectContext

View File

@ -130,12 +130,12 @@ type alias Context =
initialContext : Rule.ContextCreator () Context initialContext : Rule.ContextCreator () Context
initialContext = initialContext =
Rule.initContextCreator Rule.initContextCreator
(\metadata () -> (\isInSourceDirectories () ->
{ inDeclarationOfNonTestValue = False { inDeclarationOfNonTestValue = False
, isInSourceDirectories = Rule.isInSourceDirectories metadata , isInSourceDirectories = isInSourceDirectories
} }
) )
|> Rule.withMetadata |> Rule.withIsInSourceDirectories

View File

@ -195,11 +195,11 @@ fromProjectToModule =
fromModuleToProject : Target -> Rule.ContextCreator ModuleContext ProjectContext fromModuleToProject : Target -> Rule.ContextCreator ModuleContext ProjectContext
fromModuleToProject target = fromModuleToProject target =
Rule.initContextCreator Rule.initContextCreator
(\metadata moduleContext -> (\moduleName moduleContext ->
{ foundTargetFunction = moduleContext.foundTargetFunction && (Rule.moduleNameFromMetadata metadata == target.moduleName) { foundTargetFunction = moduleContext.foundTargetFunction && (moduleName == target.moduleName)
} }
) )
|> Rule.withMetadata |> Rule.withModuleName
foldProjectContexts : ProjectContext -> ProjectContext -> ProjectContext foldProjectContexts : ProjectContext -> ProjectContext -> ProjectContext

View File

@ -159,9 +159,9 @@ initialProjectContext =
fromProjectToModule : Rule.ContextCreator ProjectContext ModuleContext fromProjectToModule : Rule.ContextCreator ProjectContext ModuleContext
fromProjectToModule = fromProjectToModule =
Rule.initContextCreator Rule.initContextCreator
(\lookupTable metadata projectContext -> (\lookupTable moduleName projectContext ->
{ lookupTable = lookupTable { lookupTable = lookupTable
, isModuleExposed = Set.member (Rule.moduleNameFromMetadata metadata) projectContext.exposedModules , isModuleExposed = Set.member moduleName projectContext.exposedModules
, exposed = Exposing.Explicit [] , exposed = Exposing.Explicit []
, customTypeArgs = [] , customTypeArgs = []
, usedArguments = Dict.empty , usedArguments = Dict.empty
@ -169,26 +169,26 @@ fromProjectToModule =
} }
) )
|> Rule.withModuleNameLookupTable |> Rule.withModuleNameLookupTable
|> Rule.withMetadata |> Rule.withModuleName
fromModuleToProject : Rule.ContextCreator ModuleContext ProjectContext fromModuleToProject : Rule.ContextCreator ModuleContext ProjectContext
fromModuleToProject = fromModuleToProject =
Rule.initContextCreator Rule.initContextCreator
(\moduleKey metadata moduleContext -> (\moduleKey moduleName moduleContext ->
{ exposedModules = Set.empty { exposedModules = Set.empty
, customTypeArgs = , customTypeArgs =
Dict.singleton Dict.singleton
(Rule.moduleNameFromMetadata metadata) moduleName
{ moduleKey = moduleKey { moduleKey = moduleKey
, args = getNonExposedCustomTypes moduleContext , args = getNonExposedCustomTypes moduleContext
} }
, usedArguments = replaceLocalModuleNameForDict (Rule.moduleNameFromMetadata metadata) moduleContext.usedArguments , usedArguments = replaceLocalModuleNameForDict moduleName moduleContext.usedArguments
, customTypesNotToReport = replaceLocalModuleNameForSet (Rule.moduleNameFromMetadata metadata) moduleContext.customTypesNotToReport , customTypesNotToReport = replaceLocalModuleNameForSet moduleName moduleContext.customTypesNotToReport
} }
) )
|> Rule.withModuleKey |> Rule.withModuleKey
|> Rule.withMetadata |> Rule.withModuleName
replaceLocalModuleNameForSet : ModuleName -> Set ( ModuleName, comparable ) -> Set ( ModuleName, comparable ) replaceLocalModuleNameForSet : ModuleName -> Set ( ModuleName, comparable ) -> Set ( ModuleName, comparable )

View File

@ -126,8 +126,8 @@ rule phantomTypes =
|> Rule.withContextFromImportedModules |> Rule.withContextFromImportedModules
|> Rule.withModuleVisitor moduleVisitor |> Rule.withModuleVisitor moduleVisitor
|> Rule.withModuleContextUsingContextCreator |> Rule.withModuleContextUsingContextCreator
{ fromProjectToModule = Rule.initContextCreator fromProjectToModule |> Rule.withModuleNameLookupTable |> Rule.withMetadata { fromProjectToModule = fromProjectToModule
, fromModuleToProject = Rule.initContextCreator fromModuleToProject |> Rule.withModuleKey |> Rule.withMetadata , fromModuleToProject = fromModuleToProject
, foldProjectContexts = foldProjectContexts , foldProjectContexts = foldProjectContexts
} }
|> Rule.withElmJsonProjectVisitor elmJsonVisitor |> Rule.withElmJsonProjectVisitor elmJsonVisitor
@ -229,11 +229,13 @@ initialProjectContext phantomTypes =
} }
fromProjectToModule : ModuleNameLookupTable -> Rule.Metadata -> ProjectContext -> ModuleContext fromProjectToModule : Rule.ContextCreator ProjectContext ModuleContext
fromProjectToModule lookupTable metadata projectContext = fromProjectToModule =
Rule.initContextCreator
(\lookupTable moduleName projectContext ->
{ lookupTable = lookupTable { lookupTable = lookupTable
, exposedCustomTypesWithConstructors = Set.empty , exposedCustomTypesWithConstructors = Set.empty
, isExposed = Set.member (Rule.moduleNameFromMetadata metadata |> String.join ".") projectContext.exposedModules , isExposed = Set.member (String.join "." moduleName) projectContext.exposedModules
, exposedConstructors = projectContext.declaredConstructors , exposedConstructors = projectContext.declaredConstructors
, exposesEverything = False , exposesEverything = False
, declaredTypesWithConstructors = Dict.empty , declaredTypesWithConstructors = Dict.empty
@ -246,10 +248,15 @@ fromProjectToModule lookupTable metadata projectContext =
, fixesForRemovingConstructor = Dict.empty , fixesForRemovingConstructor = Dict.empty
, ignoredComparisonRanges = [] , ignoredComparisonRanges = []
} }
)
|> Rule.withModuleNameLookupTable
|> Rule.withModuleName
fromModuleToProject : Rule.ModuleKey -> Rule.Metadata -> ModuleContext -> ProjectContext fromModuleToProject : Rule.ContextCreator ModuleContext ProjectContext
fromModuleToProject moduleKey metadata moduleContext = fromModuleToProject =
Rule.initContextCreator
(\moduleKey moduleName moduleContext ->
let let
localUsed : Set ConstructorName localUsed : Set ConstructorName
localUsed = localUsed =
@ -263,10 +270,6 @@ fromModuleToProject moduleKey metadata moduleContext =
|> Dict.get [] |> Dict.get []
|> Maybe.withDefault [] |> Maybe.withDefault []
moduleName : ModuleName
moduleName =
Rule.moduleNameFromMetadata metadata
moduleNameAsString : ModuleNameAsString moduleNameAsString : ModuleNameAsString
moduleNameAsString = moduleNameAsString =
String.join "." moduleName String.join "." moduleName
@ -338,6 +341,9 @@ fromModuleToProject moduleKey metadata moduleContext =
) )
moduleContext.fixesForRemovingConstructor moduleContext.fixesForRemovingConstructor
} }
)
|> Rule.withModuleKey
|> Rule.withModuleName
foldProjectContexts : ProjectContext -> ProjectContext -> ProjectContext foldProjectContexts : ProjectContext -> ProjectContext -> ProjectContext

View File

@ -133,24 +133,19 @@ fromProjectToModule =
fromModuleToProject : Rule.ContextCreator ModuleContext ProjectContext fromModuleToProject : Rule.ContextCreator ModuleContext ProjectContext
fromModuleToProject = fromModuleToProject =
Rule.initContextCreator Rule.initContextCreator
(\metadata { usedDependencies } -> (\isInSourceDirectories { usedDependencies } ->
let
isSourceDir : Bool
isSourceDir =
Rule.isInSourceDirectories metadata
in
{ moduleNameToDependency = Dict.empty { moduleNameToDependency = Dict.empty
, dependencies = Dict.empty , dependencies = Dict.empty
, directProjectDependencies = Set.empty , directProjectDependencies = Set.empty
, directTestDependencies = Set.empty , directTestDependencies = Set.empty
, usedDependencies = , usedDependencies =
if isSourceDir then if isInSourceDirectories then
usedDependencies usedDependencies
else else
Set.empty Set.empty
, usedDependenciesFromTest = , usedDependenciesFromTest =
if isSourceDir then if isInSourceDirectories then
Set.empty Set.empty
else else
@ -158,7 +153,7 @@ fromModuleToProject =
, elmJsonKey = Nothing , elmJsonKey = Nothing
} }
) )
|> Rule.withMetadata |> Rule.withIsInSourceDirectories
foldProjectContexts : ProjectContext -> ProjectContext -> ProjectContext foldProjectContexts : ProjectContext -> ProjectContext -> ProjectContext

View File

@ -57,8 +57,8 @@ rule =
Rule.newProjectRuleSchema "NoUnused.Exports" initialProjectContext Rule.newProjectRuleSchema "NoUnused.Exports" initialProjectContext
|> Rule.withModuleVisitor moduleVisitor |> Rule.withModuleVisitor moduleVisitor
|> Rule.withModuleContextUsingContextCreator |> Rule.withModuleContextUsingContextCreator
{ fromProjectToModule = Rule.initContextCreator fromProjectToModule |> Rule.withModuleNameLookupTable { fromProjectToModule = fromProjectToModule
, fromModuleToProject = Rule.initContextCreator fromModuleToProject |> Rule.withModuleKey |> Rule.withMetadata , fromModuleToProject = fromModuleToProject
, foldProjectContexts = foldProjectContexts , foldProjectContexts = foldProjectContexts
} }
|> Rule.withContextFromImportedModules |> Rule.withContextFromImportedModules
@ -136,8 +136,10 @@ initialProjectContext =
} }
fromProjectToModule : ModuleNameLookupTable -> ProjectContext -> ModuleContext fromProjectToModule : Rule.ContextCreator ProjectContext ModuleContext
fromProjectToModule lookupTable _ = fromProjectToModule =
Rule.initContextCreator
(\lookupTable _ ->
{ lookupTable = lookupTable { lookupTable = lookupTable
, exposesEverything = False , exposesEverything = False
, exposed = Dict.empty , exposed = Dict.empty
@ -145,15 +147,14 @@ fromProjectToModule lookupTable _ =
, used = Set.empty , used = Set.empty
, elementsNotToReport = Set.empty , elementsNotToReport = Set.empty
} }
)
|> Rule.withModuleNameLookupTable
fromModuleToProject : Rule.ModuleKey -> Rule.Metadata -> ModuleContext -> ProjectContext fromModuleToProject : Rule.ContextCreator ModuleContext ProjectContext
fromModuleToProject moduleKey metadata moduleContext = fromModuleToProject =
let Rule.initContextCreator
moduleName : ModuleName (\moduleKey moduleName moduleContext ->
moduleName =
Rule.moduleNameFromMetadata metadata
in
{ projectType = IsApplication ElmApplication { projectType = IsApplication ElmApplication
, modules = , modules =
Dict.singleton Dict.singleton
@ -181,6 +182,9 @@ fromModuleToProject moduleKey metadata moduleContext =
Dict.empty Dict.empty
moduleContext.exposed moduleContext.exposed
} }
)
|> Rule.withModuleKey
|> Rule.withModuleName
foldProjectContexts : ProjectContext -> ProjectContext -> ProjectContext foldProjectContexts : ProjectContext -> ProjectContext -> ProjectContext

View File

@ -252,17 +252,17 @@ fromProjectToModule =
fromModuleToProject : Rule.ContextCreator ModuleContext ProjectContext fromModuleToProject : Rule.ContextCreator ModuleContext ProjectContext
fromModuleToProject = fromModuleToProject =
Rule.initContextCreator Rule.initContextCreator
(\metadata moduleContext -> (\moduleName moduleContext ->
{ customTypes = { customTypes =
moduleContext.localTypes moduleContext.localTypes
|> Dict.map (\_ customType -> customType.variants) |> Dict.map (\_ customType -> customType.variants)
|> Dict.singleton (Rule.moduleNameFromMetadata metadata) |> Dict.singleton moduleName
-- Will be ignored in foldProjectContexts -- Will be ignored in foldProjectContexts
, isApplication = True , isApplication = True
} }
) )
|> Rule.withMetadata |> Rule.withModuleName
foldProjectContexts : ProjectContext -> ProjectContext -> ProjectContext foldProjectContexts : ProjectContext -> ProjectContext -> ProjectContext

View File

@ -770,9 +770,9 @@ fromModuleToProject =
initialModuleContext : Rule.ContextCreator () ModuleContext initialModuleContext : Rule.ContextCreator () ModuleContext
initialModuleContext = initialModuleContext =
Rule.initContextCreator Rule.initContextCreator
(\lookupTable metadata () -> (\lookupTable moduleName () ->
{ lookupTable = lookupTable { lookupTable = lookupTable
, moduleName = Rule.moduleNameFromMetadata metadata , moduleName = moduleName
, rangesToIgnore = [] , rangesToIgnore = []
, rightSidesOfPlusPlus = [] , rightSidesOfPlusPlus = []
, localIgnoredCustomTypes = [] , localIgnoredCustomTypes = []
@ -781,15 +781,15 @@ initialModuleContext =
} }
) )
|> Rule.withModuleNameLookupTable |> Rule.withModuleNameLookupTable
|> Rule.withMetadata |> Rule.withModuleName
fromProjectToModule : Rule.ContextCreator ProjectContext ModuleContext fromProjectToModule : Rule.ContextCreator ProjectContext ModuleContext
fromProjectToModule = fromProjectToModule =
Rule.initContextCreator Rule.initContextCreator
(\lookupTable metadata projectContext -> (\lookupTable moduleName projectContext ->
{ lookupTable = lookupTable { lookupTable = lookupTable
, moduleName = Rule.moduleNameFromMetadata metadata , moduleName = moduleName
, rangesToIgnore = [] , rangesToIgnore = []
, rightSidesOfPlusPlus = [] , rightSidesOfPlusPlus = []
, localIgnoredCustomTypes = [] , localIgnoredCustomTypes = []
@ -798,7 +798,7 @@ fromProjectToModule =
} }
) )
|> Rule.withModuleNameLookupTable |> Rule.withModuleNameLookupTable
|> Rule.withMetadata |> Rule.withModuleName
buildConstructorsToIgnore : List Constructor -> Set ( ModuleName, String ) buildConstructorsToIgnore : List Constructor -> Set ( ModuleName, String )