Skip to content

Commit

Permalink
ReviewLinksAndSections: Use Rule.withModuleName
Browse files Browse the repository at this point in the history
  • Loading branch information
jfmengels committed Aug 24, 2022
1 parent 2bd3a69 commit 8856258
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions src/Docs/ReviewLinksAndSections.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -206,7 +201,7 @@ fromProjectToModule =
, links = []
}
)
|> Rule.withMetadata
|> Rule.withModuleName


fromModuleToProject : Rule.ContextCreator ModuleContext ProjectContext
Expand Down Expand Up @@ -239,7 +234,7 @@ moduleVisitor : Rule.ModuleRuleSchema schemaState ModuleContext -> Rule.ModuleRu
moduleVisitor schema =
schema
|> Rule.withModuleDefinitionVisitor moduleDefinitionVisitor
|> Rule.withCommentsVisitor commentsVisitor
|> Rule.withModuleDocumentationVisitor moduleDocumentationVisitor
|> Rule.withDeclarationListVisitor declarationListVisitor


Expand Down Expand Up @@ -356,37 +351,34 @@ exposedName node =



-- COMMENTS VISITOR
-- MODULE DOCUMENTATION VISITOR


commentsVisitor : List (Node String) -> ModuleContext -> ( List nothing, ModuleContext )
commentsVisitor comments context =
moduleDocumentationVisitor : Maybe (Node String) -> ModuleContext -> ( List (Rule.Error {}), ModuleContext )
moduleDocumentationVisitor moduleDocumentation context =
let
docs : List (Node String)
docs =
List.filter (Node.value >> String.startsWith "{-|") comments

sectionsAndLinks : List { titleSections : List SectionWithRange, links : List MaybeExposedLink }
sectionsAndLinks : { titleSections : List SectionWithRange, links : List MaybeExposedLink }
sectionsAndLinks =
List.map
(\doc ->
case moduleDocumentation of
Just (Node range content) ->
findSectionsAndLinks
context.moduleName
context.isModuleExposed
{ content = Node.value doc, startRow = (Node.range doc).start.row }
)
docs
{ content = content, startRow = range.start.row }

Nothing ->
{ titleSections = [], links = [] }
in
( []
, { isModuleExposed = context.isModuleExposed
, exposedElements = context.exposedElements
, moduleName = context.moduleName
, commentSections = List.concatMap .titleSections sectionsAndLinks
, commentSections = sectionsAndLinks.titleSections
, sections =
List.append
(List.concatMap (.titleSections >> List.map removeRangeFromSection) sectionsAndLinks)
(List.map removeRangeFromSection sectionsAndLinks.titleSections)
context.sections
, links = List.append (List.concatMap .links sectionsAndLinks) context.links
, links = List.append sectionsAndLinks.links context.links
}
)

Expand Down

0 comments on commit 8856258

Please sign in to comment.