Skip to content

Commit

Permalink
[Fix #52] Drop support for Ruby 2.2
Browse files Browse the repository at this point in the history
RuboCop has dropped support for Ruby 2.2 (rubocop/rubocop@bcbcfb8) and so should we.
  • Loading branch information
bquorning committed May 9, 2019
1 parent 72db479 commit dd4ee96
Show file tree
Hide file tree
Showing 30 changed files with 63 additions and 67 deletions.
3 changes: 0 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ jobs:
workflows:
build:
jobs:
- rake_default:
name: Ruby 2.2
image: circleci/ruby:2.2
- rake_default:
name: Ruby 2.3
image: circleci/ruby:2.3
Expand Down
8 changes: 1 addition & 7 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ AllCops:
- 'vendor/**/*'
- 'spec/fixtures/**/*'
- 'tmp/**/*'
TargetRubyVersion: 2.2
TargetRubyVersion: 2.3

Naming/PredicateName:
# Method define macros for dynamically generated method.
Expand All @@ -21,9 +21,6 @@ Naming/PredicateName:
- def_node_matcher
- def_node_search

Style/FrozenStringLiteralComment:
EnforcedStyle: always

Style/FormatStringToken:
# Because we parse a lot of source codes from strings. Percent arrays
# look like unannotated format string tokens to this cop.
Expand Down Expand Up @@ -54,9 +51,6 @@ Layout/ClassStructure:
- protected_methods
- private_methods

Layout/IndentHeredoc:
EnforcedStyle: powerpack

# Trailing white space is meaningful in code examples
Layout/TrailingWhitespace:
AllowInHeredoc: true
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Changes

* [#52](https://github.com/rubocop-hq/rubocop-performance/issues/52): Drop support for Ruby 2.2. ([@bquorning][])

## 1.2.0 (2019-05-04)

### Bug fixes
Expand All @@ -23,3 +27,4 @@

[@composerinteralia]: https://github.com/composerinteralia
[@koic]: https://github.com/koic
[@bquorning]: https://github.com/bquorning
4 changes: 2 additions & 2 deletions lib/rubocop/cop/performance/caller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ module Performance
# caller_locations(1..1).first
class Caller < Cop
MSG_BRACE = 'Use `%<method>s(%<n>d..%<n>d).first`' \
' instead of `%<method>s[%<m>d]`.'.freeze
' instead of `%<method>s[%<m>d]`.'
MSG_FIRST = 'Use `%<method>s(%<n>d..%<n>d).first`' \
' instead of `%<method>s.first`.'.freeze
' instead of `%<method>s.first`.'

def_node_matcher :slow_caller?, <<-PATTERN
{
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/performance/case_when_splat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class CaseWhenSplat < Cop
include RangeHelp

MSG = 'Reordering `when` conditions with a splat to the end ' \
'of the `when` branches can improve performance.'.freeze
'of the `when` branches can improve performance.'
ARRAY_MSG = 'Pass the contents of array literals ' \
'directly to `when` conditions.'.freeze
'directly to `when` conditions.'

def on_case(case_node)
when_conditions = case_node.when_branches.flat_map(&:conditions)
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/performance/casecmp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module Performance
# str.casecmp('ABC').zero?
# 'abc'.casecmp(str).zero?
class Casecmp < Cop
MSG = 'Use `%<good>s` instead of `%<bad>s`.'.freeze
MSG = 'Use `%<good>s` instead of `%<bad>s`.'
CASE_METHODS = %i[downcase upcase].freeze

def_node_matcher :downcase_eq, <<-PATTERN
Expand Down
10 changes: 5 additions & 5 deletions lib/rubocop/cop/performance/chain_array_allocation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,27 @@ class ChainArrayAllocation < Cop
# [1,2].first # => 1
# [1,2].first(1) # => [1]
#
RETURN_NEW_ARRAY_WHEN_ARGS = ':first :last :pop :sample :shift '.freeze
RETURN_NEW_ARRAY_WHEN_ARGS = ':first :last :pop :sample :shift '

# These methods return a new array only when called without a block.
RETURNS_NEW_ARRAY_WHEN_NO_BLOCK = ':zip :product '.freeze
RETURNS_NEW_ARRAY_WHEN_NO_BLOCK = ':zip :product '

# These methods ALWAYS return a new array
# after they're called it's safe to mutate the the resulting array
ALWAYS_RETURNS_NEW_ARRAY = ':* :+ :- :collect :compact :drop '\
':drop_while :flatten :map :reject ' \
':reverse :rotate :select :shuffle :sort ' \
':take :take_while :transpose :uniq ' \
':values_at :| '.freeze
':values_at :| '

# These methods have a mutation alternative. For example :collect
# can be called as :collect!
HAS_MUTATION_ALTERNATIVE = ':collect :compact :flatten :map :reject '\
':reverse :rotate :select :shuffle :sort '\
':uniq '.freeze
':uniq '
MSG = 'Use unchained `%<method>s!` and `%<second_method>s!` '\
'(followed by `return array` if required) instead of chaining '\
'`%<method>s...%<second_method>s`.'.freeze
'`%<method>s...%<second_method>s`.'

def_node_matcher :flat_map_candidate?, <<-PATTERN
{
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/performance/compare_with_block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CompareWithBlock < Cop

MSG = 'Use `%<compare_method>s_by%<instead>s` instead of ' \
'`%<compare_method>s { |%<var_a>s, %<var_b>s| %<str_a>s ' \
'<=> %<str_b>s }`.'.freeze
'<=> %<str_b>s }`.'

def_node_matcher :compare?, <<-PATTERN
(block
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/performance/count.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Count < Cop
include SafeMode
include RangeHelp

MSG = 'Use `count` instead of `%<selector>s...%<counter>s`.'.freeze
MSG = 'Use `count` instead of `%<selector>s...%<counter>s`.'

def_node_matcher :count_candidate?, <<-PATTERN
{
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/performance/detect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class Detect < Cop
include SafeMode

MSG = 'Use `%<prefer>s` instead of ' \
'`%<first_method>s.%<second_method>s`.'.freeze
'`%<first_method>s.%<second_method>s`.'
REVERSE_MSG = 'Use `reverse.%<prefer>s` instead of ' \
'`%<first_method>s.%<second_method>s`.'.freeze
'`%<first_method>s.%<second_method>s`.'

def_node_matcher :detect_candidate?, <<-PATTERN
{
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/performance/double_start_end_with.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Performance
# str.end_with?(var1, var2)
class DoubleStartEndWith < Cop
MSG = 'Use `%<receiver>s.%<method>s(%<combined_args>s)` ' \
'instead of `%<original_code>s`.'.freeze
'instead of `%<original_code>s`.'

def on_or(node)
receiver,
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/performance/end_with.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ module Performance
# 'abc'.end_with?('bc')
class EndWith < Cop
MSG = 'Use `String#end_with?` instead of a regex match anchored to ' \
'the end of the string.'.freeze
SINGLE_QUOTE = "'".freeze
'the end of the string.'
SINGLE_QUOTE = "'"

def_node_matcher :redundant_regex?, <<-PATTERN
{(send $!nil? {:match :=~ :match?} (regexp (str $#literal_at_end?) (regopt)))
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/performance/fixed_size.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module Performance
# waldo.size
#
class FixedSize < Cop
MSG = 'Do not compute the size of statically sized objects.'.freeze
MSG = 'Do not compute the size of statically sized objects.'

def_node_matcher :counter, <<-MATCHER
(send ${array hash str sym} {:count :length :size} $...)
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/performance/flat_map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ module Performance
class FlatMap < Cop
include RangeHelp

MSG = 'Use `flat_map` instead of `%<method>s...%<flatten>s`.'.freeze
MSG = 'Use `flat_map` instead of `%<method>s...%<flatten>s`.'
FLATTEN_MULTIPLE_LEVELS = ' Beware, `flat_map` only flattens 1 level ' \
'and `flatten` can be used to flatten ' \
'multiple levels.'.freeze
'multiple levels.'

def_node_matcher :flat_map_candidate?, <<-PATTERN
(send (block $(send _ ${:collect :map}) ...) ${:flatten :flatten!} $...)
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/performance/open_struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module Performance
#
class OpenStruct < Cop
MSG = 'Consider using `Struct` over `OpenStruct` ' \
'to optimize the performance.'.freeze
'to optimize the performance.'

def_node_matcher :open_struct, <<-PATTERN
(send (const {nil? cbase} :OpenStruct) :new ...)
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/performance/range_include.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module Performance
#
# ('a'..'z').cover?('yellow') # => true
class RangeInclude < Cop
MSG = 'Use `Range#cover?` instead of `Range#include?`.'.freeze
MSG = 'Use `Range#cover?` instead of `Range#include?`.'

# TODO: If we traced out assignments of variables to their uses, we
# might pick up on a few more instances of this issue
Expand Down
10 changes: 5 additions & 5 deletions lib/rubocop/cop/performance/redundant_block_call.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ module Performance
# yield 1, 2, 3
# end
class RedundantBlockCall < Cop
MSG = 'Use `yield` instead of `%<argname>s.call`.'.freeze
YIELD = 'yield'.freeze
OPEN_PAREN = '('.freeze
CLOSE_PAREN = ')'.freeze
SPACE = ' '.freeze
MSG = 'Use `yield` instead of `%<argname>s.call`.'
YIELD = 'yield'
OPEN_PAREN = '('
CLOSE_PAREN = ')'
SPACE = ' '

def_node_matcher :blockarg_def, <<-PATTERN
{(def _ (args ... (blockarg $_)) $_)
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/performance/redundant_match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Performance
# return value unless regex =~ 'str'
class RedundantMatch < Cop
MSG = 'Use `=~` in places where the `MatchData` returned by ' \
'`#match` will not be used.'.freeze
'`#match` will not be used.'

# 'match' is a fairly generic name, so we don't flag it unless we see
# a string or regexp literal on one side or the other
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/performance/redundant_merge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ module Performance
# hash.merge!({'key' => 'value'})
# hash.merge!(a: 1, b: 2)
class RedundantMerge < Cop
AREF_ASGN = '%<receiver>s[%<key>s] = %<value>s'.freeze
MSG = 'Use `%<prefer>s` instead of `%<current>s`.'.freeze
AREF_ASGN = '%<receiver>s[%<key>s] = %<value>s'
MSG = 'Use `%<prefer>s` instead of `%<current>s`.'

WITH_MODIFIER_CORRECTION = <<-RUBY.strip_indent
%<keyword>s %<condition>s
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/performance/regexp_match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class RegexpMatch < Cop
TYPES_IMPLEMENTING_MATCH = %i[const regexp str sym].freeze
MSG =
'Use `match?` instead of `%<current>s` when `MatchData` ' \
'is not used.'.freeze
'is not used.'

def_node_matcher :match_method?, <<-PATTERN
{
Expand All @@ -106,7 +106,7 @@ def match_with_lvasgn?(node)
regexp.to_regexp.named_captures.empty?
end

MATCH_NODE_PATTERN = <<-PATTERN.freeze
MATCH_NODE_PATTERN = <<-PATTERN
{
#match_method?
#match_operator?
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/performance/reverse_each.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ module Performance
class ReverseEach < Cop
include RangeHelp

MSG = 'Use `reverse_each` instead of `reverse.each`.'.freeze
UNDERSCORE = '_'.freeze
MSG = 'Use `reverse_each` instead of `reverse.each`.'
UNDERSCORE = '_'

def_node_matcher :reverse_each?, <<-MATCHER
(send $(send _ :reverse) :each)
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/performance/size.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module Performance
# TODO: Add advanced detection of variables that could
# have been assigned to an array or a hash.
class Size < Cop
MSG = 'Use `size` instead of `count`.'.freeze
MSG = 'Use `size` instead of `count`.'

def on_send(node)
return unless eligible_node?(node)
Expand All @@ -51,7 +51,7 @@ def eligible_receiver?(node)
end

def allowed_parent?(node)
node && node.block_type?
node&.block_type?
end

def array?(node)
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/performance/start_with.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ module Performance
# 'abc'.start_with?('ab')
class StartWith < Cop
MSG = 'Use `String#start_with?` instead of a regex match anchored to ' \
'the beginning of the string.'.freeze
SINGLE_QUOTE = "'".freeze
'the beginning of the string.'
SINGLE_QUOTE = "'"

def_node_matcher :redundant_regex?, <<-PATTERN
{(send $!nil? {:match :=~ :match?} (regexp (str $#literal_at_start?) (regopt)))
Expand Down
10 changes: 5 additions & 5 deletions lib/rubocop/cop/performance/string_replacement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ module Performance
class StringReplacement < Cop
include RangeHelp

MSG = 'Use `%<prefer>s` instead of `%<current>s`.'.freeze
MSG = 'Use `%<prefer>s` instead of `%<current>s`.'
DETERMINISTIC_REGEX = /\A(?:#{LITERAL_REGEX})+\Z/.freeze
DELETE = 'delete'.freeze
TR = 'tr'.freeze
BANG = '!'.freeze
SINGLE_QUOTE = "'".freeze
DELETE = 'delete'
TR = 'tr'
BANG = '!'
SINGLE_QUOTE = "'"

def_node_matcher :string_replacement?, <<-PATTERN
(send _ {:gsub :gsub!}
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/performance/times_map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ module Performance
# end
class TimesMap < Cop
MESSAGE = 'Use `Array.new(%<count>s)` with a block ' \
'instead of `.times.%<map_or_collect>s`'.freeze
MESSAGE_ONLY_IF = 'only if `%<count>s` is always 0 or more'.freeze
'instead of `.times.%<map_or_collect>s`'
MESSAGE_ONLY_IF = 'only if `%<count>s` is always 0 or more'

def on_send(node)
check(node)
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/performance/unfreeze_string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class UnfreezeString < Cop

minimum_target_ruby_version 2.3

MSG = 'Use unary plus to get an unfrozen string literal.'.freeze
MSG = 'Use unary plus to get an unfrozen string literal.'

def_node_matcher :dup_string?, <<-PATTERN
(send {str dstr} :dup)
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/performance/uri_default_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Performance
#
class UriDefaultParser < Cop
MSG = 'Use `%<double_colon>sURI::DEFAULT_PARSER` instead of ' \
'`%<double_colon>sURI::Parser.new`.'.freeze
'`%<double_colon>sURI::Parser.new`.'

def_node_matcher :uri_parser_new?, <<-PATTERN
(send
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/performance/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module RuboCop
module Performance
module Version
STRING = '1.2.0'.freeze
STRING = '1.2.0'
end
end
end
2 changes: 1 addition & 1 deletion rubocop-performance.gemspec
Original file line number Diff line number Diff line change
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.2.2'
s.required_ruby_version = '>= 2.3.0'
s.authors = ['Bozhidar Batsov', 'Jonas Arvidsson', 'Yuji Nakayama']
s.description = <<-DESCRIPTION
A collection of RuboCop cops to check for performance optimizations
Expand Down
Loading

0 comments on commit dd4ee96

Please sign in to comment.