class RuboCop::Cop::Rails::IgnoredSkipActionFilterOption

@see api.rubyonrails.org/classes/AbstractController/Callbacks/ClassMethods.html#method-i-_normalize_callback_options<br><br>end
if: -> { trusted_origin? && action_name != “admin” }
skip_before_action :login_required,
class MyPageController < ApplicationController
# good
end
except: :admin, if: :trusted_origin?
skip_before_action :login_required,
class MyPageController < ApplicationController
# bad
@example
end
if: -> { trusted_origin? && action_name == “show” }
skip_before_action :login_required,
class MyPageController < ApplicationController
# good
end
only: :show, if: :trusted_origin?
skip_before_action :login_required,
class MyPageController < ApplicationController
# bad
@example
are used together.
Similarly, the ‘except` option will be ignored when `if` and `except`
The `if` option will be ignored when `if` and `only` are used together.
as options of `skip_*` action filter.
This cop checks that `if` and `only` (or `except`) are not used together

def if_and_except?(options)

def if_and_except?(options)
  options.key?(:if) && options.key?(:except)
end

def if_and_only?(options)

def if_and_only?(options)
  options.key?(:if) && options.key?(:only)
end

def on_send(node)

def on_send(node)
  options = filter_options(node)
  return unless options
  return unless options.hash_type?
  options = options_hash(options)
  if if_and_only?(options)
    add_offense(options[:if],
                message: format(MSG, prefer: :only, ignore: :if))
  elsif if_and_except?(options)
    add_offense(options[:except],
                message: format(MSG, prefer: :if, ignore: :except))
  end
end

def options_hash(options)

def options_hash(options)
  options.pairs
         .select { |pair| pair.key.sym_type? }
         .map { |pair| [pair.key.value, pair] }.to_h
end