rubocop-performance 1.18.0 → 1.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/config/default.yml +24 -17
- data/lib/rubocop/cop/mixin/sort_block.rb +2 -2
- data/lib/rubocop/cop/performance/array_semi_infinite_range_slice.rb +2 -1
- data/lib/rubocop/cop/performance/block_given_with_explicit_block.rb +4 -0
- data/lib/rubocop/cop/performance/casecmp.rb +6 -0
- data/lib/rubocop/cop/performance/chain_array_allocation.rb +11 -4
- data/lib/rubocop/cop/performance/count.rb +5 -5
- data/lib/rubocop/cop/performance/delete_prefix.rb +5 -2
- data/lib/rubocop/cop/performance/delete_suffix.rb +5 -2
- data/lib/rubocop/cop/performance/detect.rb +3 -2
- data/lib/rubocop/cop/performance/end_with.rb +6 -3
- data/lib/rubocop/cop/performance/fixed_size.rb +4 -3
- data/lib/rubocop/cop/performance/flat_map.rb +4 -3
- data/lib/rubocop/cop/performance/inefficient_hash_search.rb +16 -10
- data/lib/rubocop/cop/performance/map_compact.rb +5 -4
- data/lib/rubocop/cop/performance/map_method_chain.rb +89 -0
- data/lib/rubocop/cop/performance/range_include.rb +8 -6
- data/lib/rubocop/cop/performance/redundant_block_call.rb +2 -0
- data/lib/rubocop/cop/performance/redundant_equality_comparison_block.rb +1 -1
- data/lib/rubocop/cop/performance/redundant_match.rb +30 -1
- data/lib/rubocop/cop/performance/redundant_merge.rb +5 -3
- data/lib/rubocop/cop/performance/redundant_split_regexp_argument.rb +2 -1
- data/lib/rubocop/cop/performance/regexp_match.rb +1 -8
- data/lib/rubocop/cop/performance/reverse_each.rb +2 -1
- data/lib/rubocop/cop/performance/reverse_first.rb +6 -13
- data/lib/rubocop/cop/performance/select_map.rb +3 -6
- data/lib/rubocop/cop/performance/size.rb +4 -3
- data/lib/rubocop/cop/performance/sort_reverse.rb +5 -4
- data/lib/rubocop/cop/performance/squeeze.rb +5 -2
- data/lib/rubocop/cop/performance/start_with.rb +6 -3
- data/lib/rubocop/cop/performance/string_identifier_argument.rb +58 -10
- data/lib/rubocop/cop/performance/string_include.rb +11 -5
- data/lib/rubocop/cop/performance/string_replacement.rb +2 -1
- data/lib/rubocop/cop/performance/sum.rb +11 -9
- data/lib/rubocop/cop/performance/times_map.rb +14 -2
- data/lib/rubocop/cop/performance/unfreeze_string.rb +6 -3
- data/lib/rubocop/cop/performance/uri_default_parser.rb +1 -1
- data/lib/rubocop/cop/performance_cops.rb +1 -0
- data/lib/rubocop/performance/version.rb +1 -1
- data/lib/rubocop-performance.rb +8 -0
- metadata +15 -8
@@ -39,6 +39,7 @@ module RuboCop
|
|
39
39
|
def on_send(node)
|
40
40
|
check(node)
|
41
41
|
end
|
42
|
+
alias on_csend on_send
|
42
43
|
|
43
44
|
def on_block(node)
|
44
45
|
check(node)
|
@@ -49,6 +50,8 @@ module RuboCop
|
|
49
50
|
|
50
51
|
def check(node)
|
51
52
|
times_map_call(node) do |map_or_collect, count|
|
53
|
+
next unless handleable_receiver?(node)
|
54
|
+
|
52
55
|
add_offense(node, message: message(map_or_collect, count)) do |corrector|
|
53
56
|
replacement = "Array.new(#{count.source}#{map_or_collect.arguments.map { |arg| ", #{arg.source}" }.join})"
|
54
57
|
|
@@ -57,6 +60,13 @@ module RuboCop
|
|
57
60
|
end
|
58
61
|
end
|
59
62
|
|
63
|
+
def handleable_receiver?(node)
|
64
|
+
receiver = node.receiver.receiver
|
65
|
+
return true if receiver.literal? && (receiver.int_type? || receiver.float_type?)
|
66
|
+
|
67
|
+
node.receiver.dot?
|
68
|
+
end
|
69
|
+
|
60
70
|
def message(map_or_collect, count)
|
61
71
|
template = if count.literal?
|
62
72
|
"#{MESSAGE}."
|
@@ -67,8 +77,10 @@ module RuboCop
|
|
67
77
|
end
|
68
78
|
|
69
79
|
def_node_matcher :times_map_call, <<~PATTERN
|
70
|
-
{
|
71
|
-
|
80
|
+
{
|
81
|
+
({block numblock} $(call (call $!nil? :times) {:map :collect}) ...)
|
82
|
+
$(call (call $!nil? :times) {:map :collect} (block_pass ...))
|
83
|
+
}
|
72
84
|
PATTERN
|
73
85
|
end
|
74
86
|
end
|
@@ -15,8 +15,8 @@ module RuboCop
|
|
15
15
|
#
|
16
16
|
# @example
|
17
17
|
# # bad
|
18
|
-
# ''.dup
|
19
|
-
# "something".dup
|
18
|
+
# ''.dup # when Ruby 3.2 or lower
|
19
|
+
# "something".dup # when Ruby 3.2 or lower
|
20
20
|
# String.new
|
21
21
|
# String.new('')
|
22
22
|
# String.new('something')
|
@@ -26,6 +26,9 @@ module RuboCop
|
|
26
26
|
# +''
|
27
27
|
class UnfreezeString < Base
|
28
28
|
extend AutoCorrector
|
29
|
+
extend TargetRubyVersion
|
30
|
+
|
31
|
+
minimum_target_ruby_version 2.3
|
29
32
|
|
30
33
|
MSG = 'Use unary plus to get an unfrozen string literal.'
|
31
34
|
RESTRICT_ON_SEND = %i[dup new].freeze
|
@@ -42,7 +45,7 @@ module RuboCop
|
|
42
45
|
PATTERN
|
43
46
|
|
44
47
|
def on_send(node)
|
45
|
-
return unless dup_string?(node) || string_new?(node)
|
48
|
+
return unless (dup_string?(node) && target_ruby_version <= 3.2) || string_new?(node)
|
46
49
|
|
47
50
|
add_offense(node) do |corrector|
|
48
51
|
string_value = "+#{string_value(node)}"
|
@@ -25,6 +25,7 @@ require_relative 'performance/fixed_size'
|
|
25
25
|
require_relative 'performance/flat_map'
|
26
26
|
require_relative 'performance/inefficient_hash_search'
|
27
27
|
require_relative 'performance/map_compact'
|
28
|
+
require_relative 'performance/map_method_chain'
|
28
29
|
require_relative 'performance/method_object_as_block'
|
29
30
|
require_relative 'performance/open_struct'
|
30
31
|
require_relative 'performance/range_include'
|
data/lib/rubocop-performance.rb
CHANGED
@@ -9,3 +9,11 @@ require_relative 'rubocop/performance/inject'
|
|
9
9
|
RuboCop::Performance::Inject.defaults!
|
10
10
|
|
11
11
|
require_relative 'rubocop/cop/performance_cops'
|
12
|
+
|
13
|
+
RuboCop::Cop::Lint::UnusedMethodArgument.singleton_class.prepend(
|
14
|
+
Module.new do
|
15
|
+
def autocorrect_incompatible_with
|
16
|
+
super.push(RuboCop::Cop::Performance::BlockGivenWithExplicitBlock)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
)
|
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.21.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:
|
13
|
+
date: 2024-03-30 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.
|
21
|
+
version: 1.48.1
|
22
22
|
- - "<"
|
23
23
|
- !ruby/object:Gem::Version
|
24
24
|
version: '2.0'
|
@@ -28,7 +28,7 @@ dependencies:
|
|
28
28
|
requirements:
|
29
29
|
- - ">="
|
30
30
|
- !ruby/object:Gem::Version
|
31
|
-
version: 1.
|
31
|
+
version: 1.48.1
|
32
32
|
- - "<"
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '2.0'
|
@@ -38,14 +38,20 @@ dependencies:
|
|
38
38
|
requirements:
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
41
|
+
version: 1.31.1
|
42
|
+
- - "<"
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '2.0'
|
42
45
|
type: :runtime
|
43
46
|
prerelease: false
|
44
47
|
version_requirements: !ruby/object:Gem::Requirement
|
45
48
|
requirements:
|
46
49
|
- - ">="
|
47
50
|
- !ruby/object:Gem::Version
|
48
|
-
version:
|
51
|
+
version: 1.31.1
|
52
|
+
- - "<"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
49
55
|
description: |
|
50
56
|
A collection of RuboCop cops to check for performance optimizations
|
51
57
|
in Ruby code.
|
@@ -87,6 +93,7 @@ files:
|
|
87
93
|
- lib/rubocop/cop/performance/inefficient_hash_search.rb
|
88
94
|
- lib/rubocop/cop/performance/io_readlines.rb
|
89
95
|
- lib/rubocop/cop/performance/map_compact.rb
|
96
|
+
- lib/rubocop/cop/performance/map_method_chain.rb
|
90
97
|
- lib/rubocop/cop/performance/method_object_as_block.rb
|
91
98
|
- lib/rubocop/cop/performance/open_struct.rb
|
92
99
|
- lib/rubocop/cop/performance/range_include.rb
|
@@ -123,7 +130,7 @@ metadata:
|
|
123
130
|
homepage_uri: https://docs.rubocop.org/rubocop-performance/
|
124
131
|
changelog_uri: https://github.com/rubocop/rubocop-performance/blob/master/CHANGELOG.md
|
125
132
|
source_code_uri: https://github.com/rubocop/rubocop-performance/
|
126
|
-
documentation_uri: https://docs.rubocop.org/rubocop-performance/1.
|
133
|
+
documentation_uri: https://docs.rubocop.org/rubocop-performance/1.21/
|
127
134
|
bug_tracker_uri: https://github.com/rubocop/rubocop-performance/issues
|
128
135
|
rubygems_mfa_required: 'true'
|
129
136
|
post_install_message:
|
@@ -141,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
148
|
- !ruby/object:Gem::Version
|
142
149
|
version: '0'
|
143
150
|
requirements: []
|
144
|
-
rubygems_version: 3.5.
|
151
|
+
rubygems_version: 3.5.3
|
145
152
|
signing_key:
|
146
153
|
specification_version: 4
|
147
154
|
summary: Automatic performance checking tool for Ruby code.
|