-
-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New cop idea: specifying response content when rendering a 204 No Content response #967
Labels
feature request
Request for new functionality
Comments
Should such a cop recommend |
I am unsure what is best practice in this regard. I suppose Interested to hear other opinions. |
I have never encountered a case like this (it may be lucky 😅 ). Can you show expected bad and good case example codes in practice? |
@koic of course. # Bad
render status: :continue, plain: 'content for the response body'
render status: :no_content, html: helpers.tag.strong('content for the response body')
render status: :reset_content, json: { content_for: 'the response body' }
render status: :not_modified, xml: { content_for: 'the response body' }.to_xml
# Good
render status: :continue
render status: :no_content
render status: :reset_content
render status: :not_modified
# Also good
head :continue
head :no_content
head :reset_content
head :not_modified |
samrjenkins
added a commit
to samrjenkins/rubocop-rails
that referenced
this issue
Apr 2, 2023
samrjenkins
added a commit
to samrjenkins/rubocop-rails
that referenced
this issue
Apr 2, 2023
9 tasks
samrjenkins
added a commit
to samrjenkins/rubocop-rails
that referenced
this issue
Apr 7, 2023
samrjenkins
added a commit
to samrjenkins/rubocop-rails
that referenced
this issue
Apr 7, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
Occasionally I see Rails engineers specify a 204 No Content response within a controller action along with content for the response's body:
This is misleading. As specified in the Rails docs (https://guides.rubyonrails.org/layouts_and_rendering.html):
and can give engineers the impression that their response body will contain the content they specify.
Describe the solution you'd like
A new cop to register an offence whenever body content is specified for a response with a no-content status code.
I would be very happy to work on such a cop.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
The text was updated successfully, but these errors were encountered: