rubocop-rails 2.12.0 → 2.12.4

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: 547615c004c88ace5079ff3c4c0da33bbc3a6187b963baaf82ba34ee9a068224
4
- data.tar.gz: b7b09ff7ab96257ea329a393158c656f2d92fa3e3528916dc4bd3664f2341f90
3
+ metadata.gz: 7c247cc795386a013c8f1a9dd7a76a08ef8fbd3c729ebe69e2f99bcb28a7baf6
4
+ data.tar.gz: f85139a9ef4a5f1666672431285e6d34ca9a8c0a367bf6c1e2b8ed2d3d0acf63
5
5
  SHA512:
6
- metadata.gz: 97f42ef251a1f3bcb91d0e08e3b89fb480a6555aa8f13266c57d0bf6b8319e35b4d200b8c4d2f407c303b8b8bbf72dc354a259688e27f032e625516683f1aafc
7
- data.tar.gz: c9b8d93ad9c39f1903c2424c0e0e284281e7effe0373fbcfe8e3138b2dd659122fb69cb658b9560f4af8a94cd332ad80066b3617339a21ae24de47cf2987f2c6
6
+ metadata.gz: cd4893d903809e187a9094f84a14209aecfc931e4773df64e1c5a05c94fce22305ca0b0c899881545e697ceae8c6facb3400d0dc41415fed57a3b07244b7fdff
7
+ data.tar.gz: 91832638f61072047b0cf11b300d7be679a8fc7f708dc47cb5769eb1cd7852c8caf70452d6297cca122af4a53fd0599605d7221a8fc647e96352934fb0828684
data/config/default.yml CHANGED
@@ -9,7 +9,7 @@ AllCops:
9
9
  - bin/*
10
10
  - db/schema.rb
11
11
  # What version of Rails is the inspected code using? If a value is specified
12
- # for TargetRailsVersion then it is used. Acceptable values are specificed
12
+ # for TargetRailsVersion then it is used. Acceptable values are specified
13
13
  # as a float (i.e. 5.1); the patch version of Rails should not be included.
14
14
  # If TargetRailsVersion is not set, RuboCop will parse the Gemfile.lock or
15
15
  # gems.locked file to find the version of Rails that has been bound to the
@@ -189,6 +189,9 @@ Rails/ContentTag:
189
189
  Enabled: true
190
190
  VersionAdded: '2.6'
191
191
  VersionChanged: '2.12'
192
+ # This `Exclude` config prevents false positives for `tag` calls to `has_one: tag`. No helpers are used in normal models.
193
+ Exclude:
194
+ - app/models/**/*.rb
192
195
 
193
196
  Rails/CreateTableWithTimestamps:
194
197
  Description: >-
@@ -198,6 +201,10 @@ Rails/CreateTableWithTimestamps:
198
201
  VersionAdded: '0.52'
199
202
  Include:
200
203
  - db/migrate/*.rb
204
+ Exclude:
205
+ # Respect the `active_storage_variant_records` table of `*_create_active_storage_tables.active_storage.rb`
206
+ # auto-generated by `bin/rails active_storage:install` even if `created_at` is not specified.
207
+ - db/migrate/*_create_active_storage_tables.active_storage.rb
201
208
 
202
209
  Rails/Date:
203
210
  Description: >-
@@ -816,7 +823,7 @@ Rails/UniqBeforePluck:
816
823
  AutoCorrect: false
817
824
 
818
825
  Rails/UniqueValidationWithoutIndex:
819
- Description: 'Uniqueness validation should be with a unique index.'
826
+ Description: 'Uniqueness validation should have a unique index on the database column.'
820
827
  Enabled: true
821
828
  VersionAdded: '2.5'
822
829
  Include:
@@ -8,10 +8,10 @@ module RuboCop
8
8
  #
9
9
  # @example
10
10
  # #bad
11
- # Book.update_attributes!(author: 'Alice')
11
+ # book.update_attributes!(author: 'Alice')
12
12
  #
13
13
  # #good
14
- # Book.update!(author: 'Alice')
14
+ # book.update!(author: 'Alice')
15
15
  class ActiveRecordAliases < Base
16
16
  extend AutoCorrector
17
17
 
@@ -33,6 +33,9 @@ module RuboCop
33
33
  end
34
34
 
35
35
  def on_send(node)
36
+ return unless node.receiver.nil?
37
+ return if node.arguments.count >= 3
38
+
36
39
  first_argument = node.first_argument
37
40
  return if !first_argument ||
38
41
  allowed_argument?(first_argument) ||
@@ -41,12 +44,7 @@ module RuboCop
41
44
  preferred_method = node.first_argument.value.to_s.underscore
42
45
  message = format(MSG, preferred_method: preferred_method, current_argument: first_argument.source)
43
46
 
44
- add_offense(node, message: message) do |corrector|
45
- autocorrect(corrector, node, preferred_method)
46
-
47
- @corrected_nodes ||= Set.new.compare_by_identity
48
- @corrected_nodes.add(node)
49
- end
47
+ register_offense(node, message, preferred_method)
50
48
  end
51
49
 
52
50
  private
@@ -63,6 +61,15 @@ module RuboCop
63
61
  allowed_name?(argument)
64
62
  end
65
63
 
64
+ def register_offense(node, message, preferred_method)
65
+ add_offense(node, message: message) do |corrector|
66
+ autocorrect(corrector, node, preferred_method)
67
+
68
+ @corrected_nodes ||= Set.new.compare_by_identity
69
+ @corrected_nodes.add(node)
70
+ end
71
+ end
72
+
66
73
  def autocorrect(corrector, node, preferred_method)
67
74
  range = correction_range(node)
68
75
 
@@ -43,9 +43,22 @@ module RuboCop
43
43
  private
44
44
 
45
45
  def ignored?(node)
46
+ return true if active_model_error_where?(node.receiver)
47
+
46
48
  method_chain = node.each_node(:send).map(&:method_name)
49
+
47
50
  (cop_config['IgnoredMethods'].map(&:to_sym) & method_chain).any?
48
51
  end
52
+
53
+ def active_model_error_where?(node)
54
+ node.method?(:where) && active_model_error?(node.receiver)
55
+ end
56
+
57
+ def active_model_error?(node)
58
+ return false if node.nil?
59
+
60
+ node.send_type? && node.method?(:errors)
61
+ end
49
62
  end
50
63
  end
51
64
  end
@@ -45,7 +45,7 @@ module RuboCop
45
45
  PATTERN
46
46
 
47
47
  def_node_matcher :association_with_options?, <<~PATTERN
48
- (send nil? {:has_many :has_one} _ (hash $...))
48
+ (send nil? {:has_many :has_one} ... (hash $...))
49
49
  PATTERN
50
50
 
51
51
  def_node_matcher :dependent_option?, <<~PATTERN
@@ -100,8 +100,8 @@ module RuboCop
100
100
  end
101
101
 
102
102
  def contain_valid_options_in_with_options_block?(node)
103
- if with_options_block(node)
104
- return true if valid_options?(with_options_block(node))
103
+ if (options = with_options_block(node))
104
+ return true if valid_options?(options)
105
105
 
106
106
  return false unless node.parent
107
107
 
@@ -114,6 +114,8 @@ module RuboCop
114
114
  end
115
115
 
116
116
  def valid_options?(options)
117
+ return false if options.nil?
118
+
117
119
  options = options.first.children.first.pairs if options.first.kwsplat_type?
118
120
 
119
121
  return true unless options
@@ -90,7 +90,7 @@ module RuboCop
90
90
  end
91
91
 
92
92
  def nested_relative_date(node, &callback)
93
- return if node.block_type?
93
+ return if node.nil? || node.block_type?
94
94
 
95
95
  node.each_child_node do |child|
96
96
  nested_relative_date(child, &callback)
@@ -317,16 +317,24 @@ module RuboCop
317
317
  return if receiver != node.receiver &&
318
318
  reversible_change_table_call?(node)
319
319
 
320
+ action = if method_name == :remove
321
+ target_rails_version >= 6.1 ? 't.remove (without type)' : 't.remove'
322
+ else
323
+ "change_table(with #{method_name})"
324
+ end
325
+
320
326
  add_offense(
321
327
  node,
322
- message: format(MSG, action: "change_table(with #{method_name})")
328
+ message: format(MSG, action: action)
323
329
  )
324
330
  end
325
331
 
326
332
  def reversible_change_table_call?(node)
327
333
  case node.method_name
328
- when :change, :remove
334
+ when :change
329
335
  false
336
+ when :remove
337
+ target_rails_version >= 6.1 && all_hash_key?(node.arguments.last, :type)
330
338
  when :change_default, :change_column_default, :change_table_comment,
331
339
  :change_column_comment
332
340
  all_hash_key?(node.arguments.last, :from, :to)
@@ -27,7 +27,7 @@ module RuboCop
27
27
  class UniqueValidationWithoutIndex < Base
28
28
  include ActiveRecordHelper
29
29
 
30
- MSG = 'Uniqueness validation should be with a unique index.'
30
+ MSG = 'Uniqueness validation should have a unique index on the database column.'
31
31
  RESTRICT_ON_SEND = %i[validates].freeze
32
32
 
33
33
  def on_send(node)
@@ -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.12.0'
7
+ STRING = '2.12.4'
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.12.0
4
+ version: 2.12.4
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-09-09 00:00:00.000000000 Z
13
+ date: 2021-10-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -205,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
205
  - !ruby/object:Gem::Version
206
206
  version: '0'
207
207
  requirements: []
208
- rubygems_version: 3.2.18
208
+ rubygems_version: 3.2.22
209
209
  signing_key:
210
210
  specification_version: 4
211
211
  summary: Automatic Rails code style checking tool.