Skip to content

Fix clippy warnings and add optional config parsers#31

Merged
leynos merged 2 commits intomainfrom
codex/run-make-lint-and-fix-violations
Jul 26, 2025
Merged

Fix clippy warnings and add optional config parsers#31
leynos merged 2 commits intomainfrom
codex/run-make-lint-and-fix-violations

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Jul 26, 2025

Summary

  • enable JSON5/YAML config parsing via new optional dependencies
  • document config features in design doc
  • fix clippy lints across the project

Testing

  • make fmt
  • make lint
  • make test

https://chatgpt.com/codex/tasks/task_e_6884b4830dbc83228e2938292973d5f1

Summary by Sourcery

Enable optional JSON5 and YAML configuration parsing and apply clippy-driven refactorings across the codebase

New Features:

  • Add optional JSON5 and YAML configuration parsing via feature flags

Enhancements:

  • Fix clippy warnings and refactor code (unwrap to expect, to_owned, Self usage, Option/map_or_else patterns, slice handling) for consistency and clarity

Documentation:

  • Document JSON5 and YAML configuration features in the design doc

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Jul 26, 2025

Reviewer's Guide

This PR introduces optional JSON5/YAML config parsing via new feature flags (figment-json5, serde_yaml) and updates the design document, alongside a broad sweep of Clippy lint fixes—replacing unwraps with expect, switching to .to_owned(), adding lint allow reasons, and adopting more idiomatic Rust patterns—and refactors diff and reference parsing logic for improved safety and clarity, with a minor signature change in GlobalArgs.

Class diagram for updated GlobalArgs::merge signature

classDiagram
    class GlobalArgs {
        +Option<String> repo
        +fn merge(&mut self, other: Self)
    }
Loading

Class diagram for new optional config features in Cargo.toml

classDiagram
    class Features {
        +toml: [figment, xdg, uncased, toml, ortho_config/toml]
        +json5: [toml, figment-json5, ortho_config/json5]
        +yaml: [toml, serde_yaml, ortho_config/yaml]
    }
    class Dependencies {
        +figment-json5 (optional)
        +serde_yaml (optional)
    }
    Features -- Dependencies
Loading

File-Level Changes

Change Details Files
Enable optional JSON5/YAML configuration parsing
  • Add figment-json5 and serde_yaml as optional dependencies
  • Update json5 and yaml feature definitions in Cargo.toml to include the new deps
  • Expand docs/vk-design.md with a new configuration and features section
Cargo.toml
docs/vk-design.md
Apply Clippy lint fixes across the codebase
  • Replace unwrap() calls with expect(...) and descriptive messages
  • Swap .to_string() for .to_owned() on static strings and regex patterns
  • Add reason clauses to #[allow(...)] lint attributes
  • Use Self::Variant instead of explicit enum names
src/main.rs
src/cli_args.rs
Refactor parsing and slicing logic for clarity and safety
  • Use map_or_else to streamline HUNK_RE.captures handling
  • Replace manual string slicing with split_off for gutter formatting
  • Switch from index-based segments[...] to segments.get(...).expect(...)
  • Use lines.get(start..end).unwrap_or(&[]) instead of slicing directly
src/main.rs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jul 26, 2025

Warning

Rate limit exceeded

@leynos has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 35 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, 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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between c8aacd6 and 48c3aba.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • Cargo.toml (1 hunks)
  • docs/vk-design.md (4 hunks)

Summary by CodeRabbit

  • Documentation

    • Improved clarity and formatting in documentation, including a new section describing configuration file support and feature flags for JSON5 and YAML.
  • Style

    • Refined code for clarity, safety, and idiomatic usage, including improved error messages and safer handling of data.
  • Chores

    • Updated optional dependencies and feature flags for JSON5 and YAML configuration file support.

Walkthrough

Update the project dependencies in Cargo.toml to explicitly include figment-json5 and serde_yaml under the json5 and yaml features. Refine documentation to describe configuration options and feature flags. Adjust a method signature in cli_args.rs for idiomatic style. Refactor main.rs for improved clarity, error handling, and code safety.

Changes

File(s) Change Summary
Cargo.toml Add figment-json5 and serde_yaml as optional dependencies; update json5 and yaml features to include these.
docs/vk-design.md Refine documentation for clarity; add section on configuration and feature flags.
src/cli_args.rs Change merge method parameter from GlobalArgs to Self for idiomatic style.
src/main.rs Refactor for improved error handling, code clarity, and safe access patterns; no logic changes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant vk (CLI)
    participant figment
    participant figment-json5
    participant serde_yaml

    User->>vk (CLI): Run with config file and feature flags
    vk (CLI)->>figment: Load config file
    alt JSON5 feature enabled
        figment->>figment-json5: Parse JSON5 config
    end
    alt YAML feature enabled
        figment->>serde_yaml: Parse YAML config
    end
    figment-->>vk (CLI): Return parsed configuration
    vk (CLI)-->>User: Operate with loaded configuration
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Possibly related PRs

Poem

New crates arrive, the features grow,
JSON5 and YAML now in tow.
Docs are polished, style refined,
Error messages clear, robust by design.
With safer code and clearer prose,
The project blooms as progress shows! 🚀

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/run-make-lint-and-fix-violations

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey @leynos - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `docs/vk-design.md:8` </location>
<code_context>
-associated review threads through the GitHub GraphQL API. Each thread is printed
-with syntax highlighting using Termimad. Diffs appear once per thread, even when
-multiple comments reference the same code.
+`vk` (View Komments) is a CLI tool for inspecting unresolved GitHub pull
+request comments. Users supply a pull request URL or number, and `vk` fetches
+the associated review threads through the GitHub GraphQL API. Each thread is
</code_context>

<issue_to_address>
Paragraph is not wrapped to 80 columns as required by the style guide.

Please ensure that all paragraphs and bullet points are wrapped to 80 columns. This helps maintain readability and consistency throughout the documentation.
</issue_to_address>

### Comment 2
<location> `docs/vk-design.md:27` </location>
<code_context>
 The code centres on three printing helpers:

-1. `write_comment_body` formats a single comment body to any `Write` implementation.
+1. `write_comment_body` formats a single comment body to any `Write`
+   implementation.
 2. `write_comment` includes the diff for the first comment in a thread.
</code_context>

<issue_to_address>
Bullet point is not wrapped to 80 columns as required.

Bullet points should be wrapped to 80 columns to maintain consistent formatting. Please adjust the wrapping accordingly.
</issue_to_address>

### Comment 3
<location> `docs/vk-design.md:38` </location>
<code_context>
-printing results.
-The public `GlobalArgs`, `PrArgs`, and `IssueArgs` structures are fully
-documented so their purpose and merge semantics are clear to downstream users.
+[src/cli_args.rs](../src/cli_args.rs). Keeping these structures in a dedicated
+module isolates the lint expectations generated by `clap` and keeps `main.rs`
+focused on orchestrating API calls and printing results. The public
</code_context>

<issue_to_address>
Paragraph is not wrapped to 80 columns as required.

Please wrap this paragraph to 80 columns for consistency with the documentation style guide.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread docs/vk-design.md
Comment thread docs/vk-design.md
Comment thread docs/vk-design.md
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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5139763 and c8aacd6.

📒 Files selected for processing (4)
  • Cargo.toml (1 hunks)
  • docs/vk-design.md (4 hunks)
  • src/cli_args.rs (1 hunks)
  • src/main.rs (26 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.rs

📄 CodeRabbit Inference Engine (AGENTS.md)

**/*.rs: Run cargo fmt, cargo clippy -- -D warnings, and RUSTFLAGS="-D warnings" cargo test before committing.
Clippy warnings MUST be disallowed.
Fix any warnings emitted during tests in the code itself rather than silencing them.
Where a function is too long, extract meaningfully named helper functions adhering to separation of concerns and CQRS.
Where a function has too many parameters, group related parameters in meaningfully named structs.
Where a function is returning a large error consider using Arc to reduce the amount of data returned.
Write unit and behavioural tests for new functionality. Run both before and after making any change.
Document public APIs using Rustdoc comments (///) so documentation can be generated with cargo doc.
Prefer immutable data and avoid unnecessary mut bindings.
Handle errors with the Result type instead of panicking where feasible.
Avoid unsafe code unless absolutely necessary and document any usage clearly.

Files:

  • src/cli_args.rs
  • src/main.rs

⚙️ CodeRabbit Configuration File

**/*.rs: * Seek to keep the cyclomatic complexity of functions no more than 12.

  • Adhere to single responsibility and CQRS

  • Place function attributes after doc comments.

  • Do not use return in single-line functions.

  • Move conditionals with >2 branches into a predicate function.

  • Avoid unsafe unless absolutely necessary.

  • Every module must begin with a //! doc comment that explains the module's purpose and utility.

  • Comments and docs must follow en-GB-oxendict (-ize / -our) spelling and grammar

  • Lints must not be silenced except as a last resort.

    • #[allow] is forbidden.
    • Only narrowly scoped #[expect(lint, reason = "...")] is allowed.
    • No lint groups, no blanket or file-wide suppression.
    • Include FIXME: with link if a fix is expected.
  • Use rstest fixtures for shared setup and to avoid repetition between tests.

  • Replace duplicated tests with #[rstest(...)] parameterised cases.

  • Prefer mockall for mocks/stubs.

  • Prefer .expect() over .unwrap()

  • Ensure that any API or behavioural changes are reflected in the documentation in docs/

  • Ensure that any completed roadmap steps are recorded in the appropriate roadmap in docs/

  • Files must not exceed 400 lines in length

    • Large modules must be decomposed
    • Long match statements or dispatch tables should be decomposed by domain and collocated with targets
    • Large blocks of inline data (e.g., test fixtures, constants or templates) must be moved to external files and inlined at compile-time or loaded at run-time.

Files:

  • src/cli_args.rs
  • src/main.rs
docs/**/*.md

📄 CodeRabbit Inference Engine (AGENTS.md)

docs/**/*.md: Reference: Use the markdown files within the docs/ directory as a knowledge base and source of truth for project requirements, dependency choices, and architectural decisions.
Update: When new decisions are made, requirements change, libraries are added/removed, or architectural patterns evolve, proactively update the relevant file(s) in the docs/ directory to reflect the latest state.

Files:

  • docs/vk-design.md
**/*.md

📄 CodeRabbit Inference Engine (AGENTS.md)

**/*.md: Validate Markdown files using markdownlint.
Validate Markdown Mermaid diagrams using the nixie CLI.

Files:

  • docs/vk-design.md

⚙️ CodeRabbit Configuration File

**/*.md: * Avoid 2nd person or 1st person pronouns ("I", "you", "we")

  • Use en-GB-oxendict (-ize / -our) spelling and grammar
  • Paragraphs and bullets must be wrapped to 80 columns, except where a long URL would prevent this (in which case, silence MD013 for that line)
  • Code blocks should be wrapped to 120 columns.
  • Headings must not be wrapped.
  • Documents must start with a level 1 heading
  • Headings must correctly increase or decrease by no more than one level at a time
  • Use GitHub-flavoured Markdown style for footnotes and endnotes.
  • Numbered footnotes must be numbered by order of appearance in the document.

Files:

  • docs/vk-design.md
Cargo.toml

📄 CodeRabbit Inference Engine (AGENTS.md)

Use explicit version ranges in Cargo.toml and keep dependencies up-to-date.

Files:

  • Cargo.toml
🪛 LanguageTool
docs/vk-design.md

[uncategorized] ~74-~74: Possible missing comma found.
Context: ...in the figment-json5 and serde_yaml crates respectively.

(AI_HYDRA_LEO_MISSING_COMMA)

🔇 Additional comments (16)
src/cli_args.rs (1)

26-26: Excellent idiomatic improvement using Self.

This change satisfies the use_self clippy lint and improves code consistency.

Cargo.toml (1)

24-25: Good addition of optional parsing dependencies.

The explicit dep: syntax in the feature definitions is correct modern Cargo practice.

docs/vk-design.md (1)

70-74: Excellent documentation of new configuration features.

The new section clearly explains the optional JSON5 and YAML support and aligns perfectly with the Cargo.toml changes.

src/main.rs (13)

58-60: Excellent use of Self:: for enum variants.

This satisfies the use_self clippy lint and improves code consistency.


91-93: Good improvement using .expect() with descriptive messages.

Replacing .unwrap() with .expect("valid regex") provides better error diagnostics when regex compilation fails.

Also applies to: 95-96, 101-101


219-222: Well-documented lint suppressions with explicit reasons.

The expanded #[allow] attributes with reasons satisfy the coding guidelines requirement to avoid blanket suppressions.

Also applies to: 242-242


454-454: Appropriate use of .to_owned() for string cloning.

This is more semantically correct than .to_string() when cloning existing strings.

Also applies to: 459-459


480-482: Good replacement of string slicing with .split_off().

This avoids potential panics from string slicing and is more explicit about the intent.


491-513: Excellent refactor using map_or_else for cleaner control flow.

The replacement of if-else logic with map_or_else is more idiomatic and improves readability.


518-521: Outstanding use of safe indexing with .get() and fallbacks.

Replacing direct indexing with .get() and .unwrap_or(&[]) prevents potential panics and satisfies the indexing_slicing = "deny" lint requirement.

Also applies to: 524-524


638-650: Good use of .expect() for static string parsing.

Using .expect("static string") and .expect("valid header") provides better error context than .unwrap().


654-657: Proper lint suppression with detailed reasoning.

The #[allow(clippy::result_large_err)] attributes with explanatory reasons follow the coding guidelines for narrow, documented lint suppressions.

Also applies to: 688-691, 740-743, 760-763, 806-809, 817-820


774-790: Excellent replacement of unsafe indexing with bounds-checked access.

Using .get() with .expect("length checked") and .to_owned() instead of direct indexing and .to_string() improves both safety and semantic correctness.


830-832: Good use of .to_owned() for string extraction from regex captures.

This is more semantically appropriate than .to_string() when extracting owned strings from borrowed data.

Also applies to: 841-854


845-847: Excellent use of iterator methods instead of collecting.

Using splitn(2, '/') with iterator methods instead of collecting into vectors is more efficient and clearer.


888-889: Consistent improvement using .expect() with descriptive messages.

Throughout the test code, replacing .unwrap() with .expect() provides better error diagnostics and aligns with the coding guidelines.

Also applies to: 897-898, 906-906, 908-908, 913-918, 924-924, 931-931, 958-958, 961-961, 967-967, 988-991, 997-997, 1005-1005, 1009-1009, 1027-1027, 1036-1036, 1047-1047, 1058-1058, 1067-1067, 1076-1077, 1086-1087, 1095-1095, 1103-1103, 1155-1156, 1166-1166, 1192-1193

Comment thread Cargo.toml
Comment thread docs/vk-design.md Outdated
@leynos leynos merged commit 94f53d0 into main Jul 26, 2025
1 check passed
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