feat(checks): let OrphanExport report exports imported only by tests (CD-320) - #208
Merged
Conversation
…(CD-320) Consumption is now tallied twice per file — every importer, and only importers that don't match `test_file_patterns`. A new `test_imports_count` option (default true, the pre-existing behaviour) picks which tally decides orphan status. Under the strict reading an export consumed solely by tests reports "imported only by test files", distinct from the genuine "never imported" case. The ticket's premise — that cofferdam drops test-file import edges — is wrong; it counts them like any other. The poker-puzzle findings that motivated it came from that repo's `.cofferdamignore` excluding `**/*.test.ts`, refiled as CD-325. The capability was missing all the same. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019afugU2bTYCtXn6Vy9dn1v
Criterion benchmark comparison (PR head vs base branch) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes CD-320. Read the correction below before the diff — the ticket's premise was wrong, and the finding that replaces it is filed as CD-325.
The ticket said
Design.OrphanExportdrops test-file import edges, so an export a test imports is reported as "never imported in the project". Evidence: all 33 findings on poker-puzzle at 0.4.2 are symbols that tests import.What is actually true
cofferdam counts a test-file import like any other. Minimal reproduction:
cofferdam check . --no-cacheat 0.4.2 → clean. Multi-line andtype-mixed specifier lists behave the same. Add a one-line.cofferdamignorecontaining**/*.test.tsand the orphan finding appears.That is what happened on poker-puzzle: its
.cofferdamignoreexcludes**/*.test.tsand**/*.test.tsx, so the test files contributed no edges. An ignore rule silently changes the answers other files get, andDesign.OrphanExportstates that answer as a fact about the whole project. Filed as CD-325; not fixed here.What this PR does ship
The capability the ticket asked for was genuinely missing, so it is kept:
test_imports_count, a bool defaulting totrue— the pre-existing behaviour, now named and switchable.FileConsumptiontallies consumption twice per file:anycounts every importer,non_testcounts only importers that misstest_file_patterns. Classification reuses the existing pattern list rather than inventing a second definition of "test file".test_imports_count = false, an export consumed solely by tests reports "imported only by test files" — distinct from the genuine "never imported" case, which still reports in both modes.is_consumedso both tallies get it identically, replacing the oldcontinuespecial case.Before this, "exported solely for tests" — a real smell — could not be seen at all.
Tests
Six cases: same-directory
.test.tsand__tests__/conventions, each in both modes; a normal-file importer (never flagged either way); no importer at all (flagged "never imported" both ways). Also fixes the pre-existingopts_default()helper indesign/mod.rsfor the new field.Verification
cargo build --workspace,cargo test --workspace(1382 passed, 8 ignored),cargo clippy --workspace --all-targets -- -D warnings,cargo fmt --all -- --check— all green.cofferdam gen-docsre-run and committed.🤖 Generated with Claude Code
https://claude.ai/code/session_019afugU2bTYCtXn6Vy9dn1v