rubocop-rails 2.15.1 → 2.15.2

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: 9dc39965bea5c1a04b65aed496d749cc59a8ed9eeccef6d010ff8ce1970dabb9
4
- data.tar.gz: f827dd6365f66a1464ae9433985960a99a90a8ba35b1b7c683c9dc3d7a0209ce
3
+ metadata.gz: 169ed04b1f5378e9e08fbffdca151afaf4b84fd54b1867a173740aadaede60b3
4
+ data.tar.gz: 1a2ac75c313cfcdeec1814d7e3aff4777c5013527d2cf4a2aa4f95aeb45446bf
5
5
  SHA512:
6
- metadata.gz: eea7efbff824ab7a3bdae13bdbbdb2c33b4cd04ba74c2f9a7f89971ddf2da0d7a3f68a4508e9ca81314425fe9ba593f6675e014a5b385923e3790a7357bba6f5
7
- data.tar.gz: 28990bc579868dcd5ce06332558f1bd5bb97ae13895bdf690b46650e86f7e4cf37e1d64e5a18c681f3cfa17347c338f30511b1d34788617bbaf311c5fea37126
6
+ metadata.gz: 51d495edd3e825db49ece8f51bfc118c73887681f414b86d31cd47d85dc5a1a22a385a2a17ed4ebf7d1c6332989795e2cde999a364d911c60f452993dc926c4b
7
+ data.tar.gz: 4546785b39af93e6c7fe5a6a3b637fa5c21d4b358c38ea8ad3ebd5c272d1d0a504e8206e8201cfe3771af9199c336649d033e32b324f16b06fc7d150054dc488
data/config/default.yml CHANGED
@@ -367,6 +367,7 @@ Rails/Exit:
367
367
 
368
368
  Rails/ExpandedDateRange:
369
369
  Description: 'Checks for expanded date range.'
370
+ StyleGuide: 'https://rails.rubystyle.guide/#date-time-range'
370
371
  Enabled: pending
371
372
  VersionAdded: '2.11'
372
373
 
@@ -54,6 +54,7 @@ module RuboCop
54
54
  # delegate :bar, to: :foo, prefix: true
55
55
  class Delegate < Base
56
56
  extend AutoCorrector
57
+ include VisibilityHelp
57
58
 
58
59
  MSG = 'Use `delegate` to define delegations.'
59
60
 
@@ -112,17 +113,11 @@ module RuboCop
112
113
  end
113
114
 
114
115
  def private_or_protected_delegation(node)
115
- line = node.first_line
116
- private_or_protected_before(line) ||
117
- private_or_protected_inline(line)
116
+ private_or_protected_inline(node) || node_visibility(node) != :public
118
117
  end
119
118
 
120
- def private_or_protected_before(line)
121
- (processed_source[0..line].map(&:strip) & %w[private protected]).any?
122
- end
123
-
124
- def private_or_protected_inline(line)
125
- processed_source[line - 1].strip.match?(/\A(private )|(protected )/)
119
+ def private_or_protected_inline(node)
120
+ processed_source[node.first_line - 1].strip.match?(/\A(private )|(protected )/)
126
121
  end
127
122
  end
128
123
  end
@@ -106,6 +106,8 @@ module RuboCop
106
106
 
107
107
  def on_send(node)
108
108
  any_manipulation?(node) do
109
+ next if node.method?(:keys) && target_rails_version <= 6.0
110
+
109
111
  add_offense(node) do |corrector|
110
112
  next unless AUTOCORECTABLE_METHODS.include?(node.method_name)
111
113
 
@@ -29,14 +29,6 @@ module RuboCop
29
29
 
30
30
  minimum_target_rails_version 5.1
31
31
 
32
- def_node_matcher :expanded_date_range, <<~PATTERN
33
- (irange
34
- (send
35
- $_ {:beginning_of_day :beginning_of_week :beginning_of_month :beginning_of_quarter :beginning_of_year})
36
- (send
37
- $_ {:end_of_day :end_of_week :end_of_month :end_of_quarter :end_of_year}))
38
- PATTERN
39
-
40
32
  PREFERRED_METHODS = {
41
33
  beginning_of_day: 'all_day',
42
34
  beginning_of_week: 'all_week',
@@ -54,31 +46,55 @@ module RuboCop
54
46
  }.freeze
55
47
 
56
48
  def on_irange(node)
57
- return unless expanded_date_range(node)
58
-
59
49
  begin_node = node.begin
60
50
  end_node = node.end
61
- return unless same_receiver?(begin_node, end_node)
62
-
63
- beginning_method = begin_node.method_name
64
- end_method = end_node.method_name
65
- return unless use_mapped_methods?(beginning_method, end_method)
51
+ return if allow?(begin_node, end_node)
66
52
 
67
- preferred_method = "#{begin_node.receiver.source}.#{PREFERRED_METHODS[beginning_method]}"
53
+ preferred_method = preferred_method(begin_node)
54
+ if begin_node.method?(:beginning_of_week) && begin_node.arguments.one?
55
+ return unless same_argument?(begin_node, end_node)
68
56
 
69
- add_offense(node, message: format(MSG, preferred_method: preferred_method)) do |corrector|
70
- corrector.replace(node, preferred_method)
57
+ preferred_method << "(#{begin_node.first_argument.source})"
58
+ elsif any_arguments?(begin_node, end_node)
59
+ return
71
60
  end
61
+
62
+ register_offense(node, preferred_method)
72
63
  end
73
64
 
74
65
  private
75
66
 
76
- def same_receiver?(begin_node, end_node)
77
- begin_node.receiver.source == end_node.receiver.source
67
+ def allow?(begin_node, end_node)
68
+ return true unless (begin_source = receiver_source(begin_node))
69
+ return true unless (end_source = receiver_source(end_node))
70
+
71
+ begin_source != end_source || MAPPED_DATE_RANGE_METHODS[begin_node.method_name] != end_node.method_name
72
+ end
73
+
74
+ def receiver_source(node)
75
+ return if !node&.send_type? || node.receiver.nil?
76
+
77
+ node.receiver.source
78
78
  end
79
79
 
80
- def use_mapped_methods?(beginning_method, end_method)
81
- MAPPED_DATE_RANGE_METHODS[beginning_method] == end_method
80
+ def same_argument?(begin_node, end_node)
81
+ begin_node.first_argument.source == end_node.first_argument.source
82
+ end
83
+
84
+ def preferred_method(begin_node)
85
+ +"#{begin_node.receiver.source}.#{PREFERRED_METHODS[begin_node.method_name]}"
86
+ end
87
+
88
+ def any_arguments?(begin_node, end_node)
89
+ begin_node.arguments.any? || end_node.arguments.any?
90
+ end
91
+
92
+ def register_offense(node, preferred_method)
93
+ message = format(MSG, preferred_method: preferred_method)
94
+
95
+ add_offense(node, message: message) do |corrector|
96
+ corrector.replace(node, preferred_method)
97
+ end
82
98
  end
83
99
  end
84
100
  end
@@ -43,7 +43,7 @@ module RuboCop
43
43
 
44
44
  def register_offense(node, heredoc)
45
45
  add_offense(node) do |corrector|
46
- squiggly_heredoc = heredoc.source.sub(/\A<<-?/, '<<~')
46
+ squiggly_heredoc = heredoc.source.sub(/\A<<(-|~)?/, '<<~')
47
47
 
48
48
  corrector.replace(heredoc, squiggly_heredoc)
49
49
  corrector.remove(node.loc.dot)
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Rails
5
5
  # This module holds the RuboCop Rails version information.
6
6
  module Version
7
- STRING = '2.15.1'
7
+ STRING = '2.15.2'
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-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.15.1
4
+ version: 2.15.2
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: 2022-06-26 00:00:00.000000000 Z
13
+ date: 2022-07-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -227,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
227
227
  - !ruby/object:Gem::Version
228
228
  version: '0'
229
229
  requirements: []
230
- rubygems_version: 3.4.0.dev
230
+ rubygems_version: 3.1.6
231
231
  signing_key:
232
232
  specification_version: 4
233
233
  summary: Automatic Rails code style checking tool.