Skip to content

Pre Commit Hook - #9

Merged
mstdokumaci merged 3 commits into
mainfrom
pre-commit
Aug 5, 2026
Merged

mstdokumaci merged 3 commits into
mainfrom
pre-commit

Conversation

@mstdokumaci

@mstdokumaci mstdokumaci commented Aug 5, 2026 •

Copy link
Copy Markdown
Owner

closing #8

Summary by CodeRabbit

  • New Features

    • Check and fix commands now accept multiple files and directories in one invocation.
    • Directories are scanned recursively, with results reported across all targets.
    • Added pre-commit hooks to verify or automatically sort Zig imports.
  • Bug Fixes

    • Processing continues when individual targets are inaccessible or invalid, with failed targets reported together.
    • Improved terminal output handling for special characters.
  • Documentation

    • Expanded CLI usage, multi-target examples, pre-commit setup, configuration, version pinning, and changed-file behavior.
    • Added unreleased change notes.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 26a2c4ee-e7bb-4de2-b1e0-ad09ea117259

📥 Commits

Reviewing files that changed from the base of the PR and between e241aee and 7df5f36.

📒 Files selected for processing (1)
  • src/zsort.zig
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/zsort.zig

📝 Walkthrough

Walkthrough

Changes

The CLI now accepts multiple files or directories, processes targets independently, and reports target errors after collection. Tests cover ordered multi-target parsing. Documentation and the pre-commit manifest describe multi-target usage and Zig import-ordering hooks.

Multi-target CLI and integration

Layer / File(s) Summary
Target collection and CLI contract
src/zsort.zig, src/zsort_test.zig
Args stores multiple targets. Argument parsing, help text, escaping, and tests support the updated CLI behavior.
Target processing and error handling
src/zsort.zig
runMain processes files and directories across all targets and preserves failures while continuing.
Pre-commit integration and documentation
.pre-commit-hooks.yaml, README.md, CHANGELOG.md
The project adds zsort and zsort-fix hooks and documents multi-target commands and hook configuration.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant parseArgs
  participant runMain
  participant Filesystem
  CLI->>parseArgs: collect positional targets
  parseArgs-->>CLI: return Args.targets
  CLI->>runMain: process Args.targets
  runMain->>Filesystem: inspect each target
  Filesystem-->>runMain: target type or access error
  runMain-->>CLI: report files, failures, or no-file result
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main feature: adding pre-commit hook support.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pre-commit

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 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 `@README.md`:
- Line 121: Update the README zsort example to use non-overlapping targets,
replacing the redundant src/main.zig target with a Zig file outside src/, such
as build.zig, so the same file is not processed twice.
- Around line 140-142: Publish the v0.5.0 release tag containing the pre-commit
hooks before users apply this README configuration, and keep the rev set to
v0.5.0 rather than changing it to v0.4.0.

In `@src/zsort.zig`:
- Around line 823-824: Update the target-processing loop around compat.openDir
to catch directory-opening errors instead of propagating them through runMain.
Report the affected target, increment error_count, and continue with subsequent
targets; retain the existing defer cleanup and processing flow for successfully
opened directories.
- Around line 825-826: Release the `.gitignore` pattern allocations after each
directory scan by freeing the slice and its individual patterns once `walkDir`
returns. Update the flow around `loadGitignore` and `walkDir` so cleanup occurs
on both successful and failing scans, while preserving the existing directory
traversal behavior.
🪄 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: 1b538ea6-e50a-4d17-9c89-c0fafe1a43d2

📥 Commits

Reviewing files that changed from the base of the PR and between 23f7bfb and 756c8e1.

📒 Files selected for processing (5)
  • .pre-commit-hooks.yaml
  • CHANGELOG.md
  • README.md
  • src/zsort.zig
  • src/zsort_test.zig

Comment thread README.md Outdated
Comment thread README.md
Comment thread src/zsort.zig Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/zsort.zig (2)

40-51: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Remove the contradictory escapeTerm contract.

Line 43 says allocation failure returns the raw input. Line 44 describes ESC-only escaping. Lines 45-50 define five-byte escaping and error.OutOfMemory propagation. Keep one current contract so callers do not rely on removed behavior.

🤖 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.zig` around lines 40 - 51, Update the documentation for escapeTerm
to remove the obsolete ESC-only behavior and raw-input-on-OOM contract. Keep
only the current five-byte terminal-control escaping behavior and the
error.OutOfMemory propagation guarantee, ensuring callers rely on this single
consistent contract.

817-824: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Release escaped target strings after error reporting.

When a target contains an escaped control byte, escapeTerm returns a new allocation. The calls at Lines 817, 824, 838, and 846 pass that allocation directly to compat.printStderr and lose ownership. Multi-target error handling can retain one allocation per message until process exit.

Bind each result to a local value and conditionally free it when its pointer differs from the original target, as done at Lines 887-888.

Also applies to: 838-846

🤖 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.zig` around lines 817 - 824, Update the error-reporting paths
around the directory/stat handling and the corresponding blocks at lines 838-846
to store each escapeTerm result in a local variable, pass it to
compat.printStderr, then free it when its pointer differs from the original
target, matching the existing ownership pattern at lines 887-888.
🤖 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`:
- Line 834: Update the recursive scan call in runMain to catch walkDir errors
per target instead of propagating every error with try. Report the affected
target and increment error_count for recoverable filesystem errors, continue
scanning subsequent targets, and preserve propagation of error.OutOfMemory.

---

Outside diff comments:
In `@src/zsort.zig`:
- Around line 40-51: Update the documentation for escapeTerm to remove the
obsolete ESC-only behavior and raw-input-on-OOM contract. Keep only the current
five-byte terminal-control escaping behavior and the error.OutOfMemory
propagation guarantee, ensuring callers rely on this single consistent contract.
- Around line 817-824: Update the error-reporting paths around the
directory/stat handling and the corresponding blocks at lines 838-846 to store
each escapeTerm result in a local variable, pass it to compat.printStderr, then
free it when its pointer differs from the original target, matching the existing
ownership pattern at lines 887-888.
🪄 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: be2dc3f4-2a7c-44ce-97e0-9f10cf9e3993

📥 Commits

Reviewing files that changed from the base of the PR and between 756c8e1 and e241aee.

📒 Files selected for processing (2)
  • README.md
  • src/zsort.zig
🚧 Files skipped from review as they are similar to previous changes (1)
  • README.md

Comment thread src/zsort.zig Outdated
@mstdokumaci
mstdokumaci merged commit 9be017a into main Aug 5, 2026
10 checks passed
@mstdokumaci
mstdokumaci deleted the pre-commit branch August 5, 2026 08:17
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