Skip to content

[Bug Fix] Fix gem linter: remove redundant keyword_init: true#426

Merged
cirdes merged 2 commits into
ruby-ui:mainfrom
jacksonpires:fix/lint-redundant-struct-keyword-init
Jun 15, 2026
Merged

[Bug Fix] Fix gem linter: remove redundant keyword_init: true#426
cirdes merged 2 commits into
ruby-ui:mainfrom
jacksonpires:fix/lint-redundant-struct-keyword-init

Conversation

@jacksonpires

@jacksonpires jacksonpires commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Description

The gem linter (rake standard) is currently failing on main, independent of any feature work. Standard now flags Style/RedundantStructKeywordInit: on Ruby 3.2+ a Struct accepts both positional and keyword arguments, so keyword_init: true is redundant.

Four offenses across three docs Structs:

  • lib/ruby_ui/data_table/data_table_docs.rb:4
  • lib/ruby_ui/table/table_docs.rb:4 and :5
  • lib/ruby_ui/tabs/tabs_docs.rb:4

This PR removes the redundant keyword_init: true. The structs are still instantiated with keyword arguments throughout the docs, which keeps working on the gem's supported Ruby (>= 3.2).

The cop's autocorrect is marked unsafe (it would change behavior on Ruby < 3.2), so standardrb --fix leaves it alone — hence the manual edit.

How to test

cd gem
bundle exec rake standard   # 364 files inspected, no offenses detected
bundle exec rake test       # all green

🤖 Generated with Claude Code


Summary by cubic

Fixes failing linters in both the gem and the docs app by removing redundant keyword_init: true from sample Structs. Ruby 3.2+ accepts keyword args without it, so behavior is unchanged and both linters pass.

  • Bug Fixes
    • Removed keyword_init: true from Row, Invoice, User, and Repo across gem *_docs.rb and docs app components/views.
    • Confirmed keyword instantiation on Ruby >= 3.2; gem and docs linters green, gem tests pass.

Written for commit d71f26a. Summary will update on new commits.

Review in cubic

Standard's Style/RedundantStructKeywordInit flags `keyword_init: true`
as redundant on Ruby 3.2+ (where Struct accepts both positional and
keyword args), failing the gem linter on main. Drop it from the three
*_docs.rb sample Structs; keyword instantiation still works on the
supported Ruby (>= 3.2).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jacksonpires jacksonpires requested a review from cirdes as a code owner June 15, 2026 17:03

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="gem/lib/ruby_ui/table/table_docs.rb">

<violation number="1" location="gem/lib/ruby_ui/table/table_docs.rb:4">
P2: Behavioral contract loosened: `keyword_init: true` is not purely redundant on Ruby 3.2+ and still enforces keyword-only initialization by rejecting positional arguments. Removing it allows silent positional call sites, increasing the risk of data mis-mapping if struct member order ever changes.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment on lines +4 to +5
Invoice = Struct.new(:identifier, :status, :method, :amount)
User = Struct.new(:avatar_url, :name, :username, :commits, :github_url)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Behavioral contract loosened: keyword_init: true is not purely redundant on Ruby 3.2+ and still enforces keyword-only initialization by rejecting positional arguments. Removing it allows silent positional call sites, increasing the risk of data mis-mapping if struct member order ever changes.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At gem/lib/ruby_ui/table/table_docs.rb, line 4:

<comment>Behavioral contract loosened: `keyword_init: true` is not purely redundant on Ruby 3.2+ and still enforces keyword-only initialization by rejecting positional arguments. Removing it allows silent positional call sites, increasing the risk of data mis-mapping if struct member order ever changes.</comment>

<file context>
@@ -1,8 +1,8 @@
 class Views::Docs::Table < Views::Base
-  Invoice = Struct.new(:identifier, :status, :method, :amount, keyword_init: true)
-  User = Struct.new(:avatar_url, :name, :username, :commits, :github_url, keyword_init: true)
+  Invoice = Struct.new(:identifier, :status, :method, :amount)
+  User = Struct.new(:avatar_url, :name, :username, :commits, :github_url)
 
</file context>
Suggested change
Invoice = Struct.new(:identifier, :status, :method, :amount)
User = Struct.new(:avatar_url, :name, :username, :commits, :github_url)
# standard:disable Style/RedundantStructKeywordInit
Invoice = Struct.new(:identifier, :status, :method, :amount, keyword_init: true)
User = Struct.new(:avatar_url, :name, :username, :commits, :github_url, keyword_init: true)
# standard:enable Style/RedundantStructKeywordInit

Same Style/RedundantStructKeywordInit drift failing the Docs (Rails)
linter. Drop the redundant `keyword_init: true` from the six sample
Structs in the docs app; keyword instantiation still works on Ruby 3.2+.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jacksonpires

Copy link
Copy Markdown
Contributor Author

Thanks — good catch by cubic. The finding is technically correct: keyword_init: true isn't purely redundant on Ruby 3.2+. It also rejects positional initialization, so dropping it does loosen the contract (the struct starts accepting positional args too). That's exactly why this cop's autocorrect is marked unsafe.

I evaluated the practical impact for these specific Structs and decided to keep the removal:

  • All of them are sample-data Structs living in *_docs.rb files, defined and used only within the same file — not part of any public API.
  • I checked every call site of Row, Invoice, User, and Repo across the gem and docs app: all of them already use keyword arguments. There are no positional callers, so the loosened contract isn't exercised.
  • Removing keyword_init: true is the fix Style/RedundantStructKeywordInit (the cop that's currently failing CI on main) asks for, and the supported Ruby is >= 3.2.

So the behavioral change is theoretical here (it would only bite if someone deliberately added a positional call to a docs example), while the lint fix unblocks CI. Happy to revisit if a maintainer would rather suppress the cop and keep strict keyword-only enforcement instead.

@cirdes cirdes merged commit 857b515 into ruby-ui:main Jun 15, 2026
8 checks passed
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