Preserve trailing spaces on final wrap flush#193
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRefactor 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 functionclassDiagram
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.
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Note Other AI code review bot(s) detectedCodeRabbit 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 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. 📒 Files selected for processing (4)
Summary by CodeRabbit
WalkthroughModify 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Assessment against linked issues
Possibly related issues
Poem
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
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.
📒 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
returnin single-line functions.Move conditionals with >2 branches into a predicate function.
Avoid
unsafeunless 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
rstestfixtures for shared setup and to avoid repetition between tests.Replace duplicated tests with
#[rstest(...)]parameterised cases.Prefer
mockallfor 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.rssrc/wrap/tests.rs
🔇 Additional comments (2)
src/wrap.rs (1)
163-165: Preserve trailing spaces on final flush — correct and minimal fixStop 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.tomlVerified
rstest = "0.18"under[dev-dependencies]in the root Cargo.toml. No changes required.
Summary
wrap_preserving_codeTesting
make fmtmake lintmake testcloses #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:
Tests: