Skip to content

Style/IfUnlessModifier vs hashes with omitted values #13725

Closed
@zverok

Description

@zverok

The minimal reproducing code:

if true
  data[:foo] = {x:}
end

Run Rubocop with

rubocop test.rb --only Style/IfUnlessModifier -A

Expected behavior

The code is changed to:

data[:foo] = {x:} if true

Actual behavior

The code is changed to:

data[:foo](:foo, {x:}) if true

Doesn’t reproduce if without value-omission hashes (e.g., {x: 1})

RuboCop version

$ rubocop -V
1.70.0 (using Parser 3.3.7.0, rubocop-ast 1.37.0, analyzing as Ruby 3.1, running on ruby 3.2.2) [x86_64-linux]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions