rubocop-performance 1.5.0 → 1.5.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 +4 -4
- data/lib/rubocop/cop/performance/caller.rb +1 -1
- data/lib/rubocop/cop/performance/end_with.rb +6 -1
- data/lib/rubocop/cop/performance/redundant_merge.rb +1 -1
- data/lib/rubocop/cop/performance/size.rb +2 -2
- data/lib/rubocop/cop/performance/start_with.rb +6 -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: 55bbd229a457fd01ff1b22b43e644f5399dd97160ae6e4b853ce83bd6ea32359
|
4
|
+
data.tar.gz: 7106cb02fec6940d7d59672b84add493689910ea1046bdc69b93d7db6edbeeb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2840baf60f0906f80aa7a310bee2ac0591eb8763ff938334498d47f52df17782efbdcea0c50479a587a3d5b04f00bb2510c7779577b92a4caa6221944b55d85
|
7
|
+
data.tar.gz: e89228cca25aefdceb216c530e928732d062f47971587e50403a79e67220904ff2b9e3601fbb997f529f1bd5b5fda066e727a4e2428026a44723edb959a3f066
|
@@ -51,7 +51,7 @@ module RuboCop
|
|
51
51
|
caller_arg = node.receiver.first_argument
|
52
52
|
n = caller_arg ? int_value(caller_arg) : 1
|
53
53
|
|
54
|
-
if node.
|
54
|
+
if node.method?(:[])
|
55
55
|
m = int_value(node.first_argument)
|
56
56
|
n += m
|
57
57
|
format(MSG_BRACE, n: n, m: m, method: method_name)
|
@@ -9,8 +9,11 @@ module RuboCop
|
|
9
9
|
# @example
|
10
10
|
# # bad
|
11
11
|
# 'abc'.match?(/bc\Z/)
|
12
|
+
# /bc\Z/.match?('abc')
|
12
13
|
# 'abc' =~ /bc\Z/
|
14
|
+
# /bc\Z/ =~ 'abc'
|
13
15
|
# 'abc'.match(/bc\Z/)
|
16
|
+
# /bc\Z/.match('abc')
|
14
17
|
#
|
15
18
|
# # good
|
16
19
|
# 'abc'.end_with?('bc')
|
@@ -21,7 +24,8 @@ module RuboCop
|
|
21
24
|
|
22
25
|
def_node_matcher :redundant_regex?, <<-PATTERN
|
23
26
|
{(send $!nil? {:match :=~ :match?} (regexp (str $#literal_at_end?) (regopt)))
|
24
|
-
(send (regexp (str $#literal_at_end?) (regopt)) {:match
|
27
|
+
(send (regexp (str $#literal_at_end?) (regopt)) {:match :match?} $_)
|
28
|
+
(match-with-lvasgn (regexp (str $#literal_at_end?) (regopt)) $_)}
|
25
29
|
PATTERN
|
26
30
|
|
27
31
|
def literal_at_end?(regex_str)
|
@@ -36,6 +40,7 @@ module RuboCop
|
|
36
40
|
|
37
41
|
add_offense(node)
|
38
42
|
end
|
43
|
+
alias on_match_with_lvasgn on_send
|
39
44
|
|
40
45
|
def autocorrect(node)
|
41
46
|
redundant_regex?(node) do |receiver, regex_str|
|
@@ -60,7 +60,7 @@ module RuboCop
|
|
60
60
|
|
61
61
|
_, constant = *node.receiver
|
62
62
|
|
63
|
-
constant == :Array || node.
|
63
|
+
constant == :Array || node.method?(:to_a)
|
64
64
|
end
|
65
65
|
|
66
66
|
def hash?(node)
|
@@ -69,7 +69,7 @@ module RuboCop
|
|
69
69
|
|
70
70
|
_, constant = *node.receiver
|
71
71
|
|
72
|
-
constant == :Hash || node.
|
72
|
+
constant == :Hash || node.method?(:to_h)
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
@@ -9,8 +9,11 @@ module RuboCop
|
|
9
9
|
# @example
|
10
10
|
# # bad
|
11
11
|
# 'abc'.match?(/\Aab/)
|
12
|
+
# /\Aab/.match?('abc')
|
12
13
|
# 'abc' =~ /\Aab/
|
14
|
+
# /\Aab/ =~ 'abc'
|
13
15
|
# 'abc'.match(/\Aab/)
|
16
|
+
# /\Aab/.match('abc')
|
14
17
|
#
|
15
18
|
# # good
|
16
19
|
# 'abc'.start_with?('ab')
|
@@ -21,7 +24,8 @@ module RuboCop
|
|
21
24
|
|
22
25
|
def_node_matcher :redundant_regex?, <<-PATTERN
|
23
26
|
{(send $!nil? {:match :=~ :match?} (regexp (str $#literal_at_start?) (regopt)))
|
24
|
-
(send (regexp (str $#literal_at_start?) (regopt)) {:match
|
27
|
+
(send (regexp (str $#literal_at_start?) (regopt)) {:match :match?} $_)
|
28
|
+
(match-with-lvasgn (regexp (str $#literal_at_start?) (regopt)) $_)}
|
25
29
|
PATTERN
|
26
30
|
|
27
31
|
def literal_at_start?(regex_str)
|
@@ -39,6 +43,7 @@ module RuboCop
|
|
39
43
|
|
40
44
|
add_offense(node)
|
41
45
|
end
|
46
|
+
alias on_match_with_lvasgn on_send
|
42
47
|
|
43
48
|
def autocorrect(node)
|
44
49
|
redundant_regex?(node) do |receiver, regex_str|
|
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.5.
|
4
|
+
version: 1.5.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: 2019-
|
13
|
+
date: 2019-11-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '0'
|
109
109
|
requirements: []
|
110
|
-
rubygems_version: 3.0.
|
110
|
+
rubygems_version: 3.0.3
|
111
111
|
signing_key:
|
112
112
|
specification_version: 4
|
113
113
|
summary: Automatic performance checking tool for Ruby code.
|