From 68423f72d1019a87c9b58f04a274687d5ae89136 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Mon, 25 Apr 2022 19:47:41 +0900 Subject: [PATCH] Drop Ruby 2.5 support Follow up https://github.com/rubocop/rubocop/pull/10577. --- .circleci/config.yml | 3 -- .rubocop.yml | 2 +- changelog/change_drop_ruby_2_5_support.md | 1 + .../ignored_skip_action_filter_option.rb | 2 +- lib/rubocop/cop/rails/safe_navigation.rb | 2 +- rubocop-rails.gemspec | 2 +- spec/rubocop/cop/rails/index_by_spec.rb | 26 +++++---------- spec/rubocop/cop/rails/index_with_spec.rb | 32 ++++++------------- 8 files changed, 23 insertions(+), 47 deletions(-) create mode 100644 changelog/change_drop_ruby_2_5_support.md diff --git a/.circleci/config.yml b/.circleci/config.yml index ee76813558..a663940d0f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 diff --git a/.rubocop.yml b/.rubocop.yml index 704da791ea..3792c8d25d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -13,7 +13,7 @@ AllCops: - 'vendor/**/*' - 'spec/fixtures/**/*' - 'tmp/**/*' - TargetRubyVersion: 2.5 + TargetRubyVersion: 2.6 SuggestExtensions: false InternalAffairs/NodeMatcherDirective: diff --git a/changelog/change_drop_ruby_2_5_support.md b/changelog/change_drop_ruby_2_5_support.md new file mode 100644 index 0000000000..d7ed7e5aad --- /dev/null +++ b/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][]) diff --git a/lib/rubocop/cop/rails/ignored_skip_action_filter_option.rb b/lib/rubocop/cop/rails/ignored_skip_action_filter_option.rb index 05432756e7..61946e45f3 100644 --- a/lib/rubocop/cop/rails/ignored_skip_action_filter_option.rb +++ b/lib/rubocop/cop/rails/ignored_skip_action_filter_option.rb @@ -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) diff --git a/lib/rubocop/cop/rails/safe_navigation.rb b/lib/rubocop/cop/rails/safe_navigation.rb index 5ff334bc9c..a8f2f23f59 100644 --- a/lib/rubocop/cop/rails/safe_navigation.rb +++ b/lib/rubocop/cop/rails/safe_navigation.rb @@ -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) diff --git a/rubocop-rails.gemspec b/rubocop-rails.gemspec index 710d67b4b6..225b28d505 100644 --- a/rubocop-rails.gemspec +++ b/rubocop-rails.gemspec @@ -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. diff --git a/spec/rubocop/cop/rails/index_by_spec.rb b/spec/rubocop/cop/rails/index_by_spec.rb index 0ff37f22b4..33a89d1147 100644 --- a/spec/rubocop/cop/rails/index_by_spec.rb +++ b/spec/rubocop/cop/rails/index_by_spec.rb @@ -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 diff --git a/spec/rubocop/cop/rails/index_with_spec.rb b/spec/rubocop/cop/rails/index_with_spec.rb index c269c20e24..6d7dcc888f 100644 --- a/spec/rubocop/cop/rails/index_with_spec.rb +++ b/spec/rubocop/cop/rails/index_with_spec.rb @@ -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 @@ -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