Class: RuboCop::Cop::Rails::ActionOrder
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Rails::ActionOrder
- Extended by:
- AutoCorrector
- Includes:
- DefNode, VisibilityHelp
- Defined in:
- lib/rubocop/cop/rails/action_order.rb
Overview
Enforces consistent ordering of the standard Rails RESTful controller actions.
The cop is configurable and can enforce any ordering of the standard actions. All other methods are ignored.
- source,yaml
Rails/ActionOrder: ExpectedOrder: - index - show - new - edit - create - update - destroy
Constant Summary collapse
- MSG =
'Action `%<current>s` should appear before `%<previous>s`.'
Instance Method Summary collapse
Instance Method Details
#on_class(node) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/rubocop/cop/rails/action_order.rb', line 43 def on_class(node) action_declarations(node, actions).each_cons(2) do |previous, current| next if node_visibility(current) != :public || non_public?(current) next if find_index(current) >= find_index(previous) register_offense(previous, current) end end |