lib/rubocop/cop/rails/not_null_column.rb in rubocop-rails-2.17.4 vs lib/rubocop/cop/rails/not_null_column.rb in rubocop-rails-2.18.0
- old
+ new
@@ -19,11 +19,11 @@
class NotNullColumn < Base
MSG = 'Do not add a NOT NULL column without a default value.'
RESTRICT_ON_SEND = %i[add_column add_reference].freeze
def_node_matcher :add_not_null_column?, <<~PATTERN
- (send nil? :add_column _ _ _ (hash $...))
+ (send nil? :add_column _ _ $_ (hash $...))
PATTERN
def_node_matcher :add_not_null_reference?, <<~PATTERN
(send nil? :add_reference _ _ (hash $...))
PATTERN
@@ -42,20 +42,23 @@
end
private
def check_add_column(node)
- pairs = add_not_null_column?(node)
- check_pairs(pairs)
+ add_not_null_column?(node) do |type, pairs|
+ return if type.value == :virtual || type.value == 'virtual'
+
+ check_pairs(pairs)
+ end
end
def check_add_reference(node)
- pairs = add_not_null_reference?(node)
- check_pairs(pairs)
+ add_not_null_reference?(node) do |pairs|
+ check_pairs(pairs)
+ end
end
def check_pairs(pairs)
- return unless pairs
return if pairs.any? { |pair| default_option?(pair) }
null_false = pairs.find { |pair| null_false?(pair) }
return unless null_false