rubocop-performance 1.20.2 → 1.21.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/config/default.yml +2 -1
- 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/end_with.rb +2 -1
- data/lib/rubocop/cop/performance/map_compact.rb +3 -2
- 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/regexp_match.rb +1 -8
- data/lib/rubocop/cop/performance/start_with.rb +2 -1
- data/lib/rubocop/cop/performance/string_include.rb +2 -1
- data/lib/rubocop/performance/version.rb +1 -1
- metadata +6 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd286ebd5cb0d982f759a355a86281898577db559004bef9bfb53b8493a32934
|
4
|
+
data.tar.gz: f3e101a14918c3efa6dc657841471b22afec47d54ce70442567d54ffc3ee8ed5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d6df8e36cbb224d892f14e7fb1eeccf34c887c9fd6e9ad302889ab71b64e48db3c3167291f210ad7e69a23f5e4720ae23ee767c4a569701d09e8fa771ede28c
|
7
|
+
data.tar.gz: 428da3a79195bcf8c715a1962c5bea38a08ee2973c0450b78fc24ceeb376a4f984b3d4f91efba93c799d28986dda22f711e90937738007abbd41b470a484a887
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# RuboCop Performance
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/rubocop-performance.svg)](https://badge.fury.io/rb/rubocop-performance)
|
4
|
-
[![
|
4
|
+
[![CI](https://github.com/rubocop/rubocop-performance/actions/workflows/test.yml/badge.svg)](https://github.com/rubocop/rubocop-performance/actions/workflows/test.yml)
|
5
5
|
[![Discord](https://img.shields.io/badge/chat-on%20discord-7289da.svg?sanitize=true)](https://discord.gg/wJjWvGRDmm)
|
6
6
|
|
7
7
|
Performance optimization analysis for your projects, as an extension to [RuboCop](https://github.com/rubocop/rubocop).
|
data/config/default.yml
CHANGED
@@ -55,9 +55,10 @@ Performance/Casecmp:
|
|
55
55
|
Description: >-
|
56
56
|
Use `casecmp` rather than `downcase ==`, `upcase ==`, `== downcase`, or `== upcase`..
|
57
57
|
Reference: 'https://github.com/fastruby/fast-ruby#stringcasecmp-vs--stringcasecmp-vs-stringdowncase---code'
|
58
|
-
Enabled:
|
58
|
+
Enabled: false
|
59
59
|
Safe: false
|
60
60
|
VersionAdded: '0.36'
|
61
|
+
VersionChanged: '1.21'
|
61
62
|
|
62
63
|
Performance/ChainArrayAllocation:
|
63
64
|
Description: >-
|
@@ -6,6 +6,12 @@ module RuboCop
|
|
6
6
|
# Identifies places where a case-insensitive string comparison
|
7
7
|
# can better be implemented using `casecmp`.
|
8
8
|
#
|
9
|
+
# This cop is disabled by default because `String#casecmp` only works with
|
10
|
+
# ASCII characters. See https://github.com/rubocop/rubocop/issues/9753.
|
11
|
+
#
|
12
|
+
# If you are working only with ASCII characters, then this cop can be
|
13
|
+
# safely enabled.
|
14
|
+
#
|
9
15
|
# @safety
|
10
16
|
# This cop is unsafe because `String#casecmp` and `String#casecmp?` behave
|
11
17
|
# differently when using Non-ASCII characters.
|
@@ -19,8 +19,6 @@ module RuboCop
|
|
19
19
|
# array.map! { |x| x.downcase }
|
20
20
|
# array
|
21
21
|
class ChainArrayAllocation < Base
|
22
|
-
include RangeHelp
|
23
|
-
|
24
22
|
# These methods return a new array but only sometimes. They must be
|
25
23
|
# called with an argument. For example:
|
26
24
|
#
|
@@ -54,7 +52,7 @@ module RuboCop
|
|
54
52
|
def_node_matcher :chain_array_allocation?, <<~PATTERN
|
55
53
|
(send {
|
56
54
|
(send _ $%RETURN_NEW_ARRAY_WHEN_ARGS {int lvar ivar cvar gvar send})
|
57
|
-
(block (send _ $%ALWAYS_RETURNS_NEW_ARRAY) ...)
|
55
|
+
({block numblock} (send _ $%ALWAYS_RETURNS_NEW_ARRAY) ...)
|
58
56
|
(send _ $%RETURNS_NEW_ARRAY ...)
|
59
57
|
} $%HAS_MUTATION_ALTERNATIVE ...)
|
60
58
|
PATTERN
|
@@ -62,12 +60,21 @@ module RuboCop
|
|
62
60
|
def on_send(node)
|
63
61
|
chain_array_allocation?(node) do |fm, sm|
|
64
62
|
return if node.each_descendant(:send).any? { |descendant| descendant.method?(:lazy) }
|
63
|
+
return if node.method?(:select) && !enumerable_select_method?(node.receiver)
|
65
64
|
|
66
|
-
range =
|
65
|
+
range = node.loc.selector.begin.join(node.source_range.end)
|
67
66
|
|
68
67
|
add_offense(range, message: format(MSG, method: fm, second_method: sm))
|
69
68
|
end
|
70
69
|
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def enumerable_select_method?(node)
|
74
|
+
# NOTE: `QueryMethods#select` in Rails accepts positional arguments, whereas `Enumerable#select` does not.
|
75
|
+
# This difference can be utilized to reduce the knowledge requirements related to `select`.
|
76
|
+
(node.block_type? || node.numblock_type?) && node.send_node.arguments.empty?
|
77
|
+
end
|
71
78
|
end
|
72
79
|
end
|
73
80
|
end
|
@@ -56,7 +56,8 @@ module RuboCop
|
|
56
56
|
def_node_matcher :redundant_regex?, <<~PATTERN
|
57
57
|
{(call $!nil? {:match :=~ :match?} (regexp (str $#literal_at_end?) (regopt)))
|
58
58
|
(send (regexp (str $#literal_at_end?) (regopt)) {:match :match?} $_)
|
59
|
-
(match-with-lvasgn (regexp (str $#literal_at_end?) (regopt)) $_)
|
59
|
+
({send match-with-lvasgn} (regexp (str $#literal_at_end?) (regopt)) $_)
|
60
|
+
(send (regexp (str $#literal_at_end?) (regopt)) :=~ $_)}
|
60
61
|
PATTERN
|
61
62
|
|
62
63
|
def on_send(node)
|
@@ -8,8 +8,9 @@ module RuboCop
|
|
8
8
|
# This cop identifies places where `map { ... }.compact` can be replaced by `filter_map`.
|
9
9
|
#
|
10
10
|
# @safety
|
11
|
-
# This cop's autocorrection is unsafe because `map { ... }.compact`
|
12
|
-
#
|
11
|
+
# This cop's autocorrection is unsafe because `map { ... }.compact` might yield
|
12
|
+
# different results than `filter_map`. As illustrated in the example, `filter_map`
|
13
|
+
# also filters out falsy values, while `compact` only gets rid of `nil`.
|
13
14
|
#
|
14
15
|
# [source,ruby]
|
15
16
|
# ----
|
@@ -64,7 +64,7 @@ module RuboCop
|
|
64
64
|
return unless one_block_argument?(node.arguments)
|
65
65
|
|
66
66
|
block_argument = node.first_argument
|
67
|
-
block_body = node.body
|
67
|
+
return unless (block_body = node.body)
|
68
68
|
return unless use_equality_comparison_block?(block_body)
|
69
69
|
return if same_block_argument_and_is_a_argument?(block_body, block_argument)
|
70
70
|
return unless (new_argument = new_argument(block_argument, block_body))
|
@@ -248,7 +248,7 @@ module RuboCop
|
|
248
248
|
end
|
249
249
|
|
250
250
|
def correct_operator(corrector, recv, arg, oper = nil)
|
251
|
-
op_range =
|
251
|
+
op_range = recv.source_range.end.join(arg.source_range.begin)
|
252
252
|
|
253
253
|
replace_with_match_predicate_method(corrector, recv, arg, op_range)
|
254
254
|
|
@@ -271,13 +271,6 @@ module RuboCop
|
|
271
271
|
corrector.replace(recv, arg.source)
|
272
272
|
corrector.replace(arg, recv.source)
|
273
273
|
end
|
274
|
-
|
275
|
-
def correction_range(recv, arg)
|
276
|
-
buffer = processed_source.buffer
|
277
|
-
op_begin_pos = recv.source_range.end_pos
|
278
|
-
op_end_pos = arg.source_range.begin_pos
|
279
|
-
Parser::Source::Range.new(buffer, op_begin_pos, op_end_pos)
|
280
|
-
end
|
281
274
|
end
|
282
275
|
end
|
283
276
|
end
|
@@ -56,7 +56,8 @@ module RuboCop
|
|
56
56
|
def_node_matcher :redundant_regex?, <<~PATTERN
|
57
57
|
{(call $!nil? {:match :=~ :match?} (regexp (str $#literal_at_start?) (regopt)))
|
58
58
|
(send (regexp (str $#literal_at_start?) (regopt)) {:match :match?} $_)
|
59
|
-
(match-with-lvasgn (regexp (str $#literal_at_start?) (regopt)) $_)
|
59
|
+
(match-with-lvasgn (regexp (str $#literal_at_start?) (regopt)) $_)
|
60
|
+
(send (regexp (str $#literal_at_start?) (regopt)) :=~ $_)}
|
60
61
|
PATTERN
|
61
62
|
|
62
63
|
def on_send(node)
|
@@ -29,7 +29,8 @@ module RuboCop
|
|
29
29
|
def_node_matcher :redundant_regex?, <<~PATTERN
|
30
30
|
{(call $!nil? {:match :=~ :!~ :match?} (regexp (str $#literal?) (regopt)))
|
31
31
|
(send (regexp (str $#literal?) (regopt)) {:match :match? :===} $_)
|
32
|
-
(match-with-lvasgn (regexp (str $#literal?) (regopt)) $_)
|
32
|
+
(match-with-lvasgn (regexp (str $#literal?) (regopt)) $_)
|
33
|
+
(send (regexp (str $#literal?) (regopt)) :=~ $_)}
|
33
34
|
PATTERN
|
34
35
|
|
35
36
|
# rubocop:disable Metrics/AbcSize
|
metadata
CHANGED
@@ -1,16 +1,15 @@
|
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
8
8
|
- Jonas Arvidsson
|
9
9
|
- Yuji Nakayama
|
10
|
-
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date: 2024-
|
12
|
+
date: 2024-06-16 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: rubocop
|
@@ -38,7 +37,7 @@ dependencies:
|
|
38
37
|
requirements:
|
39
38
|
- - ">="
|
40
39
|
- !ruby/object:Gem::Version
|
41
|
-
version: 1.
|
40
|
+
version: 1.31.1
|
42
41
|
- - "<"
|
43
42
|
- !ruby/object:Gem::Version
|
44
43
|
version: '2.0'
|
@@ -48,7 +47,7 @@ dependencies:
|
|
48
47
|
requirements:
|
49
48
|
- - ">="
|
50
49
|
- !ruby/object:Gem::Version
|
51
|
-
version: 1.
|
50
|
+
version: 1.31.1
|
52
51
|
- - "<"
|
53
52
|
- !ruby/object:Gem::Version
|
54
53
|
version: '2.0'
|
@@ -130,10 +129,9 @@ metadata:
|
|
130
129
|
homepage_uri: https://docs.rubocop.org/rubocop-performance/
|
131
130
|
changelog_uri: https://github.com/rubocop/rubocop-performance/blob/master/CHANGELOG.md
|
132
131
|
source_code_uri: https://github.com/rubocop/rubocop-performance/
|
133
|
-
documentation_uri: https://docs.rubocop.org/rubocop-performance/1.
|
132
|
+
documentation_uri: https://docs.rubocop.org/rubocop-performance/1.21/
|
134
133
|
bug_tracker_uri: https://github.com/rubocop/rubocop-performance/issues
|
135
134
|
rubygems_mfa_required: 'true'
|
136
|
-
post_install_message:
|
137
135
|
rdoc_options: []
|
138
136
|
require_paths:
|
139
137
|
- lib
|
@@ -148,8 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
146
|
- !ruby/object:Gem::Version
|
149
147
|
version: '0'
|
150
148
|
requirements: []
|
151
|
-
rubygems_version: 3.
|
152
|
-
signing_key:
|
149
|
+
rubygems_version: 3.6.0.dev
|
153
150
|
specification_version: 4
|
154
151
|
summary: Automatic performance checking tool for Ruby code.
|
155
152
|
test_files: []
|