Fix Rails::NegateInclude issues

- cop class: RuboCop::Cop::Rails::NegateInclude
 -  replaced !array.include?(2) by array.exclude?(2)
This commit is contained in:
cyrillefr
2024-04-04 14:42:42 +02:00
parent cf9414a352
commit 84747ea064
6 changed files with 5 additions and 15 deletions

View File

@@ -668,16 +668,6 @@ Rails/LexicallyScopedActionFilter:
- 'app/controllers/spree/admin/zones_controller.rb'
- 'app/controllers/spree/users_controller.rb'
# Offense count: 5
# This cop supports unsafe autocorrection (--autocorrect-all).
Rails/NegateInclude:
Exclude:
- 'app/controllers/admin/resource_controller.rb'
- 'app/models/calculator/weight.rb'
- 'app/models/product_import/spreadsheet_entry.rb'
- 'lib/spree/localized_number.rb'
- 'spec/support/matchers/table_matchers.rb'
# Offense count: 32
# This cop supports unsafe autocorrection (--autocorrect-all).
Rails/Pluck:

View File

@@ -229,7 +229,7 @@ module Admin
end
def member_action?
!collection_actions.include? action
collection_actions.exclude? action
end
def new_actions

View File

@@ -10,7 +10,7 @@ module Calculator
end
def set_preference(name, value)
if name == :unit_from_list && !["kg", "lb"].include?(value)
if name == :unit_from_list && ["kg", "lb"].exclude?(value)
calculable.errors.add(:preferred_unit_from_list, I18n.t(:calculator_preferred_unit_error))
else
__send__ self.class.preference_setter_method(name), value

View File

@@ -94,7 +94,7 @@ module ProductImport
units = UnitConverter.new(attrs)
units.converted_attributes.each do |attr, value|
if respond_to?("#{attr}=") && !NON_PRODUCT_ATTRIBUTES.include?(attr)
if respond_to?("#{attr}=") && NON_PRODUCT_ATTRIBUTES.exclude?(attr)
public_send("#{attr}=", value)
end
end

View File

@@ -77,7 +77,7 @@ module Spree
private
def non_activerecord_attribute?(attribute)
table_exists? && !column_names.include?(attribute.to_s)
table_exists? && column_names.exclude?(attribute.to_s)
rescue ::ActiveRecord::NoDatabaseError
# This class is now loaded during `rake db:create` (since Rails 5.2), and not only does the
# table not exist, but the database does not even exist yet, and throws a fatal error.

View File

@@ -8,7 +8,7 @@ RSpec::Matchers.define :have_table_row do |row|
match_when_negated do |node|
@row = row
!rows_under(node).include? row # Robust check of columns
rows_under(node).exclude? row # Robust check of columns
end
failure_message do |text|