Repository navigation
Zsort corner cases - #179
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe import sorter now strips only line comments during semicolon detection and uses boundary-aware type keyword matching. Regression tests cover aliases, import preservation, expressions, and file-leading module documentation. ChangesImport sorter scanning
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tools/zsort.zig (1)
143-161: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winDo not match type keywords in trailing comments.
hasTypeKeywordscans the full line. A valid declaration such asconst dep =@import("dep"); // = structmatches= structand terminates the import block.
processSourcethen marks this import and later imports as stray. A correctly sorted file can failzsort checkbecausechangedis true when stray imports exist.Match the first token after the declaration assignment instead of searching the complete line. Add a regression case with a trailing
// = structcomment.Proposed fix
-fn hasTypeKeyword(trimmed: []const u8, kw: []const u8) bool { - const i = std.mem.indexOf(u8, trimmed, kw) orelse return false; - const after = i + kw.len; - return after >= trimmed.len or - (!std.ascii.isAlphanumeric(trimmed[after]) and trimmed[after] != '_'); +fn hasTypeKeyword(trimmed: []const u8, keyword: []const u8) bool { + const eq = std.mem.indexOfScalar(u8, trimmed, '=') orelse return false; + const rhs = std.mem.trimLeft(u8, trimmed[eq + 1 ..], " \t"); + if (!std.mem.startsWith(u8, rhs, keyword)) return false; + const after = keyword.len; + return after >= rhs.len or + (!std.ascii.isAlphanumeric(rhs[after]) and rhs[after] != '_'); } -if (hasTypeKeyword(trimmed, "= struct")) return false; +if (hasTypeKeyword(trimmed, "struct")) return false;🤖 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 `@tools/zsort.zig` around lines 143 - 161, Update hasTypeKeyword and its callers in isTopLevelImportLine to inspect only the first token following the declaration assignment, excluding trailing comments from type detection. Preserve recognition of actual struct, enum, union, and opaque declarations, and add a regression case covering an import with a trailing “// = struct” comment so zsort check remains unchanged.
🤖 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.
Outside diff comments:
In `@tools/zsort.zig`:
- Around line 143-161: Update hasTypeKeyword and its callers in
isTopLevelImportLine to inspect only the first token following the declaration
assignment, excluding trailing comments from type detection. Preserve
recognition of actual struct, enum, union, and opaque declarations, and add a
regression case covering an import with a trailing “// = struct” comment so
zsort check remains unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: f3762517-0858-4ee4-8ae8-85077731fca4
📒 Files selected for processing (2)
tools/zsort.zigtools/zsort_test.zig
Summary by CodeRabbit