Repository navigation
feat: implement support for import at the bottom of the file - #16
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe PR adds a ChangesBottom import layout
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant CLI
participant FileJob
participant processSource
participant File
CLI->>FileJob: pass bottom=true
FileJob->>processSource: process source with bottom mode
processSource->>File: separate preamble, imports, and body
processSource->>File: append sorted import block
File-->>CLI: return rewritten source or full-file diff
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/zsort_test.zig (1)
574-585: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert import relocation in the CRLF test.
The test only checks that CRLF line endings remain valid. A regression that leaves imports at the top can pass this test. Assert the expected bottom-layout output.
Proposed test update
try std.testing.expect(result.changed); + try std.testing.expectEqualStrings( + "pub fn main() !void {}\r\n\r\n" ++ + "const a = `@import`(\"a.zig\");\r\n" ++ + "const b = `@import`(\"b.zig\");\r\n", + result.new_text, + ); var prev: u8 = 0;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/zsort_test.zig` around lines 574 - 585, Update the test named “processSource: --bottom preserves CRLF line endings” to assert that result.new_text matches the expected output with imports relocated to the bottom, while retaining the existing CRLF validation. Use the source’s import and blank-line structure to verify the complete bottom-layout result.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/zsort.zig`:
- Around line 233-246: Update the bottom-mode import emission to compute
attached comment starts with attachedCommentHeadStart for every import,
including top-region and stray imports, rather than relying on
Import.comment_start. Remove the first_start special-case block and preserve
contiguous attachment boundaries so repeated --bottom formatting remains
idempotent.
---
Nitpick comments:
In `@src/zsort_test.zig`:
- Around line 574-585: Update the test named “processSource: --bottom preserves
CRLF line endings” to assert that result.new_text matches the expected output
with imports relocated to the bottom, while retaining the existing CRLF
validation. Use the source’s import and blank-line structure to verify the
complete bottom-layout result.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 2b6979cf-873f-40a5-8a4a-3e61fe540b06
📒 Files selected for processing (5)
CHANGELOG.mdREADME.mdsrc/ast_scan.zigsrc/zsort.zigsrc/zsort_test.zig
Summary by CodeRabbit
New Features
--bottomoption that moves the complete sorted import block to the end of a file.checkandfixmodes.Documentation
--bottomusage and behavior in the README and changelog.