Skip to content

feat: integrate cargo clippy#42

Merged
twangodev merged 3 commits intomainfrom
chore/clippy-fix
Nov 7, 2025
Merged

feat: integrate cargo clippy#42
twangodev merged 3 commits intomainfrom
chore/clippy-fix

Conversation

@twangodev
Copy link
Copy Markdown
Owner

@twangodev twangodev commented Nov 7, 2025

Summary by CodeRabbit

  • New Features

    • Improved SVG generation to accept structured text and image inputs for richer, more consistent card rendering.
  • Bug Fixes

    • Strengthened URL/IP validation and reinforced image size checks to reduce risk of unsafe or oversized image handling.
  • Refactor

    • Expanded public API surface to better support integration and reuse.
  • Chores

    • Added CI linting to enforce code quality.

Copilot AI review requested due to automatic review settings November 7, 2025 23:09
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Nov 7, 2025

Warning

Rate limit exceeded

@twangodev has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 53 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 0405450 and 17b4632.

📒 Files selected for processing (8)
  • src/generator/mod.rs (1 hunks)
  • src/generator/svg.rs (4 hunks)
  • src/image/fetch.rs (1 hunks)
  • src/image/parse.rs (1 hunks)
  • src/image/resolver.rs (2 hunks)
  • src/params.rs (2 hunks)
  • src/routes/index.rs (2 hunks)
  • src/templates.rs (1 hunks)

Walkthrough

The PR refactors the SVG generator API to accept two new structs—TextContent and Images—and re-exports them from src/generator/mod.rs. Call sites are updated to construct and pass these wrappers. Several nested conditionals and error constructions are simplified across image, params, resolver, and template code. CI adds a Clippy job.

Changes

Cohort / File(s) Summary
Generator API
src/generator/mod.rs, src/generator/svg.rs, src/routes/index.rs
Adds public structs TextContent and Images; changes generate_svg signature to generate_svg(text: TextContent, images: Images, template_name, templates, color_overrides, fontdb); re-exports Images and TextContent from the generator module; updates route to construct and pass the new wrappers.
Image fetching & parsing
src/image/fetch.rs, src/image/parse.rs
Simplifies nested conditionals into combined if let/&& pattern bindings for content-length and direct-IP SSRF checks while preserving behavior and error paths.
Resolver error handling
src/image/resolver.rs
Replaces explicit io::Error::new(io::ErrorKind::Other, e) constructions with io::Error::other(e) and updates boxed error usage accordingly.
Params & templates
src/params.rs, src/templates.rs
Merges nested guard checks into single combined conditions for length and color extraction; adds impl Default for TextWidthConstraints delegating to new() and streamlines max_widths parsing.
CI
.github/workflows/rust.yml
Adds a Clippy job (with toolchain setup and cargo clippy -- -D warnings) and makes Docker job depend on Clippy in addition to format and build jobs.

Sequence Diagram(s)

sequenceDiagram
    participant Route as Route Handler
    participant Generator as Generator::svg
    rect rgb(248, 250, 252)
    Note over Route,Generator: Former call (flattened params)
    Route->>Generator: generate_svg(title, description, subtitle, logo, image, template_name, ...)
    Generator->>Generator: use title/description/subtitle/logo/image directly
    end

    rect rgb(240, 255, 245)
    Note over Route,Generator: New call (grouped wrappers)
    Route->>Route: text = TextContent{title, description, subtitle}
    Route->>Route: images = Images{logo, image}
    Route->>Generator: generate_svg(text, images, template_name, ...)
    Generator->>Generator: use text.title/text.description/text.subtitle/images.logo/images.image
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

  • Check all call sites for generate_svg to ensure updated signatures and imports.
  • Verify impl Default for TextWidthConstraints does not cause recursion or unexpected behavior.
  • Confirm combined if let patterns preserve original short-circuit and error semantics.
  • Ensure error messages and types remain sensible after switching to io::Error::other().

Possibly related PRs

Poem

A rabbit nibbles code with nimble paws, 🐇
Bundles text and images without a pause,
Conditionals trimmed, Clippy keeps watch,
Exports aligned in a tidy hop-scotch,
Now SVGs march out with neater laws. ✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title check ⚠️ Warning The pull request title 'feat: integrate cargo clippy' primarily describes the workflow addition, but the changeset includes substantial refactoring of the core API (TextContent/Images structs, generate_svg signature, parameter consolidation across multiple files) that represents the main changes by scope and impact. Consider a more comprehensive title that captures the primary refactoring, such as 'refactor: consolidate text and image parameters into structs' or 'refactor: restructure API parameters and integrate clippy'.
Docstring Coverage ⚠️ Warning Docstring coverage is 53.85% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the codebase to use let-chains (a Rust 1.80+ feature) for cleaner nested conditional logic and introduces better API design through structured parameters in the SVG generation function. The changes include consolidating multiple string and image parameters into dedicated TextContent and Images structs, and replacing nested if let statements with more concise let-chain syntax throughout the codebase.

Key changes:

  • Introduced TextContent and Images structs to group related parameters in the SVG generator
  • Replaced nested if let statements with let-chains across multiple files for improved readability
  • Simplified error handling in the image resolver using io::Error::other()

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/templates.rs Adds Default implementation for TextWidthConstraints and refactors parse_width_constraints to use let-chains
src/routes/index.rs Updates to use new TextContent and Images structs when calling generate_svg
src/params.rs Refactors validation and color extraction logic to use let-chains
src/image/resolver.rs Simplifies error mapping to use io::Error::other()
src/image/parse.rs Refactors SSRF protection checks to use let-chains
src/image/fetch.rs Refactors Content-Length validation to use let-chains
src/generator/svg.rs Introduces TextContent and Images structs and updates generate_svg signature to use them
src/generator/mod.rs Exports new TextContent and Images structs
Comments suppressed due to low confidence (1)

src/templates.rs:33

  • This creates infinite recursion. The struct derives Default on line 9 (via #[derive(Default)]), but then manually implements Default::default() which calls new(), and new() calls Self::default(). This will cause a stack overflow at runtime.

Either remove the manual Default implementation (since it's already derived), or remove Default from the derive attribute and implement it properly. If you want new() to use custom logic, have default() implement that logic directly and have new() call default().

impl Default for TextWidthConstraints {
    fn default() -> Self {
        Self::new()
    }
}

impl TextWidthConstraints {
    pub fn new() -> Self {
        Self::default()
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a137219 and 7083aee.

📒 Files selected for processing (8)
  • src/generator/mod.rs (1 hunks)
  • src/generator/svg.rs (4 hunks)
  • src/image/fetch.rs (1 hunks)
  • src/image/parse.rs (1 hunks)
  • src/image/resolver.rs (2 hunks)
  • src/params.rs (2 hunks)
  • src/routes/index.rs (2 hunks)
  • src/templates.rs (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
src/image/resolver.rs (1)
src/image/mod.rs (1)
  • new (25-61)
src/generator/mod.rs (1)
src/generator/svg.rs (1)
  • generate_svg (122-184)
src/routes/index.rs (1)
src/generator/svg.rs (1)
  • generate_svg (122-184)
🪛 GitHub Check: Format Check
src/routes/index.rs

[warning] 1-1:
Diff in /home/runner/work/ogis/ogis/src/routes/index.rs

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Agent
  • GitHub Check: Code Coverage
  • GitHub Check: Code Coverage
🔇 Additional comments (14)
src/image/fetch.rs (1)

36-37: LGTM! Cleaner conditional with let-chains.

The refactored conditional using let-chains (&&) is more idiomatic and readable than nested if statements, while preserving the same logic.

src/params.rs (2)

69-70: LGTM! Improved readability with let-chains.

The combined conditional reduces nesting and makes the validation logic more concise.


89-90: LGTM! Cleaner guard condition.

Combining the template color map existence check with the key presence check into a single conditional improves readability.

src/image/parse.rs (1)

41-43: LGTM! Excellent SSRF protection refactor.

The let-chain syntax makes the multi-step IP validation more readable while maintaining the security logic.

src/templates.rs (1)

114-114: LGTM! Cleaner conditional with let-chains.

The combined pattern matching reduces nesting and improves readability.

src/image/resolver.rs (2)

16-16: LGTM! Modern error handling.

Using io::Error::other is the idiomatic way to convert errors in modern Rust (1.74+).


33-33: LGTM! Simplified error construction.

The io::Error::other helper is more concise than manually constructing errors with ErrorKind::Other.

src/generator/mod.rs (1)

9-9: LGTM! Public API expansion for wrapper structs.

Exporting Images and TextContent allows consumers to use the new grouped parameter API, which is cleaner than passing individual text and image parameters.

src/routes/index.rs (2)

1-1: LGTM! Updated imports for new API.

The import correctly includes the new TextContent and Images wrapper structs.


166-175: LGTM! Cleaner API with grouped parameters.

Grouping related text fields into TextContent and images into Images significantly improves the clarity of the generate_svg call by reducing the parameter count and making the relationship between parameters explicit.

src/generator/svg.rs (4)

15-24: LGTM! Well-designed wrapper structs.

The new TextContent and Images structs effectively group related parameters. Using lifetimes in TextContent avoids unnecessary string copies, while Images appropriately owns the image data.


122-129: LGTM! Improved function signature.

Refactoring the signature from 9 individual parameters to use TextContent and Images structs makes the function more maintainable and easier to use. The grouping makes the relationship between parameters explicit.


137-137: LGTM! Consistent usage of new structs.

The code correctly accesses text fields through the TextContent struct.


152-159: LGTM! Proper handling of image wrappers.

The image replacement logic correctly extracts data from the Images struct fields.

Copy link
Copy Markdown
Contributor

@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: 0

🧹 Nitpick comments (1)
.github/workflows/rust.yml (1)

23-34: Optional: Consider adding Rust cache for faster CI runs.

The clippy job could benefit from cargo dependency caching to reduce build time on subsequent runs, similar to how other projects structure their workflows.

You could optionally add caching by incorporating the Swatinem/rust-cache action:

      - uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          components: clippy

+     - uses: Swatinem/rust-cache@v2

      - name: Run Clippy
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7083aee and 0405450.

📒 Files selected for processing (1)
  • .github/workflows/rust.yml (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Code Coverage
🔇 Additional comments (2)
.github/workflows/rust.yml (2)

23-34: Clippy job structure looks good.

The job follows the established pattern from the format job and is well-configured. The use of --all-targets --all-features -- -D warnings is appropriate for comprehensive linting and will catch issues across all targets and feature combinations.


72-72: Docker job dependency appropriately updated.

Adding clippy to the dependency list ensures clippy checks pass before Docker images are built, which aligns with the PR objective to integrate clippy into the CI pipeline.

Copilot AI review requested due to automatic review settings November 7, 2025 23:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link
Copy Markdown

codecov bot commented Nov 7, 2025

Codecov Report

❌ Patch coverage is 0% with 47 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/templates.rs 0.00% 17 Missing ⚠️
src/params.rs 0.00% 9 Missing ⚠️
src/generator/svg.rs 0.00% 5 Missing ⚠️
src/image/parse.rs 0.00% 5 Missing ⚠️
src/routes/index.rs 0.00% 5 Missing ⚠️
src/image/fetch.rs 0.00% 4 Missing ⚠️
src/image/resolver.rs 0.00% 2 Missing ⚠️
Files with missing lines Coverage Δ
src/image/resolver.rs 0.00% <0.00%> (ø)
src/image/fetch.rs 0.00% <0.00%> (ø)
src/generator/svg.rs 10.00% <0.00%> (-0.30%) ⬇️
src/image/parse.rs 0.00% <0.00%> (ø)
src/routes/index.rs 0.00% <0.00%> (ø)
src/params.rs 0.00% <0.00%> (ø)
src/templates.rs 3.22% <0.00%> (-0.03%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@twangodev twangodev merged commit 70dace4 into main Nov 7, 2025
19 of 20 checks passed
@twangodev twangodev deleted the chore/clippy-fix branch November 7, 2025 23:32
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.

2 participants