Skip to content

[Repo Assist] refactor: extract formatListBlock helper — eliminate ordered/unordered list duplication in MarkdownUtils.fs#1176

Closed
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/improve-list-block-refactor-2026-04-20-522903cf7da3ba07
Closed

[Repo Assist] refactor: extract formatListBlock helper — eliminate ordered/unordered list duplication in MarkdownUtils.fs#1176
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/improve-list-block-refactor-2026-04-20-522903cf7da3ba07

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Summary

Task 5 (Coding Improvements): the formatParagraph function in MarkdownUtils.fs had two near-identical blocks for formatting ordered and unordered lists — differing only in the item prefix ("* " vs "1. ", "2. ", ...). This PR extracts a shared formatListBlock helper, reducing ~48 lines to ~27 lines with no semantic change.

Before

| ListBlock(Unordered, paragraphsl, _) ->
    let isTight = paragraphsl |> List.forall (function | [ Span _ ] -> true | _ -> false)
    for paragraphs in paragraphsl do
        for (i, paragraph) in List.indexed paragraphs do
            let lines = formatParagraph ctx paragraph
            let lines = if lines.IsEmpty then [ "" ] else lines
            for (j, line) in List.indexed lines do
                if i = 0 && j = 0 then yield "* " + line
                else yield "  " + line
        if not isTight then yield ""
    if isTight then yield ""

| ListBlock(Ordered, paragraphsl, _) ->
    // ... 20 lines identical except for "$"{n+1}. "" prefix ...

After

let formatListBlock paragraphsl (getPrefix: int -> string) = ...   // shared helper

| ListBlock(Unordered, paragraphsl, _) -> yield! formatListBlock paragraphsl (fun _ -> "* ")
| ListBlock(Ordered, paragraphsl, _)   -> yield! formatListBlock paragraphsl (fun n -> $"{n + 1}. ")

Changes

File Change
src/FSharp.Formatting.Markdown/MarkdownUtils.fs Extract formatListBlock helper, remove ~21 duplicate lines
RELEASE_NOTES.md Changelog entry under [Unreleased]

Test Status

  • dotnet build src/FSharp.Formatting.Markdown/FSharp.Formatting.Markdown.fsproj --configuration Release — 0 warnings, 0 errors
  • dotnet test tests/FSharp.Markdown.Tests346/346 passed (includes existing list round-trip tests)
  • dotnet fantomas src/FSharp.Formatting.Markdown/MarkdownUtils.fs --check — formatting verified

Generated by 🌈 Repo Assist, see workflow run.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@96b9d4c39aa22359c0b38265927eadb31dcf4e2a

…ed list duplication in MarkdownUtils.fs

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant