Skip to content

Add guideline discouraging embedded newlines in puts#977

Open
andyw8 wants to merge 1 commit intorubocop:masterfrom
andyw8:discourage-embedded-newlines-in-puts
Open

Add guideline discouraging embedded newlines in puts#977
andyw8 wants to merge 1 commit intorubocop:masterfrom
andyw8:discourage-embedded-newlines-in-puts

Conversation

@andyw8
Copy link
Contributor

@andyw8 andyw8 commented Feb 16, 2026

Note: PR co-authored with Claude Code

Summary

This PR adds a guideline discouraging the use of embedded newline characters (\n) in puts calls, in favor of using separate puts calls.

Motivation

I've noticed that AI models frequently generate Ruby code using the pattern puts "\nmessage" when adding blank lines to output. I suspect this is due to training bias from Python codebases, where print("\nmessage") is an accepted and common style.

However, in Ruby, the idiomatic approach is to use separate puts calls:

puts
puts 'message'

This is more readable and aligns better with Ruby conventions.

Next Steps

I was intending to add a new RuboCop cop to enforce this guideline, but I wanted to open this PR here first for discussion. If the community agrees this is a worthwhile guideline, I'll proceed with implementing the corresponding cop in RuboCop.

Changes

  • Added a new section "Separate puts for Newlines" in the Misc section
  • Provided clear examples of the discouraged and preferred patterns

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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.

1 participant