rubocop-performance 1.10.0 → 1.10.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c936c552e05f2364a4256d5f0975973ee3a332270bc1af524db3420e9fc70ba5
4
- data.tar.gz: 3cd0086460c2db1c5926caef0737a1d9ae4038808b58b7c91f97e349cfe8f1b6
3
+ metadata.gz: 026fa40bed33c9e7867599f1024ddf6c1ab430b00beae5f5ec52d9b32f5adef9
4
+ data.tar.gz: d0997dd1a5255e217f5faf2adc4f27b64a43266ff24264aa80307b474cbfa936
5
5
  SHA512:
6
- metadata.gz: cdc03f8c28e3ea1f63a8477fe064cf1df766f6334fc017d5f8bc7a830f189ad11c1f5a65a33008469b4fe8438522f64b56e6b026fdadb208abf18181d2a6d261
7
- data.tar.gz: 04034d2353dc721670ac494d40fae7383ba3800923feea6140c8ea9d86ee080028bc8fb05e46deeb475f1365705114d6a3848520e01248076f38f6e4ef18282f
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 {regexp})}
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 unless determinist_regexp?(node.first_argument)
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(node.first_argument) do |corrector|
32
- autocorrect(corrector, node)
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?(first_argument)
39
- DETERMINISTIC_REGEX.match?(first_argument.source)
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(node)
49
- regexp_content = node.first_argument.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 == '\\'
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Performance
5
5
  # This module holds the RuboCop Performance version information.
6
6
  module Version
7
- STRING = '1.10.0'
7
+ STRING = '1.10.1'
8
8
 
9
9
  def self.document_version
10
10
  STRING.match('\d+\.\d+').to_s
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.0
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-02-28 00:00:00.000000000 Z
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.9
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.