rubocop-performance 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d571b90f427f5c2d7212fcf223a975d2426cc5b216832832d3d22c4196c6c7d3
4
- data.tar.gz: '09978347ef923455817c3f9e1753011efd618f99e6f72deffdf0e221ece5c5ad'
3
+ metadata.gz: fef013a3148e1dc068ab3f3e2430a2e43f02641ce888b98178f31f2796d291fa
4
+ data.tar.gz: 9454d77c9fdddef6fd20f1d9155867c98bf698c71f5e79933d05ed74e5e1458d
5
5
  SHA512:
6
- metadata.gz: b5886c02136883367f4fadf6818369dd08c344ee2306704a3695cc28f3c19b4d45a434f56d9b3b229d9f01644b530e64057fe6a2ae2830157d181079dc880a7e
7
- data.tar.gz: 7139532bfe4d15a47cee1eff3618529ae93faec8cedb693a40a454b866fb1f3e252fbb303e7f393ba70c9e9ab387e2814dd96e15d36b9d1dfcb693a5f08f5608
6
+ metadata.gz: 5ca78e431963e440efe8a21b4298c69b473717ec3601a80dce40fb5c072360508338aa9de4e8a33f93c9329c033fd410db47d7e7df3ba7afdddf520d1b0487e9
7
+ data.tar.gz: 1065ae95c427f38581d054e573a5799caaacf46445f601aeb8f200c0f0772c190c4e2499c24b5fbc9bacb64ab30bec71127417d61c4206808d362e8974c6ada9
@@ -20,9 +20,9 @@ module RuboCop
20
20
  # caller_locations(1..1).first
21
21
  class Caller < Cop
22
22
  MSG_BRACE = 'Use `%<method>s(%<n>d..%<n>d).first`' \
23
- ' instead of `%<method>s[%<m>d]`.'.freeze
23
+ ' instead of `%<method>s[%<m>d]`.'
24
24
  MSG_FIRST = 'Use `%<method>s(%<n>d..%<n>d).first`' \
25
- ' instead of `%<method>s.first`.'.freeze
25
+ ' instead of `%<method>s.first`.'
26
26
 
27
27
  def_node_matcher :slow_caller?, <<-PATTERN
28
28
  {
@@ -58,9 +58,9 @@ module RuboCop
58
58
  include RangeHelp
59
59
 
60
60
  MSG = 'Reordering `when` conditions with a splat to the end ' \
61
- 'of the `when` branches can improve performance.'.freeze
61
+ 'of the `when` branches can improve performance.'
62
62
  ARRAY_MSG = 'Pass the contents of array literals ' \
63
- 'directly to `when` conditions.'.freeze
63
+ 'directly to `when` conditions.'
64
64
 
65
65
  def on_case(case_node)
66
66
  when_conditions = case_node.when_branches.flat_map(&:conditions)
@@ -18,7 +18,7 @@ module RuboCop
18
18
  # str.casecmp('ABC').zero?
19
19
  # 'abc'.casecmp(str).zero?
20
20
  class Casecmp < Cop
21
- MSG = 'Use `%<good>s` instead of `%<bad>s`.'.freeze
21
+ MSG = 'Use `%<good>s` instead of `%<bad>s`.'
22
22
  CASE_METHODS = %i[downcase upcase].freeze
23
23
 
24
24
  def_node_matcher :downcase_eq, <<-PATTERN
@@ -29,10 +29,10 @@ module RuboCop
29
29
  # [1,2].first # => 1
30
30
  # [1,2].first(1) # => [1]
31
31
  #
32
- RETURN_NEW_ARRAY_WHEN_ARGS = ':first :last :pop :sample :shift '.freeze
32
+ RETURN_NEW_ARRAY_WHEN_ARGS = ':first :last :pop :sample :shift '
33
33
 
34
34
  # These methods return a new array only when called without a block.
35
- RETURNS_NEW_ARRAY_WHEN_NO_BLOCK = ':zip :product '.freeze
35
+ RETURNS_NEW_ARRAY_WHEN_NO_BLOCK = ':zip :product '
36
36
 
37
37
  # These methods ALWAYS return a new array
38
38
  # after they're called it's safe to mutate the the resulting array
@@ -40,16 +40,16 @@ module RuboCop
40
40
  ':drop_while :flatten :map :reject ' \
41
41
  ':reverse :rotate :select :shuffle :sort ' \
42
42
  ':take :take_while :transpose :uniq ' \
43
- ':values_at :| '.freeze
43
+ ':values_at :| '
44
44
 
45
45
  # These methods have a mutation alternative. For example :collect
46
46
  # can be called as :collect!
47
47
  HAS_MUTATION_ALTERNATIVE = ':collect :compact :flatten :map :reject '\
48
48
  ':reverse :rotate :select :shuffle :sort '\
49
- ':uniq '.freeze
49
+ ':uniq '
50
50
  MSG = 'Use unchained `%<method>s!` and `%<second_method>s!` '\
51
51
  '(followed by `return array` if required) instead of chaining '\
52
- '`%<method>s...%<second_method>s`.'.freeze
52
+ '`%<method>s...%<second_method>s`.'
53
53
 
54
54
  def_node_matcher :flat_map_candidate?, <<-PATTERN
55
55
  {
@@ -28,7 +28,7 @@ module RuboCop
28
28
 
29
29
  MSG = 'Use `%<compare_method>s_by%<instead>s` instead of ' \
30
30
  '`%<compare_method>s { |%<var_a>s, %<var_b>s| %<str_a>s ' \
31
- '<=> %<str_b>s }`.'.freeze
31
+ '<=> %<str_b>s }`.'
32
32
 
33
33
  def_node_matcher :compare?, <<-PATTERN
34
34
  (block
@@ -41,7 +41,7 @@ module RuboCop
41
41
  include SafeMode
42
42
  include RangeHelp
43
43
 
44
- MSG = 'Use `count` instead of `%<selector>s...%<counter>s`.'.freeze
44
+ MSG = 'Use `count` instead of `%<selector>s...%<counter>s`.'
45
45
 
46
46
  def_node_matcher :count_candidate?, <<-PATTERN
47
47
  {
@@ -26,9 +26,9 @@ module RuboCop
26
26
  include SafeMode
27
27
 
28
28
  MSG = 'Use `%<prefer>s` instead of ' \
29
- '`%<first_method>s.%<second_method>s`.'.freeze
29
+ '`%<first_method>s.%<second_method>s`.'
30
30
  REVERSE_MSG = 'Use `reverse.%<prefer>s` instead of ' \
31
- '`%<first_method>s.%<second_method>s`.'.freeze
31
+ '`%<first_method>s.%<second_method>s`.'
32
32
 
33
33
  def_node_matcher :detect_candidate?, <<-PATTERN
34
34
  {
@@ -19,7 +19,7 @@ module RuboCop
19
19
  # str.end_with?(var1, var2)
20
20
  class DoubleStartEndWith < Cop
21
21
  MSG = 'Use `%<receiver>s.%<method>s(%<combined_args>s)` ' \
22
- 'instead of `%<original_code>s`.'.freeze
22
+ 'instead of `%<original_code>s`.'
23
23
 
24
24
  def on_or(node)
25
25
  receiver,
@@ -16,8 +16,8 @@ module RuboCop
16
16
  # 'abc'.end_with?('bc')
17
17
  class EndWith < Cop
18
18
  MSG = 'Use `String#end_with?` instead of a regex match anchored to ' \
19
- 'the end of the string.'.freeze
20
- SINGLE_QUOTE = "'".freeze
19
+ 'the end of the string.'
20
+ SINGLE_QUOTE = "'"
21
21
 
22
22
  def_node_matcher :redundant_regex?, <<-PATTERN
23
23
  {(send $!nil? {:match :=~ :match?} (regexp (str $#literal_at_end?) (regopt)))
@@ -46,7 +46,7 @@ module RuboCop
46
46
  # waldo.size
47
47
  #
48
48
  class FixedSize < Cop
49
- MSG = 'Do not compute the size of statically sized objects.'.freeze
49
+ MSG = 'Do not compute the size of statically sized objects.'
50
50
 
51
51
  def_node_matcher :counter, <<-MATCHER
52
52
  (send ${array hash str sym} {:count :length :size} $...)
@@ -17,10 +17,10 @@ module RuboCop
17
17
  class FlatMap < Cop
18
18
  include RangeHelp
19
19
 
20
- MSG = 'Use `flat_map` instead of `%<method>s...%<flatten>s`.'.freeze
20
+ MSG = 'Use `flat_map` instead of `%<method>s...%<flatten>s`.'
21
21
  FLATTEN_MULTIPLE_LEVELS = ' Beware, `flat_map` only flattens 1 level ' \
22
22
  'and `flatten` can be used to flatten ' \
23
- 'multiple levels.'.freeze
23
+ 'multiple levels.'
24
24
 
25
25
  def_node_matcher :flat_map_candidate?, <<-PATTERN
26
26
  (send (block $(send _ ${:collect :map}) ...) ${:flatten :flatten!} $...)
@@ -29,7 +29,7 @@ module RuboCop
29
29
  #
30
30
  class OpenStruct < Cop
31
31
  MSG = 'Consider using `Struct` over `OpenStruct` ' \
32
- 'to optimize the performance.'.freeze
32
+ 'to optimize the performance.'
33
33
 
34
34
  def_node_matcher :open_struct, <<-PATTERN
35
35
  (send (const {nil? cbase} :OpenStruct) :new ...)
@@ -24,7 +24,7 @@ module RuboCop
24
24
  #
25
25
  # ('a'..'z').cover?('yellow') # => true
26
26
  class RangeInclude < Cop
27
- MSG = 'Use `Range#cover?` instead of `Range#include?`.'.freeze
27
+ MSG = 'Use `Range#cover?` instead of `Range#include?`.'
28
28
 
29
29
  # TODO: If we traced out assignments of variables to their uses, we
30
30
  # might pick up on a few more instances of this issue
@@ -23,11 +23,11 @@ module RuboCop
23
23
  # yield 1, 2, 3
24
24
  # end
25
25
  class RedundantBlockCall < Cop
26
- MSG = 'Use `yield` instead of `%<argname>s.call`.'.freeze
27
- YIELD = 'yield'.freeze
28
- OPEN_PAREN = '('.freeze
29
- CLOSE_PAREN = ')'.freeze
30
- SPACE = ' '.freeze
26
+ MSG = 'Use `yield` instead of `%<argname>s.call`.'
27
+ YIELD = 'yield'
28
+ OPEN_PAREN = '('
29
+ CLOSE_PAREN = ')'
30
+ SPACE = ' '
31
31
 
32
32
  def_node_matcher :blockarg_def, <<-PATTERN
33
33
  {(def _ (args ... (blockarg $_)) $_)
@@ -19,7 +19,7 @@ module RuboCop
19
19
  # return value unless regex =~ 'str'
20
20
  class RedundantMatch < Cop
21
21
  MSG = 'Use `=~` in places where the `MatchData` returned by ' \
22
- '`#match` will not be used.'.freeze
22
+ '`#match` will not be used.'
23
23
 
24
24
  # 'match' is a fairly generic name, so we don't flag it unless we see
25
25
  # a string or regexp literal on one side or the other
@@ -11,10 +11,10 @@ module RuboCop
11
11
  # hash.merge!({'key' => 'value'})
12
12
  # hash.merge!(a: 1, b: 2)
13
13
  class RedundantMerge < Cop
14
- AREF_ASGN = '%<receiver>s[%<key>s] = %<value>s'.freeze
15
- MSG = 'Use `%<prefer>s` instead of `%<current>s`.'.freeze
14
+ AREF_ASGN = '%<receiver>s[%<key>s] = %<value>s'
15
+ MSG = 'Use `%<prefer>s` instead of `%<current>s`.'
16
16
 
17
- WITH_MODIFIER_CORRECTION = <<-RUBY.strip_indent
17
+ WITH_MODIFIER_CORRECTION = <<~RUBY
18
18
  %<keyword>s %<condition>s
19
19
  %<leading_space>s%<indent>s%<body>s
20
20
  %<leading_space>send
@@ -80,14 +80,14 @@ module RuboCop
80
80
  # Constants are included in this list because it is unlikely that
81
81
  # someone will store `nil` as a constant and then use it for comparison
82
82
  TYPES_IMPLEMENTING_MATCH = %i[const regexp str sym].freeze
83
- MSG =
84
- 'Use `match?` instead of `%<current>s` when `MatchData` ' \
85
- 'is not used.'.freeze
83
+ MSG = 'Use `match?` instead of `%<current>s` when `MatchData` ' \
84
+ 'is not used.'
86
85
 
87
86
  def_node_matcher :match_method?, <<-PATTERN
88
87
  {
89
88
  (send _recv :match _ <int ...>)
90
- (send _recv :match _)
89
+ (send _recv :match {regexp str sym})
90
+ (send {regexp str sym} :match _)
91
91
  }
92
92
  PATTERN
93
93
 
@@ -106,7 +106,7 @@ module RuboCop
106
106
  regexp.to_regexp.named_captures.empty?
107
107
  end
108
108
 
109
- MATCH_NODE_PATTERN = <<-PATTERN.freeze
109
+ MATCH_NODE_PATTERN = <<-PATTERN
110
110
  {
111
111
  #match_method?
112
112
  #match_operator?
@@ -15,8 +15,8 @@ module RuboCop
15
15
  class ReverseEach < Cop
16
16
  include RangeHelp
17
17
 
18
- MSG = 'Use `reverse_each` instead of `reverse.each`.'.freeze
19
- UNDERSCORE = '_'.freeze
18
+ MSG = 'Use `reverse_each` instead of `reverse.each`.'
19
+ UNDERSCORE = '_'
20
20
 
21
21
  def_node_matcher :reverse_each?, <<-MATCHER
22
22
  (send $(send _ :reverse) :each)
@@ -24,7 +24,7 @@ module RuboCop
24
24
  # TODO: Add advanced detection of variables that could
25
25
  # have been assigned to an array or a hash.
26
26
  class Size < Cop
27
- MSG = 'Use `size` instead of `count`.'.freeze
27
+ MSG = 'Use `size` instead of `count`.'
28
28
 
29
29
  def on_send(node)
30
30
  return unless eligible_node?(node)
@@ -51,7 +51,7 @@ module RuboCop
51
51
  end
52
52
 
53
53
  def allowed_parent?(node)
54
- node && node.block_type?
54
+ node&.block_type?
55
55
  end
56
56
 
57
57
  def array?(node)
@@ -16,8 +16,8 @@ module RuboCop
16
16
  # 'abc'.start_with?('ab')
17
17
  class StartWith < Cop
18
18
  MSG = 'Use `String#start_with?` instead of a regex match anchored to ' \
19
- 'the beginning of the string.'.freeze
20
- SINGLE_QUOTE = "'".freeze
19
+ 'the beginning of the string.'
20
+ SINGLE_QUOTE = "'"
21
21
 
22
22
  def_node_matcher :redundant_regex?, <<-PATTERN
23
23
  {(send $!nil? {:match :=~ :match?} (regexp (str $#literal_at_start?) (regopt)))
@@ -21,12 +21,12 @@ module RuboCop
21
21
  class StringReplacement < Cop
22
22
  include RangeHelp
23
23
 
24
- MSG = 'Use `%<prefer>s` instead of `%<current>s`.'.freeze
24
+ MSG = 'Use `%<prefer>s` instead of `%<current>s`.'
25
25
  DETERMINISTIC_REGEX = /\A(?:#{LITERAL_REGEX})+\Z/.freeze
26
- DELETE = 'delete'.freeze
27
- TR = 'tr'.freeze
28
- BANG = '!'.freeze
29
- SINGLE_QUOTE = "'".freeze
26
+ DELETE = 'delete'
27
+ TR = 'tr'
28
+ BANG = '!'
29
+ SINGLE_QUOTE = "'"
30
30
 
31
31
  def_node_matcher :string_replacement?, <<-PATTERN
32
32
  (send _ {:gsub :gsub!}
@@ -19,8 +19,8 @@ module RuboCop
19
19
  # end
20
20
  class TimesMap < Cop
21
21
  MESSAGE = 'Use `Array.new(%<count>s)` with a block ' \
22
- 'instead of `.times.%<map_or_collect>s`'.freeze
23
- MESSAGE_ONLY_IF = 'only if `%<count>s` is always 0 or more'.freeze
22
+ 'instead of `.times.%<map_or_collect>s`'
23
+ MESSAGE_ONLY_IF = 'only if `%<count>s` is always 0 or more'
24
24
 
25
25
  def on_send(node)
26
26
  check(node)
@@ -28,7 +28,7 @@ module RuboCop
28
28
 
29
29
  minimum_target_ruby_version 2.3
30
30
 
31
- MSG = 'Use unary plus to get an unfrozen string literal.'.freeze
31
+ MSG = 'Use unary plus to get an unfrozen string literal.'
32
32
 
33
33
  def_node_matcher :dup_string?, <<-PATTERN
34
34
  (send {str dstr} :dup)
@@ -15,7 +15,7 @@ module RuboCop
15
15
  #
16
16
  class UriDefaultParser < Cop
17
17
  MSG = 'Use `%<double_colon>sURI::DEFAULT_PARSER` instead of ' \
18
- '`%<double_colon>sURI::Parser.new`.'.freeze
18
+ '`%<double_colon>sURI::Parser.new`.'
19
19
 
20
20
  def_node_matcher :uri_parser_new?, <<-PATTERN
21
21
  (send
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Performance
5
5
  module Version
6
- STRING = '1.2.0'.freeze
6
+ STRING = '1.3.0'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-performance
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-05-04 00:00:00.000000000 Z
13
+ date: 2019-05-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop
@@ -100,7 +100,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: 2.2.2
103
+ version: 2.3.0
104
104
  required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  requirements:
106
106
  - - ">="