Skip to content

Commit

Permalink
Merge pull request #697 from koic/drop_ruby_2_5_support
Browse files Browse the repository at this point in the history
Drop Ruby 2.5 support
  • Loading branch information
koic committed Apr 26, 2022
2 parents 6382db9 + 68423f7 commit b812c1f
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 47 deletions.
3 changes: 0 additions & 3 deletions .circleci/config.yml
Expand Up @@ -35,9 +35,6 @@ workflows:
build:
jobs:
- documentation-checks
- rake_default:
name: Ruby 2.5
image: cimg/ruby:2.5
- rake_default:
name: Ruby 2.6
image: cimg/ruby:2.6
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Expand Up @@ -13,7 +13,7 @@ AllCops:
- 'vendor/**/*'
- 'spec/fixtures/**/*'
- 'tmp/**/*'
TargetRubyVersion: 2.5
TargetRubyVersion: 2.6
SuggestExtensions: false

InternalAffairs/NodeMatcherDirective:
Expand Down
1 change: 1 addition & 0 deletions changelog/change_drop_ruby_2_5_support.md
@@ -0,0 +1 @@
* [#697](https://github.com/rubocop/rubocop-rails/pull/697): **(Breaking)** Drop Ruby 2.5 support. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/ignored_skip_action_filter_option.rb
Expand Up @@ -80,7 +80,7 @@ def on_send(node)
def options_hash(options)
options.pairs
.select { |pair| pair.key.sym_type? }
.map { |pair| [pair.key.value, pair] }.to_h
.to_h { |pair| [pair.key.value, pair] }
end

def if_and_only?(options)
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/safe_navigation.rb
Expand Up @@ -66,7 +66,7 @@ def on_send(node)

def autocorrect(corrector, node)
method_node, *params = *node.arguments
method = method_node.source[1..-1]
method = method_node.source[1..]

range = if node.receiver
range_between(node.loc.dot.begin_pos, node.loc.expression.end_pos)
Expand Down
2 changes: 1 addition & 1 deletion rubocop-rails.gemspec
Expand Up @@ -8,7 +8,7 @@ Gem::Specification.new do |s|
s.name = 'rubocop-rails'
s.version = RuboCop::Rails::Version::STRING
s.platform = Gem::Platform::RUBY
s.required_ruby_version = '>= 2.5.0'
s.required_ruby_version = '>= 2.6.0'
s.authors = ['Bozhidar Batsov', 'Jonas Arvidsson', 'Yuji Nakayama']
s.description = <<~DESCRIPTION
Automatic Rails code style checking tool.
Expand Down
26 changes: 8 additions & 18 deletions spec/rubocop/cop/rails/index_by_spec.rb
Expand Up @@ -145,24 +145,14 @@
RUBY
end

context 'when using Ruby 2.6 or newer', :ruby26 do
it 'registers an offense for `to_h { ... }`' do
expect_offense(<<~RUBY)
x.to_h { |el| [el.to_sym, el] }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `index_by` over `to_h { ... }`.
RUBY

expect_correction(<<~RUBY)
x.index_by { |el| el.to_sym }
RUBY
end
end
it 'registers an offense for `to_h { ... }`' do
expect_offense(<<~RUBY)
x.to_h { |el| [el.to_sym, el] }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `index_by` over `to_h { ... }`.
RUBY

context 'when using Ruby 2.5 or older', :ruby25 do
it 'does not register an offense for `to_h { ... }`' do
expect_no_offenses(<<~RUBY)
x.to_h { |el| [el.to_sym, el] }
RUBY
end
expect_correction(<<~RUBY)
x.index_by { |el| el.to_sym }
RUBY
end
end
32 changes: 10 additions & 22 deletions spec/rubocop/cop/rails/index_with_spec.rb
Expand Up @@ -118,25 +118,15 @@
RUBY
end

context 'when using Ruby 2.6 or newer', :ruby26 do
it 'registers an offense for `to_h { ... }`' do
expect_offense(<<~RUBY)
x.to_h { |el| [el, el.to_sym] }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `index_with` over `to_h { ... }`.
RUBY

expect_correction(<<~RUBY)
x.index_with { |el| el.to_sym }
RUBY
end
end
it 'registers an offense for `to_h { ... }`' do
expect_offense(<<~RUBY)
x.to_h { |el| [el, el.to_sym] }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `index_with` over `to_h { ... }`.
RUBY

context 'when using Ruby 2.5 or older', :ruby25 do
it 'does not register an offense for `to_h { ... }`' do
expect_no_offenses(<<~RUBY)
x.to_h { |el| [el, el.to_sym] }
RUBY
end
expect_correction(<<~RUBY)
x.index_with { |el| el.to_sym }
RUBY
end
end

Expand All @@ -145,10 +135,8 @@
expect_no_offenses('x.each_with_object({}) { |el, h| h[el] = foo(el) }')
end

context 'when using Ruby 2.6 or newer', :ruby26 do
it 'does not register an offense for `to_h { ... }`' do
expect_no_offenses('x.to_h { |el| [el, el.to_sym] }')
end
it 'does not register an offense for `to_h { ... }`' do
expect_no_offenses('x.to_h { |el| [el, el.to_sym] }')
end

it 'does not register an offense for `map { ... }.to_h`' do
Expand Down

0 comments on commit b812c1f

Please sign in to comment.