Skip to content

Commit

Permalink
Fix build error when using Ruby 2.8.0-dev
Browse files Browse the repository at this point in the history
This PR fixes the following build error when using Ruby 2.8.0-dev.

```console
% ruby -v
ruby 2.8.0dev (2020-07-14T04:19:55Z master e60cd14d85) [x86_64-darwin17]

% bundle exec rspec ./spec/rubocop/cop/lint/redundant_cop_disable_directive_spec.rb:47
Run options: include {:focus=>true,
:locations=>{"./spec/rubocop/cop/lint/redundant_cop_disable_directive_spec.rb"=>[47]}}

Randomized with seed 2998
F

Failures:

  1) RuboCop::Cop::Lint::RedundantCopDisableDirective.check when there
  are disabled lines and there are no offenses and a comment disables
  itself and another cop disabled on the same range returns no offense
       Failure/Error: range.cover?(line_range.min) && range.cover?(line_range.max)

  FloatDomainError:
    Infinity
  # ./lib/rubocop/cop/lint/redundant_cop_disable_directive.rb:164:in `floor'
  # ./lib/rubocop/cop/lint/redundant_cop_disable_directive.rb:164:in `max'
  # ./lib/rubocop/cop/lint/redundant_cop_disable_directive.rb:164:in
 `block in ignore_offense?'
  # ./lib/rubocop/cop/lint/redundant_cop_disable_directive.rb:163:in `any?'
  # ./lib/rubocop/cop/lint/redundant_cop_disable_directive.rb:163:in `ignore_offense?'
  # ./lib/rubocop/cop/lint/redundant_cop_disable_directive.rb:110:in
 `block in each_line_range'
```

The above error is due to the following Ruby 2.8.0-dev's changeset.
ruby/ruby@8900a25

## Ruby 2.7.1

```
% ruby -ve 'p (42..Float::INFINITY).max'
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin17]
Infinity
```

## Ruby 2.8.0-dev

```console
% ruby -ve '(42..Float::INFINITY).max'
ruby 2.8.0dev (2020-07-14T04:19:55Z master e60cd14d85) [x86_64-darwin17]
-e:1:in `floor': Infinity (FloatDomainError)
        from -e:1:in `max'
        from -e:1:in `<main>'
```

I asked the following address and it's an expected behaviour.
https://bugs.ruby-lang.org/issues/17017

Perhaps there is still a possibility that the behavior will change
while Ruby 2.8 (3.0) is being developed.
First of all, this PR is updating according to the current expectation.
  • Loading branch information
koic authored and bbatsov committed Jul 15, 2020
1 parent 0adf3cd commit ee123f4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rubocop/comment_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def analyze_rest(analysis, line)
def cop_line_ranges(analysis)
return analysis.line_ranges unless analysis.start_line_number

analysis.line_ranges + [(analysis.start_line_number..Float::INFINITY)]
analysis.line_ranges + [(analysis.start_line_number.to_f..Float::INFINITY)]
end

def each_mentioned_cop
Expand Down

0 comments on commit ee123f4

Please sign in to comment.