Class: RuboCop::Cop::Appdev::ExplicitRenderAndRedirect
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Appdev::ExplicitRenderAndRedirect
- Defined in:
- lib/rubocop/cop/appdev/explicit_render_and_redirect.rb
Overview
Enforces the explicit forms of ‘render`, `redirect_to`, and `redirect_back`:
render({ :template => "movies/index" }) # required
render({ :partial => "form", :locals => ... }) # also fine
redirect_to("/movies") # required
redirect_to("/movies/#{movie.id}", { :notice => "..." })
redirect_back(:fallback_location => "/movies")
Polished shortcuts like ‘render :new`, `redirect_to @movie`, `redirect_to places_url`, and `redirect_back(fallback_location: request.referer)` are all flagged.
Constant Summary collapse
- MSG_RENDER =
"Use `render({ :template => \"...\" })` with an explicit hash."- MSG_REDIRECT_TO =
"Use `redirect_to(\"/string/path\")` with a string literal path."- MSG_REDIRECT_BACK =
"`redirect_back` requires `:fallback_location` set to a string literal."- RESTRICT_ON_SEND =
[:render, :redirect_to, :redirect_back].freeze
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rubocop/cop/appdev/explicit_render_and_redirect.rb', line 23 def on_send(node) return if node.receiver case node.method_name when :render check_render(node) when :redirect_to check_redirect_to(node) when :redirect_back check_redirect_back(node) end end |