Releases: Betterment/betterlint
v1.14.0
v1.13.0
v1.10.1
Status code safety with `RedirectStatus` and `RenderStatus`!
👇 This release introduces two new linters, courtesy of @rzane! 👇
Betterment/RedirectStatus
The redirect_to
method defaults to a 302 Found
, but when redirecting a POST/PUT/PATCH/DELETE
to a GET location, the correct response code is 303 See Other
.
This cop requires you to explictly provide an HTTP status code when redirecting from the create,
update, and destory actions. When autocorrecting, this will automatically add status: :see_other
.
Betterment/RenderStatus
The render
method defaults to a 200 OK
. Calling render
in the create, update, and destroy
actions often indicates error handling (e.g. 422 Unprocessable Entity
).
This cop requires you to explicitly provide an HTTP status code when rendering a response in the
create, update, and destroy actions. When autocorrecting, this will automatically add
status: :unprocessable_entity
or status: :ok
depending on what you're rendering.
`FetchBoolean` linter!
This release includes a new FetchBoolean
rule that applies to both controller params
and any ENV
fetch that seems to expect a boolean but does not cast the string value (resulting in a truthy return value even for falsey strings), contributed by @ivangreene!
In Ivan's words:
This is a mistake I've made at least twice now. Basically, query params like ?should_do_something=false
will result in the value of string 'false' when fetched from a params object.
# Sending '?should_do_something=false' results in string 'false' here!
should_do_something = params.fetch(:should_do_something, false)
The only way that they can be falsey is if they are omitted from the request and default to false. This is also an issue where we are expecting exactly true and not just any truthy value. The solution is to cast them explicitly
# Always an actual boolean value
should_do_something = ActiveModel::Type::Boolean.new.cast(params.fetch(:should_do_something, false))