Skip to content

Improve Rails/HttpStatus cop #1080

Closed
@ydakuka

Description

@ydakuka

Reference: https://rails.rubystyle.guide/#http-status-code-symbols

Actual behavior

If I have the following code:

# frozen_string_literal: true

class ProductsController < ApplicationController
  def index
    render status: '403'
  end
end

or

# frozen_string_literal: true

class ProductsController < ApplicationController
  def index
    render status: 'forbidden'
  end
end

I will run rubocop and not get any offences:

ydakuka@yauhenid:~/Work/project$ bin/rails_docker rubocop app/controllers/products_controller.rb 
Inspecting 1 file
.

1 file inspected, no offenses detected

Expected behavior

# frozen_string_literal: true

class ProductsController < ApplicationController
  def index
    render status: :forbidden
  end
end

Rubocop

ydakuka@yauhenid:~/Work/project$ bin/rails_docker rubocop -V
1.55.1 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 2.7.8) [x86_64-linux]
  - rubocop-capybara 2.18.0
  - rubocop-factory_bot 2.23.1
  - rubocop-performance 1.18.0
  - rubocop-rails 2.20.2
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.23.0
  - rubocop-thread_safety 0.5.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions