From 3e2fe470a506d349ea288abae5882c0a0283e818 Mon Sep 17 00:00:00 2001 From: MarttiCheng Date: Mon, 13 Apr 2020 21:15:45 +0900 Subject: [PATCH] Drop support for Ruby 2.3 Follow rubocop-hq/rubocop#7869. --- .circleci/config.yml | 3 - .rubocop.yml | 2 +- CHANGELOG.md | 4 + .../cop/performance/unfreeze_string.rb | 4 - rubocop-performance.gemspec | 2 +- .../cop/performance/regexp_match_spec.rb | 228 ++++++++---------- .../cop/performance/unfreeze_string_spec.rb | 122 +++++----- 7 files changed, 169 insertions(+), 196 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1d93974..2a870ba 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -23,9 +23,6 @@ jobs: workflows: build: jobs: - - rake_default: - name: Ruby 2.3 - image: circleci/ruby:2.3 - rake_default: name: Ruby 2.4 image: circleci/ruby:2.4 diff --git a/.rubocop.yml b/.rubocop.yml index 2eefe9d..fff6650 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -11,7 +11,7 @@ AllCops: - 'vendor/**/*' - 'spec/fixtures/**/*' - 'tmp/**/*' - TargetRubyVersion: 2.3 + TargetRubyVersion: 2.4 Naming/PredicateName: # Method define macros for dynamically generated method. diff --git a/CHANGELOG.md b/CHANGELOG.md index ba79953..1df88ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,10 @@ * [#82](https://github.com/rubocop-hq/rubocop-performance/pull/82): Let `Performance/StartWith` and `Performance/EndWith` correct `Regexp#match?` and `Regexp#=~`. ([@eugeneius][]) +### Changes + +* [#103](https://github.com/rubocop-hq/rubocop-performance/pull/103): **(BREAKING)** Drop support for Ruby 2.3. ([@koic][]) + ## 1.5.0 (2019-10-01) ### Bug fixes diff --git a/lib/rubocop/cop/performance/unfreeze_string.rb b/lib/rubocop/cop/performance/unfreeze_string.rb index 1521a24..eb52b1f 100644 --- a/lib/rubocop/cop/performance/unfreeze_string.rb +++ b/lib/rubocop/cop/performance/unfreeze_string.rb @@ -24,10 +24,6 @@ module Performance # +'something' # +'' class UnfreezeString < Cop - extend TargetRubyVersion - - minimum_target_ruby_version 2.3 - MSG = 'Use unary plus to get an unfrozen string literal.' def_node_matcher :dup_string?, <<~PATTERN diff --git a/rubocop-performance.gemspec b/rubocop-performance.gemspec index 2ce142f..37c553d 100644 --- a/rubocop-performance.gemspec +++ b/rubocop-performance.gemspec @@ -7,7 +7,7 @@ Gem::Specification.new do |s| s.name = 'rubocop-performance' s.version = RuboCop::Performance::Version::STRING s.platform = Gem::Platform::RUBY - s.required_ruby_version = '>= 2.3.0' + s.required_ruby_version = '>= 2.4.0' s.authors = ['Bozhidar Batsov', 'Jonas Arvidsson', 'Yuji Nakayama'] s.description = <<~DESCRIPTION A collection of RuboCop cops to check for performance optimizations diff --git a/spec/rubocop/cop/performance/regexp_match_spec.rb b/spec/rubocop/cop/performance/regexp_match_spec.rb index dade1cf..89cf771 100644 --- a/spec/rubocop/cop/performance/regexp_match_spec.rb +++ b/spec/rubocop/cop/performance/regexp_match_spec.rb @@ -312,137 +312,115 @@ def foo end end - context 'target ruby version < 2.4', :ruby23 do - it 'accepts match method call in if condition' do - expect_no_offenses(<<~RUBY) - if foo.match(/re/) - do_something - end - RUBY - end - - it 'accepts match method call in elsif condition' do - expect_no_offenses(<<~RUBY) - if cond - do_something - elsif foo.match(/re/) - do_something2 - end - RUBY - end + it_behaves_like('all legacy match methods', 'String#match method call', + '"foo".match(re)', '"foo".match?(re)') + it_behaves_like('all legacy match methods', + 'String#match method call with position', + '"foo".match(re, 1)', '"foo".match?(re, 1)') + it_behaves_like('all legacy match methods', 'Regexp#match method call', + '/re/.match(foo)', '/re/.match?(foo)') + it_behaves_like('all legacy match methods', + 'Regexp#match method call with position', + '/re/.match(foo, 1)', '/re/.match?(foo, 1)') + it_behaves_like('all legacy match methods', 'Symbol#match method call', + ':foo.match(re)', ':foo.match?(re)') + it_behaves_like('all legacy match methods', + 'Symbol#match method call with position', + ':foo.match(re, 1)', ':foo.match?(re, 1)') + it_behaves_like('all legacy match methods', + 'match method call for a variable', + 'foo.match(/re/)', 'foo.match?(/re/)') + it_behaves_like('all legacy match methods', + 'match method call for a variable with position', + 'foo.match(/re/, 1)', 'foo.match?(/re/, 1)') + it_behaves_like('all legacy match methods', 'matching by =~`', + '/re/ =~ foo', '/re/.match?(foo)') + it_behaves_like('all legacy match methods', 'matching by =~`', + 'foo =~ /re/', '/re/.match?(foo)') + it_behaves_like('all legacy match methods', 'matching by =~`', + '"foo" =~ re', '"foo".match?(re)') + it_behaves_like('all legacy match methods', 'matching by =~`', + 're =~ "foo"', '"foo".match?(re)') + it_behaves_like('all legacy match methods', 'matching by =~`', + ':foo =~ re', ':foo.match?(re)') + it_behaves_like('all legacy match methods', 'matching by =~`', + 're =~ :foo', ':foo.match?(re)') + it_behaves_like('all legacy match methods', 'matching by =~`', + 're =~ foo', 're&.match?(foo)') + it_behaves_like('all legacy match methods', 'matching by =~`', + 're =~ FOO', 'FOO.match?(re)') + it_behaves_like('all legacy match methods', 'matching by =~`', + 'FOO =~ re', 'FOO.match?(re)') + it_behaves_like('all legacy match methods', 'matching by !~`', + '/re/ !~ foo', '!/re/.match?(foo)') + it_behaves_like('all legacy match methods', 'matching by !~`', + 'foo !~ /re/', '!/re/.match?(foo)') + it_behaves_like('all legacy match methods', 'matching by !~`', + '"foo" !~ re', '!"foo".match?(re)') + it_behaves_like('all legacy match methods', 'matching by !~`', + 're !~ "foo"', '!"foo".match?(re)') + it_behaves_like('all legacy match methods', 'matching by !~`', + ':foo !~ re', '!:foo.match?(re)') + it_behaves_like('all legacy match methods', 'matching by !~`', + 're !~ :foo', '!:foo.match?(re)') + it_behaves_like('all legacy match methods', 'matching by !~`', + 're !~ foo', '!re&.match?(foo)') + it_behaves_like('all legacy match methods', 'matching by !~`', + 're !~ FOO', '!FOO.match?(re)') + it_behaves_like('all legacy match methods', 'matching by !~`', + 'FOO !~ re', '!FOO.match?(re)') + it_behaves_like('all legacy match methods', 'matching by ===`', + '/re/ === foo', '/re/.match?(foo)') + it_behaves_like('all legacy match methods', 'matching by ===`', + '/re/i === foo', '/re/i.match?(foo)') + + it 'accepts Regexp#match? method call' do + expect_no_offenses(<<~RUBY) + if /re/.match?(str) + do_something + end + RUBY end - context 'target ruby version >= 2.4', :ruby24 do - it_behaves_like('all legacy match methods', 'String#match method call', - '"foo".match(re)', '"foo".match?(re)') - it_behaves_like('all legacy match methods', - 'String#match method call with position', - '"foo".match(re, 1)', '"foo".match?(re, 1)') - it_behaves_like('all legacy match methods', 'Regexp#match method call', - '/re/.match(foo)', '/re/.match?(foo)') - it_behaves_like('all legacy match methods', - 'Regexp#match method call with position', - '/re/.match(foo, 1)', '/re/.match?(foo, 1)') - it_behaves_like('all legacy match methods', 'Symbol#match method call', - ':foo.match(re)', ':foo.match?(re)') - it_behaves_like('all legacy match methods', - 'Symbol#match method call with position', - ':foo.match(re, 1)', ':foo.match?(re, 1)') - it_behaves_like('all legacy match methods', - 'match method call for a variable', - 'foo.match(/re/)', 'foo.match?(/re/)') - it_behaves_like('all legacy match methods', - 'match method call for a variable with position', - 'foo.match(/re/, 1)', 'foo.match?(/re/, 1)') - it_behaves_like('all legacy match methods', 'matching by =~`', - '/re/ =~ foo', '/re/.match?(foo)') - it_behaves_like('all legacy match methods', 'matching by =~`', - 'foo =~ /re/', '/re/.match?(foo)') - it_behaves_like('all legacy match methods', 'matching by =~`', - '"foo" =~ re', '"foo".match?(re)') - it_behaves_like('all legacy match methods', 'matching by =~`', - 're =~ "foo"', '"foo".match?(re)') - it_behaves_like('all legacy match methods', 'matching by =~`', - ':foo =~ re', ':foo.match?(re)') - it_behaves_like('all legacy match methods', 'matching by =~`', - 're =~ :foo', ':foo.match?(re)') - it_behaves_like('all legacy match methods', 'matching by =~`', - 're =~ foo', 're&.match?(foo)') - it_behaves_like('all legacy match methods', 'matching by =~`', - 're =~ FOO', 'FOO.match?(re)') - it_behaves_like('all legacy match methods', 'matching by =~`', - 'FOO =~ re', 'FOO.match?(re)') - it_behaves_like('all legacy match methods', 'matching by !~`', - '/re/ !~ foo', '!/re/.match?(foo)') - it_behaves_like('all legacy match methods', 'matching by !~`', - 'foo !~ /re/', '!/re/.match?(foo)') - it_behaves_like('all legacy match methods', 'matching by !~`', - '"foo" !~ re', '!"foo".match?(re)') - it_behaves_like('all legacy match methods', 'matching by !~`', - 're !~ "foo"', '!"foo".match?(re)') - it_behaves_like('all legacy match methods', 'matching by !~`', - ':foo !~ re', '!:foo.match?(re)') - it_behaves_like('all legacy match methods', 'matching by !~`', - 're !~ :foo', '!:foo.match?(re)') - it_behaves_like('all legacy match methods', 'matching by !~`', - 're !~ foo', '!re&.match?(foo)') - it_behaves_like('all legacy match methods', 'matching by !~`', - 're !~ FOO', '!FOO.match?(re)') - it_behaves_like('all legacy match methods', 'matching by !~`', - 'FOO !~ re', '!FOO.match?(re)') - it_behaves_like('all legacy match methods', 'matching by ===`', - '/re/ === foo', '/re/.match?(foo)') - it_behaves_like('all legacy match methods', 'matching by ===`', - '/re/i === foo', '/re/i.match?(foo)') - - it 'accepts Regexp#match? method call' do - expect_no_offenses(<<~RUBY) - if /re/.match?(str) - do_something - end - RUBY - end - - it 'accepts String#match? method call' do - expect_no_offenses(<<~RUBY) - if str.match?(/re/) - do_something - end - RUBY - end + it 'accepts String#match? method call' do + expect_no_offenses(<<~RUBY) + if str.match?(/re/) + do_something + end + RUBY + end - it 'accepts match without arguments' do - expect_no_offenses(<<~RUBY) - code if match - RUBY - end + it 'accepts match without arguments' do + expect_no_offenses(<<~RUBY) + code if match + RUBY + end - it 'accepts =~ with assignment' do - expect_no_offenses(<<~RUBY) - if /alias_(?.*)/ =~ something - do_something - end - RUBY - end + it 'accepts =~ with assignment' do + expect_no_offenses(<<~RUBY) + if /alias_(?.*)/ =~ something + do_something + end + RUBY + end - it 'accepts match without explicit regexp/str/sym use' do - expect_no_offenses(<<~RUBY) - if CONST.match(var) - do_something - end - RUBY - end + it 'accepts match without explicit regexp/str/sym use' do + expect_no_offenses(<<~RUBY) + if CONST.match(var) + do_something + end + RUBY + end - it 'registers an offense when a regexp used independently ' \ - 'with a regexp used in `if` are mixed' do - expect_offense(<<~RUBY) - def foo - /re/ === re # A regexp used independently is not yet supported. + it 'registers an offense when a regexp used independently ' \ + 'with a regexp used in `if` are mixed' do + expect_offense(<<~RUBY) + def foo + /re/ === re # A regexp used independently is not yet supported. - do_something if /re/ === re - ^^^^^^^^^^^ Use `match?` instead of `===` when `MatchData` is not used. - end - RUBY - end + do_something if /re/ === re + ^^^^^^^^^^^ Use `match?` instead of `===` when `MatchData` is not used. + end + RUBY end end diff --git a/spec/rubocop/cop/performance/unfreeze_string_spec.rb b/spec/rubocop/cop/performance/unfreeze_string_spec.rb index 0ed9134..c2298b0 100644 --- a/spec/rubocop/cop/performance/unfreeze_string_spec.rb +++ b/spec/rubocop/cop/performance/unfreeze_string_spec.rb @@ -3,76 +3,74 @@ RSpec.describe RuboCop::Cop::Performance::UnfreezeString, :config do subject(:cop) { described_class.new(config) } - context 'TargetRubyVersion >= 2.3', :ruby23 do - it 'registers an offense for an empty string with `.dup`' do - expect_offense(<<~RUBY) - "".dup - ^^^^^^ Use unary plus to get an unfrozen string literal. - RUBY - end + it 'registers an offense for an empty string with `.dup`' do + expect_offense(<<~RUBY) + "".dup + ^^^^^^ Use unary plus to get an unfrozen string literal. + RUBY + end - it 'registers an offense for a string with `.dup`' do - expect_offense(<<~RUBY) - "foo".dup - ^^^^^^^^^ Use unary plus to get an unfrozen string literal. - RUBY - end + it 'registers an offense for a string with `.dup`' do + expect_offense(<<~RUBY) + "foo".dup + ^^^^^^^^^ Use unary plus to get an unfrozen string literal. + RUBY + end - it 'registers an offense for a heredoc with `.dup`' do - expect_offense(<<~RUBY) - <