If you install Rubocop and execute "rubocop" in the terminal, it will be as follows ** "Use hash rockets syntax" ** has come up in large numbers.
Even if I googled, there weren't many articles, but "Hash rockets syntax" is as written in the following article Summary of Ruby hash notation
user = { :first_name => "Yusuke", :last_name => "Higaki" }
⇒ This is a hash in the form of ** "key => value" **.
$ rubocop
Inspecting 87 files
....CCCCC.CC....CC.CC..........C.CC.CCCCCC.C...C..CC......C.....C.C.........CCCCC.CCCCC
Offenses:
app/controllers/communities_controller.rb:3:40: C: Style/HashSyntax: Use hash rockets syntax.
before_action :validate_community, only: %i[edit update destroy]
^^^^^
app/controllers/communities_controller.rb:15:39: C: Style/HashSyntax: Use hash rockets syntax.
@belongings = Belonging.where(community_id: @community.id)
^^^^^^^^^^^^^
app/controllers/communities_controller.rb:21:31: C: Style/HashSyntax: Use hash rockets syntax.
@posts = @posts.where(community_id: @community.id)
^^^^^^^^^^^^^
app/controllers/communities_controller.rb:24:44: C: Style/HashSyntax: Use hash rockets syntax.
@belonging = Belonging.find_by(community_id: @community.id, user_id: current_user.id)
(Omitted below)
In conclusion, when I added the following to .rubocop.yml
, this type of indication disappeared.
ruby:.rubocop.yml
HashSyntax:
EnforcedStyle: ruby19
⇒ This means that ** "Hash notation uses ruby 1.9 hash notation instead of rocket notation" **.
** What is "ruby 1.9 hash notation" **? As described in the part pointed out when executing rubocop this time, It is a format that describes the hash in the form of ** "key: value" ** without using rocket notation.
There may be a more radical solution that hasn't been pointed out in the ruby 1.9 hash notation in the first place. If you know this, I would appreciate it if you could teach me.
Recommended Posts