rubocop-performance 1.10.0 → 1.10.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: 026fa40bed33c9e7867599f1024ddf6c1ab430b00beae5f5ec52d9b32f5adef9
|
4
|
+
data.tar.gz: d0997dd1a5255e217f5faf2adc4f27b64a43266ff24264aa80307b474cbfa936
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a09ace7478bf3d87dc35897bb677c802c6b191ce0206e1b94e04826091ce8075ad9f267cd7805cd68ba3476c679e3cdb59c219fd71760ac4756c26a209c51bc
|
7
|
+
data.tar.gz: f9ccef454d4c9ff9a8d67db5276d2249d03a2882b169abfc5d4bacc28f9f09391edb15100750480c354fe9cc161463156169f216d482c9504f7d6a17da524a0c
|
@@ -32,13 +32,15 @@ module RuboCop
|
|
32
32
|
|
33
33
|
TARGET_METHODS = %i[all? any? one? none?].freeze
|
34
34
|
COMPARISON_METHODS = %i[== === is_a? kind_of?].freeze
|
35
|
+
IS_A_METHODS = %i[is_a? kind_of?].freeze
|
35
36
|
|
36
37
|
def on_block(node)
|
37
|
-
return unless TARGET_METHODS.include?(node.method_name)
|
38
|
+
return unless TARGET_METHODS.include?(node.method_name) && node.arguments.one?
|
38
39
|
|
39
40
|
block_argument = node.arguments.first
|
40
41
|
block_body = node.body
|
41
42
|
return unless use_equality_comparison_block?(block_body)
|
43
|
+
return if same_block_argument_and_is_a_argument?(block_body, block_argument)
|
42
44
|
return unless (new_argument = new_argument(block_argument, block_body))
|
43
45
|
|
44
46
|
range = offense_range(node)
|
@@ -55,6 +57,12 @@ module RuboCop
|
|
55
57
|
block_body.send_type? && COMPARISON_METHODS.include?(block_body.method_name)
|
56
58
|
end
|
57
59
|
|
60
|
+
def same_block_argument_and_is_a_argument?(block_body, block_argument)
|
61
|
+
return false unless IS_A_METHODS.include?(block_body.method_name)
|
62
|
+
|
63
|
+
block_argument.source == block_body.first_argument.source
|
64
|
+
end
|
65
|
+
|
58
66
|
def new_argument(block_argument, block_body)
|
59
67
|
if block_argument.source == block_body.receiver.source
|
60
68
|
block_body.first_argument.source
|
@@ -21,32 +21,29 @@ module RuboCop
|
|
21
21
|
STR_SPECIAL_CHARS = %w[\n \" \' \\\\ \t \b \f \r].freeze
|
22
22
|
|
23
23
|
def_node_matcher :split_call_with_regexp?, <<~PATTERN
|
24
|
-
{(send !nil? :split
|
24
|
+
{(send !nil? :split $regexp)}
|
25
25
|
PATTERN
|
26
26
|
|
27
27
|
def on_send(node)
|
28
|
-
return unless split_call_with_regexp?(node)
|
29
|
-
return
|
28
|
+
return unless (regexp_node = split_call_with_regexp?(node))
|
29
|
+
return if regexp_node.ignore_case?
|
30
|
+
return unless determinist_regexp?(regexp_node)
|
30
31
|
|
31
|
-
add_offense(
|
32
|
-
|
32
|
+
add_offense(regexp_node) do |corrector|
|
33
|
+
new_argument = replacement(regexp_node)
|
34
|
+
|
35
|
+
corrector.replace(regexp_node, "\"#{new_argument}\"")
|
33
36
|
end
|
34
37
|
end
|
35
38
|
|
36
39
|
private
|
37
40
|
|
38
|
-
def determinist_regexp?(
|
39
|
-
DETERMINISTIC_REGEX.match?(
|
40
|
-
end
|
41
|
-
|
42
|
-
def autocorrect(corrector, node)
|
43
|
-
new_argument = replacement(node)
|
44
|
-
|
45
|
-
corrector.replace(node.first_argument, "\"#{new_argument}\"")
|
41
|
+
def determinist_regexp?(regexp_node)
|
42
|
+
DETERMINISTIC_REGEX.match?(regexp_node.source)
|
46
43
|
end
|
47
44
|
|
48
|
-
def replacement(
|
49
|
-
regexp_content =
|
45
|
+
def replacement(regexp_node)
|
46
|
+
regexp_content = regexp_node.content
|
50
47
|
stack = []
|
51
48
|
chars = regexp_content.chars.each_with_object([]) do |char, strings|
|
52
49
|
if stack.empty? && char == '\\'
|
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.10.
|
4
|
+
version: 1.10.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: 2021-
|
13
|
+
date: 2021-03-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
135
|
- !ruby/object:Gem::Version
|
136
136
|
version: '0'
|
137
137
|
requirements: []
|
138
|
-
rubygems_version: 3.2.
|
138
|
+
rubygems_version: 3.2.12
|
139
139
|
signing_key:
|
140
140
|
specification_version: 4
|
141
141
|
summary: Automatic performance checking tool for Ruby code.
|