Skip to content

Preserve trailing spaces on final wrap flush#193

Merged
leynos merged 4 commits intomainfrom
codex/fix-final-flush-to-preserve-trailing-spaces
Aug 19, 2025
Merged

Preserve trailing spaces on final wrap flush#193
leynos merged 4 commits intomainfrom
codex/fix-final-flush-to-preserve-trailing-spaces

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Aug 18, 2025

Summary

  • avoid trimming trailing spaces in wrap_preserving_code
  • test for retaining trailing spaces at line end

Testing

  • make fmt
  • make lint
  • make test

closes #65


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

Summary by Sourcery

Preserve trailing spaces when flushing the final line in wrap_preserving_code

Bug Fixes:

  • Stop trimming trailing spaces in wrap_preserving_code

Tests:

  • Add test to ensure wrap_preserving_code retains trailing spaces on the final line

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Aug 18, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactor wrap_preserving_code to preserve trailing spaces in the final line rather than trimming them and add corresponding test to verify this behavior.

Class diagram for updated wrap_preserving_code function

classDiagram
    class wrap_preserving_code {
        +wrap_preserving_code(text: &str, width: usize) Vec<String>
    }
    %% The function now preserves trailing spaces in the final line instead of trimming them.
Loading

File-Level Changes

Change Details Files
Stop trimming trailing spaces on final flush in wrap_preserving_code
  • Removed trim_end() call on current buffer
  • Push raw current string when non-empty instead of trimmed version
src/wrap.rs
Add test for retaining trailing spaces
  • Introduce wrap_preserving_code_keeps_trailing_spaces test
  • Assert that trailing spaces are preserved at line end
src/wrap/tests.rs

Assessment against linked issues

Issue Objective Addressed Explanation
#65 Remove trimming of trailing spaces in the final flush of wrap_preserving_code, so that trailing spaces are preserved consistently.
#65 Add a test to verify that wrap_preserving_code retains trailing spaces at the end of the final line.

Possibly linked issues


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
Contributor

coderabbitai Bot commented Aug 18, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Warning

Rate limit exceeded

@leynos has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 1 minutes and 45 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 acc2835 and 2da8d82.

📒 Files selected for processing (4)
  • CHANGELOG.md (1 hunks)
  • docs/trailing-spaces.md (1 hunks)
  • src/wrap.rs (1 hunks)
  • src/wrap/tests.rs (2 hunks)

Summary by CodeRabbit

  • Bug Fixes
    • Trailing spaces at the end of the final line in wrapped text are now preserved, preventing unintended trimming.
    • Improves display fidelity for content where ending whitespace is significant (e.g., code snippets or aligned text).
    • Ensures multi-line wrapping retains any trailing spaces on the last emitted line.

Walkthrough

Modify wrap_preserving_code to push the final buffer without trim_end, preserving trailing spaces on the last line. Add parameterised tests verifying trailing spaces are kept, including edge cases and wrapping behaviour.

Changes

Cohort / File(s) Summary
Wrapping logic
src/wrap.rs
Change final flush in wrap_preserving_code to push current buffer without trimming trailing whitespace.
Tests
src/wrap/tests.rs
Add rstest-based parameterised tests ensuring trailing spaces are preserved on the final line and under wrapping.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Assessment against linked issues

Objective Addressed Explanation
Fix inconsistent trailing space handling in wrap_preserving_code final flush [#65]

Possibly related issues

Poem

A space at the end, once trimmed away,
Now rests intact at close of day.
Wrapping whispers, tests agree,
“Leave the tail as it should be.”
Code exhales—no cuts, no chase—
The final line retains its space.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/fix-final-flush-to-preserve-trailing-spaces

🪧 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

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

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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 there - I've reviewed your changes and found some issues that need to be addressed.

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

### Comment 1
<location> `src/wrap/tests.rs:114` </location>
<code_context>
 }
+
+#[test]
+fn wrap_preserving_code_keeps_trailing_spaces() {
+    // Trailing spaces should be retained when flushing the final line.
+    let lines = super::wrap_preserving_code("ends with space  ", 80);
+    assert_eq!(lines, vec!["ends with space  ".to_string()]);
+}
</code_context>

<issue_to_address>
Consider adding more edge cases for trailing spaces.

Please add tests for cases like multiple consecutive trailing spaces, inputs consisting only of spaces, and trailing spaces after line breaks or within longer text to ensure consistent handling.
</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 src/wrap/tests.rs Outdated
@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Aug 19, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 19, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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: 2

📜 Review details

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

💡 Knowledge Base configuration:

  • Jira integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 4e016e3 and acc2835.

📒 Files selected for processing (2)
  • src/wrap.rs (1 hunks)
  • src/wrap/tests.rs (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.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.
  • Where code is only used by specific features, it must be conditionally compiled or a conditional expectation for unused_code applied.

  • 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/wrap.rs
  • src/wrap/tests.rs
🔇 Additional comments (2)
src/wrap.rs (1)

163-165: Preserve trailing spaces on final flush — correct and minimal fix

Stop trimming with trim_end() on the last emission and move current into the vector. This aligns the final flush with the earlier loop’s whitespace-preserving behaviour and removes the inconsistency reported in #65. LGTM.

src/wrap/tests.rs (1)

6-7: Confirm rstest declared as dev-dependency in Cargo.toml

Verified rstest = "0.18" under [dev-dependencies] in the root Cargo.toml. No changes required.

Comment thread src/wrap.rs
Comment thread src/wrap/tests.rs
@leynos leynos merged commit 3370231 into main Aug 19, 2025
2 checks passed
@leynos leynos deleted the codex/fix-final-flush-to-preserve-trailing-spaces branch August 19, 2025 22:43
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.

Inconsistent trailing space handling in wrap_preserving_code function

1 participant