[Rails] How to avoid "Use hash rockets syntax" when executing Rubocop

A lot of "Use hash rockets syntax" appears

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" **.

Pointed out when running Rubocop

$ 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

[Rails] How to avoid "Use hash rockets syntax" when executing Rubocop
[Rails] How to use enum
[Rails] How to use enum
How to use rails join
[Rails] How to use validation
[Rails] How to use authenticate_user!
[Rails] How to use "kaminari"
[Rails] How to use Scope
How to use Gem included when developing Rails API server (rack-cors, rspec-rails, factory_bot_rails, rubocop)
[Rails] How to use gem "devise"
[Rails] How to use flash messages
How to use Ruby on Rails
[Rails] How to use Active Storage
[Introduction to Rails] How to use render
How to use custom helpers in rails
[Ruby on Rails] How to use CarrierWave
[Rails] How to use rails console with docker
[Rails] How to use ActiveRecord :: Bitemporal (BiTemporalDataModel)
[Rails] How to use the map method
How to use MySQL in Rails tutorial
How to resolve errors when installing Rails 5.1.3
[Ruby on Rails] How to use redirect_to
[Note] How to use Rails 6 Devise + cancancan
[Ruby on Rails] How to use kaminari
[Rails] How to use video_tag to display videos
[Rails] How to use helper method, confimartion
How to use credentials.yml.enc introduced in Rails 5.2
[Rails] How to pass validation such as password when executing update action
[Rails] How to write when making a subquery
[Rails] How to use select boxes in Ransack
How to use rails g scaffold, functions, precautions
How to use JQuery in js.erb of Rails6
[Rails] How to use Gem'rails-i18n' for Japanese support
[Ruby on Rails] How to use session method
[Rails] How to use PostgreSQL in Vagrant environment
[rails] How to use devise helper method before_action: authenticate_user!
How to write Rails
How to use rbenv
How to use letter_opener_web
How to use with_option
How to use java.util.logging
How to use map
[Rails] I don't know how to use the model ...
How to use Twitter4J
How to use active_hash! !!
How to use hidden_field_tag
How to uninstall Rails
[How to use label]
How to use identity
How to use hashes
What to do when Address already in use is displayed after executing rails s
How to use JUnit 5
How to use Dozer.mapper
How to use Gradle
How to use org.immutables
How to use java.util.stream.Collector
How to use VisualVM
How to use Map
How to automatically generate ER diagram when migrating with Rails6
How to set environment variables when using Payjp with Rails
How to specify db when creating an app with rails