This seems to be more of surprising behavior with the Ruby parser than Rubocop, but nonetheless it is still creating errors.
# original, valid syntax, pre-Rubocop
prepend_before_filter only: [ :create, :destroy ] { request.env["devise.skip_timeout"] = true }
# invalid (Ruby 2.2.4) syntax created by Rubocop
prepend_before_filter only: %i[create destroy] { request.env["devise.skip_timeout"] = true }
The Ruby error:
app/controllers/users/sessions_controller.rb:4: syntax error, unexpected '{', expecting keyword_end
...tion only: %i[create destroy] { request.env['devise.skip_tim...
... ^
app/controllers/users/sessions_controller.rb:4: syntax error, unexpected '}', expecting keyword_end
When running rubocop -a, it produces valid Ruby syntax.
It creates invalid syntax.
Given a file:
# thing.rb
class Thing
do_anything only: [:word, :two] { 5 }
end
When you run Rubocop with auto-correct rubocop -a thing.rb
It produces an error:
Inspecting 1 file
E
Offenses:
thing.rb:2:21: C: [Corrected] Use %i or %I for an array of symbols.
do_anything only: [:word, :two] { 5 }
^^^^^^^^^^^^^
thing.rb:2:34: E: unexpected token tLCURLY
(Using Ruby 2.1 parser; configure using TargetRubyVersion parameter, under AllCops)
do_anything only: %i[word two] { 5 }
^
1 file inspected, 2 offenses detected, 1 offense corrected
0.48.1 (using Parser 2.4.0.0, running on ruby 2.2.4 x86_64-darwin16)
Interesting. Looks like parser follows MRI and throws a parsing error as well. Good catch!
The above code has same problem...
# not error
foo [:foo, :bar] { something }
# Syntax error
foo %i[foo bar] { something }
Ref:
As a note, I have opened an upstream issue for this in Redmine.
Most helpful comment
As a note, I have opened an upstream issue for this in Redmine.