Skip to content

Enable RuboCop EnforcedShorthandSyntax: always and autocorrect the codebase #2833

Description

@mroderick

Description of the issue 📄

Our RuboCop config enables Style/HashSyntax but leaves EnforcedShorthandSyntax at the default either, which accepts both styles. During review of #2832 this came up: when a hash keyword matches a same-named local variable or method, the idiomatic modern Ruby (3.1+) form is shorthand — write member: instead of member: member.

# shorthand: key name matches the variable/method name
described_class.with(member:).chaser.deliver_now
Fabricate(:subscription, member:, group: students_group)

# longhand stays: value is an expression or differently-named variable
Fabricate(:member_email_delivery, member:, email_type: action_name)

Enforcing it mechanically means reviewer preferences no longer need to be remembered — the linter carries the rule.

Size: with EnforcedShorthandSyntax: always, the current codebase produces 466 offenses across 367 files — every single one autocorrectable.

Steps to fix 🛠

  1. In .rubocop.yml, set the option on the existing cop:
Style/HashSyntax:
  EnforcedShorthandSyntax: always
  1. Run the sweep — all offenses are marked [Correctable]:
bundle exec rubocop -a
  1. No .rubocop_todo.yml entry is needed: the sweep fixes the whole backlog, so nothing is deferred.

To do 📋

  • Claim this issue (comment below, or assign yourself if you are part of the codebar org)
  • Fork and clone the repository
  • Update the relevant files. Follow the steps to fix section in this issue.
  • Commit your changes as one commit. Use the title of this issue as your commit message
  • Submit a pull request
  • Mention this issue in the PR description by including it's number
  • Have your pull request reviewed & merged by a codebar team member

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions