Rubocop: Rubocop error due to using 2.3 parser but I have `TargetRubyVersion` set.

Created on 17 Mar 2017  Â·  6Comments  Â·  Source: rubocop-hq/rubocop

Rubocop seems to fail with Ruby 2.3 style even though TargetRubyVersion is set.

Expected behavior

No error

Actual behavior

Rubocop failing with Using Ruby 2.3 parser; configure using TargetRubyVersion parameter, under AllCops when using ruby 2.3 style and having correct version set in .rubocop.yml;

AllCops:
  TargetRubyVersion: 2.3

Steps to reproduce the problem

Create a new rails repo, add rubocop and a .rubocop.yml file with the above and add some ruby 2.3 style code i.e. scope :foo, -> { |f| f.bar }

RuboCop version

➜  test_repo rubocop -V
0.47.1 (using Parser 2.4.0.0, running on ruby 2.3.1 x86_64-darwin16)

Most helpful comment

Got same kind of error this morning. It seems to be related to this issue in the parser gem.

Here is the fix for now:

gem 'parser', '2.4.0.2'

All 6 comments

I actually realised this was because my code is incorrect for the lambda. Changing to scope :foo, ->(f) { f.bar } fixes.

I guess the error raised is still wrong but not a big deal.

I have a similar problem with my code:

json.count articles.count

Error:

Lint/Syntax: unexpected token $end
(Using Ruby 2.5 parser; configure using TargetRubyVersion parameter, under AllCops)
json.count articles.count

I've already set 2.5 as the TargetRubyVersion under AllCops.

@AmitJoki I'm not sure your error is actually related to this error. Lint/Syntax: unexpected token $end indicates a syntax error in your file, but the example code posted doesn't give any Rubocop complaints for me and Ruby indicates the syntax is fine:

% ruby -cW3 -e'json.count articles.count'
Syntax OK

If you can provide an example of code that gives a Rubocop error while Ruby thinks the syntax is ok, please open a new issue with the details.

Got same kind of error this morning. It seems to be related to this issue in the parser gem.

Here is the fix for now:

gem 'parser', '2.4.0.2'

@mikegee this error occured in a .jbuilder if that is of any help.

@anthony-robin Installed it, but then the error still occurs, this time without showing the code that caused it.

Now, I get

Lint/Syntax: unexpected token $end
(Using Ruby 2.5 parser; configure using TargetRubyVersion parameter, under AllCops)

I get this same error in 0.54.0 which can't use the previous parser version.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mikegee picture mikegee  Â·  3Comments

bbugh picture bbugh  Â·  3Comments

kirrmann picture kirrmann  Â·  3Comments

benoittgt picture benoittgt  Â·  3Comments

david942j picture david942j  Â·  3Comments