Skip to content

Commit

Permalink
Drop support for Ruby 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
richardstewart0213 committed Apr 13, 2020
1 parent c896bc1 commit 734da22
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 196 deletions.
3 changes: 0 additions & 3 deletions .circleci/config.yml
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Expand Up @@ -11,7 +11,7 @@ AllCops:
- 'vendor/**/*'
- 'spec/fixtures/**/*'
- 'tmp/**/*'
TargetRubyVersion: 2.3
TargetRubyVersion: 2.4

Naming/PredicateName:
# Method define macros for dynamically generated method.
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions lib/rubocop/cop/performance/unfreeze_string.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rubocop-performance.gemspec
Expand Up @@ -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
Expand Down
228 changes: 103 additions & 125 deletions spec/rubocop/cop/performance/regexp_match_spec.rb
Expand Up @@ -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_(?<alias_id>.*)/ =~ something
do_something
end
RUBY
end
it 'accepts =~ with assignment' do
expect_no_offenses(<<~RUBY)
if /alias_(?<alias_id>.*)/ =~ 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

0 comments on commit 734da22

Please sign in to comment.