Skip to content

Reconsider enabling Style/RedundantStructKeywordInit by default #814

Description

@tttffff

I’d like to suggest disabling Style/RedundantStructKeywordInit in Standard’s default config.

It was introduced here #812

RuboCop keeps this cop disabled by default because keyword_init: true is not purely redundant.
Explained here https://docs.rubocop.org/rubocop/latest/cops_style.html#styleredundantstructkeywordinit

My personal concern is that keyword_init: true is a useful public-interface signal:

Result = Struct.new(:eligible, :reason, keyword_init: true)

Makes the intended usage clear:

Result.new(eligible: true, reason: nil)

And tells the caller not to use:

Result.new(true, nil) # As this will now not be allowed.

So while removing keyword_init: true shortens the code, it also removes intent and weakens the constructor contract.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions