rubyrubocoprakefile

What is the supported hash syntax for the default task in a Rakefile with Ruby v >= 1.9?


In this Rakefile I want to set my default task to :test.

task :default => :test

Rubocop has now entered the scene and states

Style/HashSyntax: Use the new Ruby 1.9 hash syntax.

Great. I don't have much Ruby background, but I do know that the general hash syntax is meant to assign values and make it easy to get them later.

I honestly have no idea how to communicate this, where you have some task and there is a 'magic' default instance and I want to assign :test

I have tried a few permutations but none seem to work. I obviously don't come from the same planet.


Solution

  • Rubocop is suggesting this:

    task default: :test
    

    It may look a bit strange at first but you get used to it.

    Rubocop also needs to remember that Ruby 1.9 shipped twelve years ago in 2007. It's not "new". Support for it was cut in 2015. Shows how long Rubocop has been fighting to make Ruby code better.