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 +4 -4
- data/lib/rubocop/cop/performance/caller.rb +2 -2
- data/lib/rubocop/cop/performance/case_when_splat.rb +2 -2
- data/lib/rubocop/cop/performance/casecmp.rb +1 -1
- data/lib/rubocop/cop/performance/chain_array_allocation.rb +5 -5
- data/lib/rubocop/cop/performance/compare_with_block.rb +1 -1
- data/lib/rubocop/cop/performance/count.rb +1 -1
- data/lib/rubocop/cop/performance/detect.rb +2 -2
- data/lib/rubocop/cop/performance/double_start_end_with.rb +1 -1
- data/lib/rubocop/cop/performance/end_with.rb +2 -2
- data/lib/rubocop/cop/performance/fixed_size.rb +1 -1
- data/lib/rubocop/cop/performance/flat_map.rb +2 -2
- data/lib/rubocop/cop/performance/open_struct.rb +1 -1
- data/lib/rubocop/cop/performance/range_include.rb +1 -1
- data/lib/rubocop/cop/performance/redundant_block_call.rb +5 -5
- data/lib/rubocop/cop/performance/redundant_match.rb +1 -1
- data/lib/rubocop/cop/performance/redundant_merge.rb +3 -3
- data/lib/rubocop/cop/performance/regexp_match.rb +5 -5
- data/lib/rubocop/cop/performance/reverse_each.rb +2 -2
- data/lib/rubocop/cop/performance/size.rb +2 -2
- data/lib/rubocop/cop/performance/start_with.rb +2 -2
- data/lib/rubocop/cop/performance/string_replacement.rb +5 -5
- data/lib/rubocop/cop/performance/times_map.rb +2 -2
- data/lib/rubocop/cop/performance/unfreeze_string.rb +1 -1
- data/lib/rubocop/cop/performance/uri_default_parser.rb +1 -1
- data/lib/rubocop/performance/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fef013a3148e1dc068ab3f3e2430a2e43f02641ce888b98178f31f2796d291fa
|
4
|
+
data.tar.gz: 9454d77c9fdddef6fd20f1d9155867c98bf698c71f5e79933d05ed74e5e1458d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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]`.'
|
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`.'
|
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.'
|
61
|
+
'of the `when` branches can improve performance.'
|
62
62
|
ARRAY_MSG = 'Pass the contents of array literals ' \
|
63
|
-
'directly to `when` conditions.'
|
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`.'
|
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 '
|
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 '
|
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 :| '
|
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 '
|
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`.'
|
52
|
+
'`%<method>s...%<second_method>s`.'
|
53
53
|
|
54
54
|
def_node_matcher :flat_map_candidate?, <<-PATTERN
|
55
55
|
{
|
@@ -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`.'
|
29
|
+
'`%<first_method>s.%<second_method>s`.'
|
30
30
|
REVERSE_MSG = 'Use `reverse.%<prefer>s` instead of ' \
|
31
|
-
'`%<first_method>s.%<second_method>s`.'
|
31
|
+
'`%<first_method>s.%<second_method>s`.'
|
32
32
|
|
33
33
|
def_node_matcher :detect_candidate?, <<-PATTERN
|
34
34
|
{
|
@@ -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.'
|
20
|
-
SINGLE_QUOTE = "'"
|
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.'
|
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`.'
|
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.'
|
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.'
|
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?`.'
|
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`.'
|
27
|
-
YIELD = 'yield'
|
28
|
-
OPEN_PAREN = '('
|
29
|
-
CLOSE_PAREN = ')'
|
30
|
-
SPACE = ' '
|
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.'
|
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'
|
15
|
-
MSG = 'Use `%<prefer>s` instead of `%<current>s`.'
|
14
|
+
AREF_ASGN = '%<receiver>s[%<key>s] = %<value>s'
|
15
|
+
MSG = 'Use `%<prefer>s` instead of `%<current>s`.'
|
16
16
|
|
17
|
-
WITH_MODIFIER_CORRECTION =
|
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
|
-
'
|
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
|
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`.'
|
19
|
-
UNDERSCORE = '_'
|
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`.'
|
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
|
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.'
|
20
|
-
SINGLE_QUOTE = "'"
|
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`.'
|
24
|
+
MSG = 'Use `%<prefer>s` instead of `%<current>s`.'
|
25
25
|
DETERMINISTIC_REGEX = /\A(?:#{LITERAL_REGEX})+\Z/.freeze
|
26
|
-
DELETE = 'delete'
|
27
|
-
TR = 'tr'
|
28
|
-
BANG = '!'
|
29
|
-
SINGLE_QUOTE = "'"
|
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`'
|
23
|
-
MESSAGE_ONLY_IF = 'only if `%<count>s` is always 0 or more'
|
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)
|
@@ -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`.'
|
18
|
+
'`%<double_colon>sURI::Parser.new`.'
|
19
19
|
|
20
20
|
def_node_matcher :uri_parser_new?, <<-PATTERN
|
21
21
|
(send
|
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.
|
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-
|
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.
|
103
|
+
version: 2.3.0
|
104
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
105
|
requirements:
|
106
106
|
- - ">="
|