rubocop-performance 1.9.0 → 1.9.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c90f0ddd451c37a5c2187423524462aaa583fc0a7d4fb0342077eb792f03bfcc
|
4
|
+
data.tar.gz: 7606efa668ec94c24a35b93df1062a5a6f39e8c787e013d2707f69448841b7e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2a0094a2edfa59ee9a517cbf5d71ae1fa0fc67042bf0c35b129872a1b6cb6f892c182a0777da2a4e34f1a4c4b4292c30d19a34083b65844802e75b021f75322
|
7
|
+
data.tar.gz: e24dab2beb33688d61cf110a748d5295921c185324df366c0e02478ff44c34acb0857d8b603ca308021c7eaaf6e13d9ecbaeda1f80572b180d499c1b4e5fec5d
|
data/config/default.yml
CHANGED
@@ -9,7 +9,11 @@ Performance/AncestorsInclude:
|
|
9
9
|
|
10
10
|
Performance/ArraySemiInfiniteRangeSlice:
|
11
11
|
Description: 'Identifies places where slicing arrays with semi-infinite ranges can be replaced by `Array#take` and `Array#drop`.'
|
12
|
-
|
12
|
+
# This cop was created due to a mistake in microbenchmark.
|
13
|
+
# Refer https://github.com/rubocop-hq/rubocop-performance/pull/175#issuecomment-731892717
|
14
|
+
Enabled: false
|
15
|
+
# Unsafe for string slices because strings do not have `#take` and `#drop` methods.
|
16
|
+
Safe: false
|
13
17
|
VersionAdded: '1.9'
|
14
18
|
|
15
19
|
Performance/BigDecimalWithNumericArgument:
|
@@ -5,6 +5,9 @@ module RuboCop
|
|
5
5
|
module Performance
|
6
6
|
# This cop identifies places where slicing arrays with semi-infinite ranges
|
7
7
|
# can be replaced by `Array#take` and `Array#drop`.
|
8
|
+
# This cop was created due to a mistake in microbenchmark and hence is disabled by default.
|
9
|
+
# Refer https://github.com/rubocop-hq/rubocop-performance/pull/175#issuecomment-731892717
|
10
|
+
# This cop is also unsafe for string slices because strings do not have `#take` and `#drop` methods.
|
8
11
|
#
|
9
12
|
# @example
|
10
13
|
# # bad
|
@@ -29,38 +29,40 @@ module RuboCop
|
|
29
29
|
# [1,2].first # => 1
|
30
30
|
# [1,2].first(1) # => [1]
|
31
31
|
#
|
32
|
-
RETURN_NEW_ARRAY_WHEN_ARGS =
|
32
|
+
RETURN_NEW_ARRAY_WHEN_ARGS = %i[first last pop sample shift].to_set.freeze
|
33
33
|
|
34
34
|
# These methods return a new array only when called without a block.
|
35
|
-
RETURNS_NEW_ARRAY_WHEN_NO_BLOCK =
|
35
|
+
RETURNS_NEW_ARRAY_WHEN_NO_BLOCK = %i[zip product].to_set.freeze
|
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
|
39
|
-
ALWAYS_RETURNS_NEW_ARRAY =
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
39
|
+
ALWAYS_RETURNS_NEW_ARRAY = %i[* + - collect compact drop
|
40
|
+
drop_while flatten map reject
|
41
|
+
reverse rotate select shuffle sort
|
42
|
+
take take_while transpose uniq
|
43
|
+
values_at |].to_set.freeze
|
44
44
|
|
45
45
|
# These methods have a mutation alternative. For example :collect
|
46
46
|
# can be called as :collect!
|
47
|
-
HAS_MUTATION_ALTERNATIVE =
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
HAS_MUTATION_ALTERNATIVE = %i[collect compact flatten map reject
|
48
|
+
reverse rotate select shuffle sort uniq].to_set.freeze
|
49
|
+
|
50
|
+
RETURNS_NEW_ARRAY = (ALWAYS_RETURNS_NEW_ARRAY + RETURNS_NEW_ARRAY_WHEN_NO_BLOCK).freeze
|
51
|
+
|
52
|
+
MSG = 'Use unchained `%<method>s` and `%<second_method>s!` '\
|
51
53
|
'(followed by `return array` if required) instead of chaining '\
|
52
54
|
'`%<method>s...%<second_method>s`.'
|
53
55
|
|
54
|
-
def_node_matcher :
|
55
|
-
{
|
56
|
-
(send
|
57
|
-
(
|
58
|
-
(send
|
59
|
-
}
|
56
|
+
def_node_matcher :chain_array_allocation?, <<~PATTERN
|
57
|
+
(send {
|
58
|
+
(send _ $%RETURN_NEW_ARRAY_WHEN_ARGS {int lvar ivar cvar gvar})
|
59
|
+
(block (send _ $%ALWAYS_RETURNS_NEW_ARRAY) ...)
|
60
|
+
(send _ $%RETURNS_NEW_ARRAY ...)
|
61
|
+
} $%HAS_MUTATION_ALTERNATIVE ...)
|
60
62
|
PATTERN
|
61
63
|
|
62
64
|
def on_send(node)
|
63
|
-
|
65
|
+
chain_array_allocation?(node) do |fm, sm|
|
64
66
|
range = range_between(node.loc.dot.begin_pos, node.source_range.end_pos)
|
65
67
|
|
66
68
|
add_offense(range, message: format(MSG, method: fm, second_method: sm))
|
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.9.
|
4
|
+
version: 1.9.1
|
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: 2020-11-
|
13
|
+
date: 2020-11-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|