Skip to content

refactor: split to_markdown and Roots::resolve into shorter functions - #216

Closed
tamada wants to merge 3 commits into
mainfrom
refactor/stats-to-markdown
Closed

tamada wants to merge 3 commits into
mainfrom
refactor/stats-to-markdown

Conversation

@tamada

@tamada tamada commented Oct 22, 2026

Copy link
Copy Markdown
Owner

The two longest functions in the repository were to_markdown in cli/stats.rs (143 lines) and Roots::resolve in cli/mcp/paths.rs (109 lines). Each is split so that no function is longer than 50 lines. Neither one's behaviour changes.

to_markdown

  • Each section of the Markdown report is a function of its own: md_intro, md_functions, md_elements, md_top for one group, md_per_file and md_skipped.
  • to_markdown puts them in order (17 lines). The longest of the new functions is md_elements at 40.
  • A stats Report is built with Report::new.
  • Checked by running oinkie stats -f markdown, both with and without --per-file --top 3, over a directory that produces every section, including skipped files. The output before and after is identical byte for byte.

Roots::resolve

  • resolve (7 lines) now reads as its steps:
    • refuse_parent_components refuses ..;
    • absolute joins a relative path to the working directory;
    • deepest_existing walks up to the deepest part that exists;
    • append puts the rest back on, refusing to append to a file;
    • inside_a_root checks the result.
  • The refusals that end by naming the roots are made in one place, refusal.
  • The longest function is deepest_existing at 49 lines, about half of them the comments that explain each case of the walk.
  • Checked against the original with six paths: one with .., one outside the root, a dangling symlink, one through a file, one that does not exist yet, and an existing file. Every answer, the refusal messages included, is identical. The 13 existing tests of resolve pass.

cargo test --features mcp (410 tests) and clippy with -D warnings pass locally.

🤖 Generated with Claude Code

tamada and others added 3 commits October 22, 2026 15:01
to_markdown was 143 lines. Each section -- the introduction, functions per
file, elements per function, the top elements of a group, the per-file table
and the skipped files -- is now its own function, and to_markdown puts them
in order. The output is unchanged byte for byte.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
resolve was 109 lines. It now refuses `..`, makes the path absolute, finds
the deepest part that exists, appends the rest and checks the result against
the roots, each in a function of its own. The refusals that name the roots
are made in one place. Every answer, refusals included, is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@tamada tamada closed this Oct 22, 2026
@tamada
tamada deleted the refactor/stats-to-markdown branch October 22, 2026 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant