[RAILS] Elimination of Style/BraceletsAroundHashParameters

Overview

I was addicted to RuboCop's Style/Bracelets AroundHash Parameters, so make a note.

Contents

I got a warning when I wrote the following.

config.add_notifier :slack, {
  webhook_url: 'url',
  channel: '#Error notification'
}

The cause is that there is an extra {...}, but the warning did not disappear even if I simply deleted the parentheses.

Solutions

From the conclusion, if you write as follows, the warning disappears.

config.add_notifier :slack, webhook_url: 'url', channel: '#Error notification'

This is because in the Ruby grammar, {...} can be omitted if the last argument is a hash. I simply erased it and it didn't work because I was warned to write it in one line. See Resources for details.

that's all

References

Ruby grammar for Rails beginners to stumble RuboCop | Style/BracesAroundHashParameters EnforcedStyle

Recommended Posts

Elimination of Style/BraceletsAroundHashParameters
12 of Array