Class: Ducalis::ControllersExcept

Inherits:
RuboCop::Cop::Cop
  • Object
show all
Defined in:
lib/ducalis/cops/controllers_except.rb

Constant Summary collapse

OFFENSE =
<<-MESSAGE.gsub(/^ +\|\s/, '').strip
  | Prefer to use `:only` over `:except` in controllers because it's more explicit and will be easier to maintain for new developers.
MESSAGE
FILTERS =
%i[before_filter after_filter around_filter
before_action after_action around_action].freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/ducalis/cops/controllers_except.rb', line 14

def on_send(node)
  _, method_name, *args = *node
  hash_node = args.find { |subnode| subnode.type == :hash }
  return unless FILTERS.include?(method_name) && hash_node

  type, _method_names = decomposite_hash(hash_node)
  return unless type == s(:sym, :except)

  add_offense(node, :selector, OFFENSE)
end