Skip to content

Commit

Permalink
Revert "Workaround for Style/RedundantBegin when using JRuby 9.2"
Browse files Browse the repository at this point in the history
## Summary

Revert 1533ece

Current RuboCop (1.52) requires Ruby 2.7+ and JRuby 9.4+.
So JRuby 9.2 has been dropped from runtime version.

## Additional Information

jruby/jruby#6642 has been resolved in JRuby 9.4:

```ruby
# example.rb
require 'ripper'

class RipperParser < Ripper
  def on_parse_error(message)
    raise message
  end
end

RipperParser.new(<<~RUBY).parse
  foo do
    bar do
  end
rescue NameError
  converted << nil
end
RUBY
```

```console
$ ruby -v
jruby 9.4.2.0 (3.1.0) 2023-03-08 90d2913fda Java HotSpot(TM) 64-Bit Server VM 25.271-b09 on 1.8.0_271-b09 +jit [x86_64-darwin]
$ ruby example.rb # No errors
```
  • Loading branch information
koic authored and bbatsov committed Jun 4, 2023
1 parent 1181d4e commit 0bbe96c
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions lib/rubocop/cop/lint/shadowed_exception.rb
Expand Up @@ -121,18 +121,12 @@ def evaluate_exceptions(group)

if rescued_exceptions.any?
rescued_exceptions.each_with_object([]) do |exception, converted|
# FIXME: Workaround `rubocop:disable` comment for JRuby.
# https://github.com/jruby/jruby/issues/6642
# rubocop:disable Style/RedundantBegin
begin
RuboCop::Util.silence_warnings do
# Avoid printing deprecation warnings about constants
converted << Kernel.const_get(exception.source)
end
rescue NameError
converted << nil
RuboCop::Util.silence_warnings do
# Avoid printing deprecation warnings about constants
converted << Kernel.const_get(exception.source)
end
# rubocop:enable Style/RedundantBegin
rescue NameError
converted << nil
end
else
# treat an empty `rescue` as `rescue StandardError`
Expand Down

0 comments on commit 0bbe96c

Please sign in to comment.