Search code examples
rubyrubocop

Redundant curly braces around a hash parameter for Rubocop in rails


After doing bundle exec rubocop -p for this perticular line I am getting offense.

 post = current_timeline.posts.build(post_params.merge({ avatars: params[:avatars] }))

The offense is: Style/BracesAroundHashParameters: Redundant curly braces around a hash parameter.

How to fix it? I am new to rubocop in ruby.


Solution

  • You can simply remove redundant curly braces:

    post = current_timeline.posts.build(post_params.merge(avatars: params[:avatars]))
    

    They are not needed for the last argument passed into a method being Hash literal.