[Bug Fix] Fix gem linter: remove redundant keyword_init: true#426
Conversation
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>
There was a problem hiding this comment.
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
| Invoice = Struct.new(:identifier, :status, :method, :amount) | ||
| User = Struct.new(:avatar_url, :name, :username, :commits, :github_url) |
There was a problem hiding this comment.
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>
| 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>
|
Thanks — good catch by cubic. The finding is technically correct: I evaluated the practical impact for these specific Structs and decided to keep the removal:
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. |
Description
The gem linter (
rake standard) is currently failing onmain, independent of any feature work. Standard now flagsStyle/RedundantStructKeywordInit: on Ruby 3.2+ aStructaccepts both positional and keyword arguments, sokeyword_init: trueis redundant.Four offenses across three docs Structs:
lib/ruby_ui/data_table/data_table_docs.rb:4lib/ruby_ui/table/table_docs.rb:4and:5lib/ruby_ui/tabs/tabs_docs.rb:4This 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 --fixleaves it alone — hence the manual edit.How to test
🤖 Generated with Claude Code
Summary by cubic
Fixes failing linters in both the gem and the docs app by removing redundant
keyword_init: truefrom sampleStructs. Ruby 3.2+ accepts keyword args without it, so behavior is unchanged and both linters pass.keyword_init: truefromRow,Invoice,User, andRepoacross gem*_docs.rband docs app components/views.Written for commit d71f26a. Summary will update on new commits.