Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support endless range from Ruby 2.6 #7159

Closed
antonzaytsev opened this issue Jun 20, 2019 · 1 comment · Fixed by #7160
Closed

Support endless range from Ruby 2.6 #7159

antonzaytsev opened this issue Jun 20, 2019 · 1 comment · Fixed by #7160
Labels

Comments

@antonzaytsev
Copy link
Contributor

Latest version doesn't have support of added feature endless ranges in Ruby 2.6.


Expected behavior

In case of proper syntax for endless range, Rubocop should pass

Actual behavior

It fails with error

Inspecting 1 file
An error occurred while Lint/DuplicatedKey cop was inspecting /Users/anton/code/rubocop-endless-range-issues/test.rb:3:7.
To see the complete backtrace run rubocop -d.
.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Lint/DuplicatedKey cop was inspecting /Users/anton/code/rubocop-endless-range-issues/test.rb:3:7.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop-hq/rubocop/issues

Mention the following information in the issue report:
0.71.0 (using Parser 2.6.3.0, running on ruby 2.6.1 x86_64-darwin18)

Steps to reproduce the problem

I created repo with 2 test files (ruby files and rubocop config).
https://github.com/antonzaytsev/rubocop-endless-range-issue.
Literally any code with endless range will break rubocop.
For example

hash = {
  1...20 => true,
  20... => false
}

RuboCop version

$ [bundle exec] rubocop -V
0.71.0 (using Parser 2.6.3.0, running on ruby 2.6.1 x86_64-darwin18)
@koic
Copy link
Member

koic commented Jun 21, 2019

Thanks for the feedback. I opened a PR #7160.

koic added a commit to koic/rubocop that referenced this issue Jun 21, 2019
Fixes rubocop#7159.

This PR fixes the following error for `Lint/DuplicatedKey` when
using endless range in Ruby 2.6.

```console
% rubocop -V
0.71.0 (using Parser 2.6.3.0, running on ruby 2.6.3 x86_64-darwin17)
% cat example.rb
{
  42.. => false
}
% rubocop --only Lint/DuplicatedKey -d
For /private/tmp/7159: configuration from
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/config/default.yml
Inspecting 1 file
Scanning /private/tmp/7159/example.rb
An error occurred while Lint/DuplicatedKey cop was inspecting
/private/tmp/7159/example.rb:1:0.
undefined method `recursive_basic_literal?' for nil:NilClass
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/lib/rubocop/ast/node.rb:408:in
`all?'
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/lib/rubocop/ast/node.rb:408:in
`block (2 levels) in <class:Node>'
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/lib/rubocop/cop/lint/duplicated_key.rb:27:in
`select'
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/lib/rubocop/cop/lint/duplicated_key.rb:27:in
`on_hash'
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/lib/rubocop/cop/commissioner.rb:59:in
`block (2 levels) in trigger_re
sponding_cops'

(snip)
```

There are the following differences in the AST generated by
Parser gem.

```console
% ruby-parse -e '(42..nil)'
(begin
  (irange
    (int 42)
    (nil)))

% ruby-parse -e '(42..)'
(begin
  (irange
    (int 42) nil))
```

This PR works with `nil` representing the endless range.
bbatsov pushed a commit that referenced this issue Jun 21, 2019
Fixes #7159.

This PR fixes the following error for `Lint/DuplicatedKey` when
using endless range in Ruby 2.6.

```console
% rubocop -V
0.71.0 (using Parser 2.6.3.0, running on ruby 2.6.3 x86_64-darwin17)
% cat example.rb
{
  42.. => false
}
% rubocop --only Lint/DuplicatedKey -d
For /private/tmp/7159: configuration from
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/config/default.yml
Inspecting 1 file
Scanning /private/tmp/7159/example.rb
An error occurred while Lint/DuplicatedKey cop was inspecting
/private/tmp/7159/example.rb:1:0.
undefined method `recursive_basic_literal?' for nil:NilClass
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/lib/rubocop/ast/node.rb:408:in
`all?'
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/lib/rubocop/ast/node.rb:408:in
`block (2 levels) in <class:Node>'
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/lib/rubocop/cop/lint/duplicated_key.rb:27:in
`select'
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/lib/rubocop/cop/lint/duplicated_key.rb:27:in
`on_hash'
/Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.71.0/lib/rubocop/cop/commissioner.rb:59:in
`block (2 levels) in trigger_re
sponding_cops'

(snip)
```

There are the following differences in the AST generated by
Parser gem.

```console
% ruby-parse -e '(42..nil)'
(begin
  (irange
    (int 42)
    (nil)))

% ruby-parse -e '(42..)'
(begin
  (irange
    (int 42) nil))
```

This PR works with `nil` representing the endless range.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants