Custom Rubocop rules to add

Custom cops to implement

  1. Line breaks after guard clauses

     # bad
     return unless condition
     do_stuff
    
     # good
     return unless condition
    
     do_stuff
  2. Line breaks around conditional blocks

     # bad
     do_something
     if condition
       do_extra_stuff
     end
     do_something_more
    
     # good
     do_something
    
     if condition
       do_extra_stuff
     end
    
     do_something_more

A good example to get started is probably https://github.com/bbatsov/rubocop/blob/master/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb.


Also, as discussed with @DouweM, here is a list of potential custom Rubocop cops we'd want to add in the future:

  1. Arrays should always use [] instead of any other possible syntax. E.g.: ['foo', 'bar'], %w[foo bar], %i[foo bar] instead of %w(foo bar) or %i{foo bar}...

Related to #17478 (closed).

Edited by Rémy Coutable