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.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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 )

View File

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

View File

@ -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

View File

@ -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,8 +136,10 @@ initialProjectContext =
}
fromProjectToModule : ModuleNameLookupTable -> ProjectContext -> ModuleContext
fromProjectToModule lookupTable _ =
fromProjectToModule : Rule.ContextCreator ProjectContext ModuleContext
fromProjectToModule =
Rule.initContextCreator
(\lookupTable _ ->
{ lookupTable = lookupTable
, exposesEverything = False
, exposed = Dict.empty
@ -145,15 +147,14 @@ fromProjectToModule lookupTable _ =
, used = Set.empty
, elementsNotToReport = Set.empty
}
)
|> Rule.withModuleNameLookupTable
fromModuleToProject : Rule.ModuleKey -> Rule.Metadata -> ModuleContext -> ProjectContext
fromModuleToProject moduleKey metadata moduleContext =
let
moduleName : ModuleName
moduleName =
Rule.moduleNameFromMetadata metadata
in
fromModuleToProject : Rule.ContextCreator ModuleContext ProjectContext
fromModuleToProject =
Rule.initContextCreator
(\moduleKey moduleName moduleContext ->
{ projectType = IsApplication ElmApplication
, modules =
Dict.singleton
@ -181,6 +182,9 @@ fromModuleToProject moduleKey metadata moduleContext =
Dict.empty
moduleContext.exposed
}
)
|> Rule.withModuleKey
|> Rule.withModuleName
foldProjectContexts : ProjectContext -> ProjectContext -> ProjectContext

View File

@ -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

View File

@ -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 )