Skip to content

Ban redundant then keyword via RuboCop - #1791

Open
st0012 wants to merge 1 commit into
masterfrom
claude/redundant-then-cop-8nf9q1
Open

Ban redundant then keyword via RuboCop#1791
st0012 wants to merge 1 commit into
masterfrom
claude/redundant-then-cop-8nf9q1

Conversation

@st0012

@st0012 st0012 commented Aug 28, 2026

Copy link
Copy Markdown
Member

This has bothered me for quite a while. I was thinking about dropping them gradually, but with agents reading other code they constantly add then too. So let's ban this.

Cops enabled

.rubocop.yml uses DisabledByDefault: true, so each cop is opted in explicitly:

  • Style/MultilineIfThenif cond then with the body on the next line
  • Style/MultilineWhenThen — same for when
  • Style/MultilineInPatternThen — same for in pattern matching

There is no single "redundant then" cop; these three are RuboCop's coverage for it.

They intentionally leave single-line forms alone, where then is required and not redundant:

when Hash then (name[:rdoc] || "rdoc").to_s

Enable Style/MultilineIfThen, Style/MultilineWhenThen and
Style/MultilineInPatternThen, and remove the existing redundant `then`
keywords across the codebase (autocorrected, plus two spots the cops
don't reach: a multiline `when` condition list in the ri servlet and a
code sample in a doc comment).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G11TTmQg9oQXAwJ79A5gsm
@matzbot

matzbot commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

🚀 Preview deployment available at: https://259c1d9f.rdoc-6cd.pages.dev (commit: 88c8b73)

@st0012
st0012 marked this pull request as ready for review August 28, 2026 00:30
Copilot AI balanced review requested due to automatic review settings August 28, 2026 00:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Bans redundant multiline then keywords through RuboCop and updates existing Ruby code accordingly without changing behavior.

Changes:

  • Enables three multiline then style cops.
  • Removes existing violations across source and test files.
  • Preserves required single-line then forms.

Reviewed changes

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

Show a summary per file
File Description
.rubocop.yml Enables multiline then cops.
exe/rdoc Removes redundant then.
lib/rdoc/code_object.rb Removes redundant then.
lib/rdoc/code_object/any_method.rb Removes redundant then.
lib/rdoc/code_object/attr.rb Removes redundant then.
lib/rdoc/code_object/class_module.rb Removes redundant then.
lib/rdoc/code_object/constant.rb Removes redundant then.
lib/rdoc/code_object/context.rb Removes redundant then.
lib/rdoc/code_object/method_attr.rb Removes redundant then.
lib/rdoc/code_object/require.rb Removes redundant then.
lib/rdoc/cross_reference.rb Removes redundant then.
lib/rdoc/encoding.rb Removes redundant then.
lib/rdoc/generator/darkfish.rb Removes redundant then.
lib/rdoc/generator/markup.rb Removes redundant then.
lib/rdoc/markup.rb Removes redundant then.
lib/rdoc/markup/document.rb Removes redundant then.
lib/rdoc/markup/formatter.rb Removes redundant then.
lib/rdoc/markup/indented_paragraph.rb Removes redundant then.
lib/rdoc/markup/paragraph.rb Removes redundant then.
lib/rdoc/markup/parser.rb Removes redundant then.
lib/rdoc/markup/pre_process.rb Removes redundant then.
lib/rdoc/markup/to_ansi.rb Removes redundant then.
lib/rdoc/markup/to_bs.rb Removes redundant then.
lib/rdoc/markup/to_html.rb Removes redundant then.
lib/rdoc/markup/to_html_crossref.rb Removes redundant then.
lib/rdoc/markup/to_html_snippet.rb Removes redundant then.
lib/rdoc/markup/to_markdown.rb Removes redundant then.
lib/rdoc/markup/to_rdoc.rb Removes redundant then.
lib/rdoc/markup/to_test.rb Removes redundant then.
lib/rdoc/markup/to_tt_only.rb Removes redundant then.
lib/rdoc/markup/verbatim.rb Removes redundant then.
lib/rdoc/options.rb Removes redundant then.
lib/rdoc/parser.rb Removes redundant then.
lib/rdoc/parser/c.rb Removes redundant then.
lib/rdoc/parser/changelog.rb Removes redundant then.
lib/rdoc/parser/ruby.rb Removes redundant then.
lib/rdoc/rd.rb Removes redundant then.
lib/rdoc/rd/inline.rb Removes redundant then.
lib/rdoc/rdoc.rb Removes redundant then.
lib/rdoc/ri/driver.rb Removes redundant then.
lib/rdoc/ri/paths.rb Removes redundant then.
lib/rdoc/ri/servlet.rb Removes redundant then.
lib/rdoc/rubygems_hook.rb Removes redundant then.
lib/rdoc/stats.rb Removes redundant then.
lib/rdoc/stats/normal.rb Removes redundant then.
lib/rdoc/store.rb Removes redundant then.
lib/rdoc/task.rb Removes redundant then.
lib/rdoc/token_stream.rb Removes redundant then.
lib/rdoc/tom_doc.rb Removes redundant then.
test/rdoc/code_object/class_module_test.rb Updates test code to comply.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

4 participants