rubocop-rails 2.21.1 → 2.21.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: 15c354794d638a6c49b01b74961ea1d55f5541f3a8b653ef68d9a824e042a100
4
- data.tar.gz: 3a04d9449daac9515b0be93d1394b1aa260748ab6bc57517cf3b90217f58ec88
3
+ metadata.gz: 0e154e69d10b43226db08e454d992d724dc7504d54cac804e597156ee5cf13e5
4
+ data.tar.gz: 60d4697e076620a134f48eff2f81be7b2004fd824796b1a1b15f5822239e3ce3
5
5
  SHA512:
6
- metadata.gz: '01167387c8fcee795769724ded84c4eaa373e2d2d936e8a2b0afd5f4bcb239aafd299b1c302d5a029b7ae72f2990290f2f6de1d317d1cb163f707d5f0ee91635'
7
- data.tar.gz: 61d8f93f138aceb3c8e7a8ef03604d5de870b8328e452d34c03f77612681e9846ac7a4f0ed127a48806bb2bfad055e6ccebe9d3393e82e0f4e01ea88a1d870a6
6
+ metadata.gz: f0aa0f69a7aa3b90d1e402ab26bdf5a4d03680080d9b06ba157cd92f3c5c290f821e81d4a99636009e17ec4ea2de0cfd405cea00134ebccd4323d424fb790ec8
7
+ data.tar.gz: 6b6ddbe47c1b112638cc3693464d9509f589a6683317b0bb30925a27788e39351a3a10853ecf286b419d3ec3b17e13aee9fd09ae07581d209635f0a56a44065b
data/README.md CHANGED
@@ -72,7 +72,9 @@ module YourCoolApp
72
72
  class Application < Rails::Application
73
73
  config.generators.after_generate do |files|
74
74
  parsable_files = files.filter { |file| file.end_with?('.rb') }
75
- system("bundle exec rubocop -A --fail-level=E #{parsable_files.shelljoin}", exception: true)
75
+ unless parsable_files.empty?
76
+ system("bundle exec rubocop -A --fail-level=E #{parsable_files.shelljoin}", exception: true)
77
+ end
76
78
  end
77
79
  end
78
80
  end
data/config/default.yml CHANGED
@@ -801,6 +801,9 @@ Rails/RedundantActiveRecordAllMethod:
801
801
  StyleGuide: 'https://rails.rubystyle.guide/#redundant-all'
802
802
  Enabled: pending
803
803
  Safe: false
804
+ AllowedReceivers:
805
+ - ActionMailer::Preview
806
+ - ActiveSupport::TimeZone
804
807
  VersionAdded: '2.21'
805
808
 
806
809
  Rails/RedundantAllowNil:
@@ -102,7 +102,7 @@ module RuboCop
102
102
  end
103
103
 
104
104
  # Internal helper class to hold match data
105
- Captures = Struct.new(
105
+ Captures = ::Struct.new(
106
106
  :transformed_argname,
107
107
  :transforming_body_expr
108
108
  ) do
@@ -112,7 +112,7 @@ module RuboCop
112
112
  end
113
113
 
114
114
  # Internal helper class to hold autocorrect data
115
- Autocorrection = Struct.new(:match, :block_node, :leading, :trailing) do
115
+ Autocorrection = ::Struct.new(:match, :block_node, :leading, :trailing) do
116
116
  def self.from_each_with_object(node, match)
117
117
  new(match, node, 0, 0)
118
118
  end
@@ -20,8 +20,15 @@ module RuboCop
20
20
  # User.order(:created_at)
21
21
  # users.where(id: ids)
22
22
  # user.articles.order(:created_at)
23
+ #
24
+ # @example AllowedReceivers: ['ActionMailer::Preview', 'ActiveSupport::TimeZone'] (default)
25
+ # # good
26
+ # ActionMailer::Preview.all.first
27
+ # ActiveSupport::TimeZone.all.first
23
28
  class RedundantActiveRecordAllMethod < Base
24
29
  include ActiveRecordHelper
30
+ include AllowedReceivers
31
+ include RangeHelp
25
32
  extend AutoCorrector
26
33
 
27
34
  MSG = 'Redundant `all` detected.'
@@ -126,20 +133,35 @@ module RuboCop
126
133
  without
127
134
  ].to_set.freeze
128
135
 
136
+ POSSIBLE_ENUMERABLE_BLOCK_METHODS = %i[any? count find none? one? select sum].freeze
137
+
129
138
  def_node_matcher :followed_by_query_method?, <<~PATTERN
130
139
  (send (send _ :all) QUERYING_METHODS ...)
131
140
  PATTERN
132
141
 
133
142
  def on_send(node)
134
- return unless followed_by_query_method?(node.parent)
135
- return if node.receiver.nil? && !inherit_active_record_base?(node)
143
+ return if !followed_by_query_method?(node.parent) || possible_enumerable_block_method?(node)
144
+ return if node.receiver ? allowed_receiver?(node.receiver) : !inherit_active_record_base?(node)
136
145
 
137
- range_of_all_method = node.loc.selector
146
+ range_of_all_method = offense_range(node)
138
147
  add_offense(range_of_all_method) do |collector|
139
148
  collector.remove(range_of_all_method)
140
149
  collector.remove(node.parent.loc.dot)
141
150
  end
142
151
  end
152
+
153
+ private
154
+
155
+ def possible_enumerable_block_method?(node)
156
+ parent = node.parent
157
+ return false unless POSSIBLE_ENUMERABLE_BLOCK_METHODS.include?(parent.method_name)
158
+
159
+ parent.parent&.block_type? || parent.parent&.numblock_type? || parent.first_argument&.block_pass_type?
160
+ end
161
+
162
+ def offense_range(node)
163
+ range_between(node.loc.selector.begin_pos, node.source_range.end_pos)
164
+ end
143
165
  end
144
166
  end
145
167
  end
@@ -51,10 +51,13 @@ module RuboCop
51
51
  end
52
52
  end
53
53
 
54
+ # rubocop:disable Metrics/AbcSize
54
55
  def autocorrect(corrector, select_node, node, preferred_method)
55
- corrector.remove(select_node.loc.dot.begin.join(select_node.source_range.end))
56
+ corrector.remove(select_node.loc.dot || node.loc.dot)
57
+ corrector.remove(select_node.loc.selector.begin.join(select_node.source_range.end))
56
58
  corrector.replace(node.loc.selector.begin.join(node.source_range.end), preferred_method)
57
59
  end
60
+ # rubocop:enable Metrics/AbcSize
58
61
 
59
62
  def match_column_name?(select_candidate, column_name)
60
63
  return false unless select_candidate.arguments.one?
@@ -125,7 +125,7 @@ module RuboCop
125
125
 
126
126
  def uniqueness_part(node)
127
127
  pairs = node.arguments.last
128
- return unless pairs.hash_type?
128
+ return unless pairs&.hash_type?
129
129
 
130
130
  pairs.each_pair.find do |pair|
131
131
  next unless pair.key.sym_type? && pair.key.value == :uniqueness
@@ -14,10 +14,9 @@ module RuboCop
14
14
  # render status: 100, plain: 'Ruby!'
15
15
  #
16
16
  # # good
17
- # render status: :continue
18
- # render status: 100
17
+ # head :continue
18
+ # head 100
19
19
  class UnusedRenderContent < Base
20
- extend AutoCorrector
21
20
  include RangeHelp
22
21
 
23
22
  MSG = 'Do not specify body content for a response with a non-content status code'
@@ -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.21.1'
7
+ STRING = '2.21.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.21.1
4
+ version: 2.21.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: 2023-09-14 00:00:00.000000000 Z
13
+ date: 2023-09-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport