Class: Gitlab::Styles::Rubocop::Cop::RedirectWithStatus
- Inherits:
-
RuboCop::Cop::Cop
- Object
- RuboCop::Cop::Cop
- Gitlab::Styles::Rubocop::Cop::RedirectWithStatus
- Defined in:
- lib/gitlab/styles/rubocop/cop/redirect_with_status.rb
Overview
This cop prevents usage of ‘redirect_to’ in actions ‘destroy’ without specifying ‘status’. See gitlab.com/gitlab-org/gitlab-ce/issues/31840
Constant Summary collapse
- MSG =
'Do not use "redirect_to" without "status" in "destroy" action'
Instance Method Summary collapse
Instance Method Details
#on_def(node) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/gitlab/styles/rubocop/cop/redirect_with_status.rb', line 12 def on_def(node) return unless in_controller?(node) return unless destroy?(node) || destroy_all?(node) node.each_descendant(:send) do |def_node| next unless redirect_to?(def_node) methods = [] def_node.children.last.each_node(:pair) do |pair| methods << pair.children.first.children.first end add_offense(def_node, location: :selector) unless methods.include?(:status) end end |