rubocop-performance 1.19.0 → 1.19.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: 06f3e8346dc7f9be72a1f18c62a25dc02aeac41debcfe3c58df68e2a6904df43
4
- data.tar.gz: f01facdb92a3056d05990e2ed2b6b1920de0501edf53a08e95e08620651c8557
3
+ metadata.gz: 1fa48a119a4c26e989f4d73366c0cbac4bbe854453a702e49f0af9348b1cf798
4
+ data.tar.gz: e63e391f5f6e2ab2500033cd83df591b9d48254e7f295ce69bbb352e5242c67a
5
5
  SHA512:
6
- metadata.gz: 07eb541698b6ccf2985ef62392bd78703bf6607e2877ef3865ab1762d62910c4c346fbb7e9bc48af7b7d98b0e1ad22e8c79ea2425555fbe75c2a5e614837eaa7
7
- data.tar.gz: 60fc9f900906cca518d0da62170f71ae6e5f5ffd44f4c1cbe75af83f9a1fef252b6bab95d3af4f49f328d4a856cd17c7f47621ee62575ab282eacfd26dc09841
6
+ metadata.gz: 98939001b2b61212c3b4bab44c8b9f9ae8bd906eeb873e2a9516b075f896679fbd513c23c874555982a14d390d265fe01451c218860249ff18376d89f1f59709
7
+ data.tar.gz: ce73767335d2fe19418afa72ca4a8c5c15632960a2d77282b1042c002c65ec1d744af929fc3b612ba5f7c7e7a5cbaa35aab978fcc8a57e7dde02b114c8fc873b
@@ -39,7 +39,7 @@ module RuboCop
39
39
  RESTRICT_ON_SEND = SLICE_METHODS
40
40
 
41
41
  def_node_matcher :endless_range_slice?, <<~PATTERN
42
- (call $_ $%SLICE_METHODS $#endless_range?)
42
+ (call $!{str dstr xstr} $%SLICE_METHODS $#endless_range?)
43
43
  PATTERN
44
44
 
45
45
  def_node_matcher :endless_range?, <<~PATTERN
@@ -47,6 +47,10 @@ module RuboCop
47
47
  corrector.replace(node, block_arg_name)
48
48
  end
49
49
  end
50
+
51
+ def self.autocorrect_incompatible_with
52
+ [Lint::UnusedMethodArgument]
53
+ end
50
54
  end
51
55
  end
52
56
  end
@@ -12,6 +12,12 @@ module RuboCop
12
12
  # @safety
13
13
  # This cop is unsafe because `Range#include?` (or `Range#member?`) and `Range#cover?`
14
14
  # are not equivalent behavior.
15
+ # Example of a case where `Range#cover?` may not provide the desired result:
16
+ #
17
+ # [source,ruby]
18
+ # ----
19
+ # ('a'..'z').cover?('yellow') # => true
20
+ # ----
15
21
  #
16
22
  # @example
17
23
  # # bad
@@ -20,11 +26,6 @@ module RuboCop
20
26
  #
21
27
  # # good
22
28
  # ('a'..'z').cover?('b') # => true
23
- #
24
- # # Example of a case where `Range#cover?` may not provide
25
- # # the desired result:
26
- #
27
- # ('a'..'z').cover?('yellow') # => true
28
29
  class RangeInclude < Base
29
30
  extend AutoCorrector
30
31
 
@@ -23,6 +23,8 @@ module RuboCop
23
23
  MSG = 'Use `=~` in places where the `MatchData` returned by `#match` will not be used.'
24
24
  RESTRICT_ON_SEND = %i[match].freeze
25
25
 
26
+ HIGHER_PRECEDENCE_OPERATOR_METHODS = %i[| ^ & + - * / % ** > >= < <= << >>].freeze
27
+
26
28
  # 'match' is a fairly generic name, so we don't flag it unless we see
27
29
  # a string or regexp literal on one side or the other
28
30
  def_node_matcher :match_call?, <<~PATTERN
@@ -47,7 +49,7 @@ module RuboCop
47
49
  private
48
50
 
49
51
  def autocorrect(corrector, node)
50
- new_source = "#{node.receiver.source} =~ #{node.first_argument.source}"
52
+ new_source = "#{node.receiver.source} =~ #{replacement(node)}"
51
53
 
52
54
  corrector.replace(node, new_source)
53
55
  end
@@ -57,6 +59,33 @@ module RuboCop
57
59
  # register an offense in that case
58
60
  node.receiver.regexp_type? || node.first_argument.regexp_type?
59
61
  end
62
+
63
+ def replacement(node)
64
+ arg = node.first_argument
65
+
66
+ if requires_parentheses?(arg)
67
+ "(#{arg.source})"
68
+ else
69
+ arg.source
70
+ end
71
+ end
72
+
73
+ def requires_parentheses?(arg)
74
+ return true if arg.if_type? && arg.ternary?
75
+ return true if arg.and_type? || arg.or_type? || arg.range_type?
76
+
77
+ call_like?(arg) && requires_parentheses_for_call_like?(arg)
78
+ end
79
+
80
+ def requires_parentheses_for_call_like?(arg)
81
+ return false if arg.parenthesized? || !arg.arguments?
82
+
83
+ !HIGHER_PRECEDENCE_OPERATOR_METHODS.include?(arg.method_name)
84
+ end
85
+
86
+ def call_like?(arg)
87
+ arg.call_type? || arg.yield_type? || arg.super_type?
88
+ end
60
89
  end
61
90
  end
62
91
  end
@@ -26,6 +26,9 @@ module RuboCop
26
26
  # +''
27
27
  class UnfreezeString < Base
28
28
  extend AutoCorrector
29
+ extend TargetRubyVersion
30
+
31
+ minimum_target_ruby_version 2.3
29
32
 
30
33
  MSG = 'Use unary plus to get an unfrozen string literal.'
31
34
  RESTRICT_ON_SEND = %i[dup new].freeze
@@ -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.19.0'
7
+ STRING = '1.19.1'
8
8
 
9
9
  def self.document_version
10
10
  STRING.match('\d+\.\d+').to_s
@@ -9,3 +9,11 @@ require_relative 'rubocop/performance/inject'
9
9
  RuboCop::Performance::Inject.defaults!
10
10
 
11
11
  require_relative 'rubocop/cop/performance_cops'
12
+
13
+ RuboCop::Cop::Lint::UnusedMethodArgument.singleton_class.prepend(
14
+ Module.new do
15
+ def autocorrect_incompatible_with
16
+ super.push(RuboCop::Cop::Performance::BlockGivenWithExplicitBlock)
17
+ end
18
+ end
19
+ )
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.19.0
4
+ version: 1.19.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: 2023-08-13 00:00:00.000000000 Z
13
+ date: 2023-09-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop