Skip to content

Add JSON, color, verbose output modes, add text output for default UX, configure logger AddSource dynamically#6

Merged
thumbrise merged 9 commits into
mainfrom
first-runs
May 28, 2026
Merged

Add JSON, color, verbose output modes, add text output for default UX, configure logger AddSource dynamically#6
thumbrise merged 9 commits into
mainfrom
first-runs

Conversation

@thumbrise
Copy link
Copy Markdown
Owner

@thumbrise thumbrise commented May 28, 2026

Summary by CodeRabbit

  • New Features

    • Added --no-color flag to disable colored terminal output.
    • Added --json flag for machine-readable JSON output format.
    • Added build task for project compilation.
  • Tests

    • Added configuration loading test suite.
    • Enhanced scope parser test coverage.
  • Chores

    • Updated project dependencies and build configuration.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

Warning

Review limit reached

@thumbrise, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 44 minutes and 26 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 77fac473-b8be-46b3-9c61-238fd1c4afeb

📥 Commits

Reviewing files that changed from the base of the PR and between e7d0903 and 55b7126.

📒 Files selected for processing (3)
  • cmd/root.go
  • pkg/validator/config.go
  • pkg/validator/config_test.go
📝 Walkthrough

Walkthrough

This PR adds colored and JSON-formatted violation output to the CLI, consolidates logger configuration into the root command, updates config loading to provide default regex values, and refines logging levels. The color dependency is introduced to support terminal coloring of violation headers.

Changes

CLI Output Features and Config Defaults

Layer / File(s) Summary
Build infrastructure and color dependency
.gitignore, Taskfile.yaml, go.mod
Added build task to compile output into build/ directory, updated .gitignore to exclude build/* and commitlint-scope, and added github.com/fatih/color v1.19.0 dependency.
CLI flag refactoring and logger consolidation
cmd/root.go, main.go
Moved logger initialization from main.go to cmd/root.go, replaced simple flag variables (from/to) with package-level pointers (flagFrom/flagTo), added --verbose, --no-color, and --json flags, and consolidated logging setup into configureLogger.
Violation output formatting with colors and JSON
cmd/root.go
Updated validator invocation to use new flag variables, implemented a colored violation-count header, added conditional JSON or text output routing based on --json flag, and refactored output helpers to write to an io.Writer.
Config loading with default regex
pkg/validator/config.go
Modified LoadConfig to always return a Config with default scopeRegex even when the config file is missing, introduced ErrConfigRead for non-missing-file read errors, and allowed unmarshalling to proceed with viper defaults.
Test coverage for config and scope parsing
pkg/validator/config_test.go, pkg/validator/scope_parser_test.go
Added TestLoadConfig as a table-driven test verifying default regex application, pattern loading, custom regex overrides, and combined behavior; updated TestDefaultScopeParser_Parse to use inline regex construction and added a composed-scope test case.
Debug logging adjustments for skip conditions
pkg/validator/validator.go
Changed log level for "no message, skip" and "no scope, skip" messages from info to debug, and downgraded "no files changed, skip" log from info to debug.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • thumbrise/commitlint-scope#5: Introduced config loader and scope parser contracts that this PR now extends with default behavior and comprehensive test coverage.
  • thumbrise/commitlint-scope#2: Originally added Validator.Validate method; this PR adjusts its logging behavior for skip conditions.
  • thumbrise/commitlint-scope#1: Introduced initial CLI entrypoint in cmd/root.go and main.go; this PR significantly refactors both for new output and logger features.

Poem

🐰 A builder hops through colored fields,
With JSON paths the CLI now yields,
Defaults bloom where configs are bare,
And logs descend to debug air—
Compile and bind with furry cheer! 🎨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main changes: adding JSON and color output modes, verbose output, text output for UX, and dynamic logger configuration. It aligns with the substantive changes across cmd/root.go, main.go, go.mod, and supporting files.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch first-runs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@thumbrise thumbrise self-assigned this May 28, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
pkg/validator/config_test.go (1)

16-22: ⚡ Quick win

Add an error-path case for ErrConfigRead wrapping.

Current table covers only happy paths. Add one malformed config case and assert errors.Is(err, validator.ErrConfigRead) so the new sentinel contract is tested.

Also applies to: 76-78

🤖 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 `@pkg/validator/config_test.go` around lines 16 - 22, Add a negative test entry
to the tests table in pkg/validator/config_test.go that supplies malformed YAML
(so the parser fails) and in the test loop assert errors.Is(err,
validator.ErrConfigRead) for that case; specifically, update the tests slice
(the struct used to define cases) to include a case named like "malformed
config" that sets yaml to invalid content and expect an error, then in the test
runner for each case check that when err != nil you call errors.Is(err,
validator.ErrConfigRead) (in addition to any other assertions) to verify the
sentinel wrapping contract; ensure you reference the existing tests slice and
the ErrConfigRead sentinel from the validator package so the new case integrates
with the current test loop.
🤖 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 `@cmd/root.go`:
- Around line 131-139: The jsonOutput function currently encodes each Violation
separately producing NDJSON; change it to emit a single JSON array by encoding
the entire violations slice at once (e.g., use the existing encoder to
Encode(violations) or marshal with json.MarshalIndent) and return any error;
update jsonOutput (and its use of encoder/violations) so the output is one
well-formed JSON document and ensure the function returns nil on success.

In `@pkg/validator/config_test.go`:
- Around line 67-70: The deferred and immediate os.Chdir calls ignore returned
errors; update the test setup in config_test.go to check and handle both errors
(the defer that restores origDir and the os.Chdir(dir) call) by capturing their
error returns and failing the test (e.g., using t.Fatalf or require.NoError) if
they fail; reference the defer os.Chdir(origDir) restoration and the
os.Chdir(dir) setup call so you add proper error checks and clear failure
messages.

---

Nitpick comments:
In `@pkg/validator/config_test.go`:
- Around line 16-22: Add a negative test entry to the tests table in
pkg/validator/config_test.go that supplies malformed YAML (so the parser fails)
and in the test loop assert errors.Is(err, validator.ErrConfigRead) for that
case; specifically, update the tests slice (the struct used to define cases) to
include a case named like "malformed config" that sets yaml to invalid content
and expect an error, then in the test runner for each case check that when err
!= nil you call errors.Is(err, validator.ErrConfigRead) (in addition to any
other assertions) to verify the sentinel wrapping contract; ensure you reference
the existing tests slice and the ErrConfigRead sentinel from the validator
package so the new case integrates with the current test loop.
🪄 Autofix (Beta)

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 Plus

Run ID: aa3c4fa0-02dd-44a0-8832-733a11a6537d

📥 Commits

Reviewing files that changed from the base of the PR and between bc629f4 and e7d0903.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (9)
  • .gitignore
  • Taskfile.yaml
  • cmd/root.go
  • go.mod
  • main.go
  • pkg/validator/config.go
  • pkg/validator/config_test.go
  • pkg/validator/scope_parser_test.go
  • pkg/validator/validator.go
💤 Files with no reviewable changes (1)
  • main.go

Comment thread cmd/root.go
Comment thread pkg/validator/config_test.go Outdated
@thumbrise thumbrise merged commit c58ab20 into main May 28, 2026
4 checks passed
@thumbrise thumbrise deleted the first-runs branch May 28, 2026 05:54
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 0.6.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant