Skip to content
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

Rails/HttpStatus: invalid status symbol is replaced with `` after safe autocorrection #1060

Closed
eggplants opened this issue Aug 3, 2023 · 0 comments · Fixed by #1061
Closed
Labels
bug Something isn't working

Comments

@eggplants
Copy link

eggplants commented Aug 3, 2023

Expected behavior

I think this cop should not be marked as a safe cop.

Actual behavior

bundle exec rubocop --only Rails/HttpStatus

Rubocop says:

app/controllers/Foos_controller.rb:3:30: C: [Correctable] Rails/HttpStatus: Prefer  over :ng to define HTTP status code.
      render json: {}, status: :ng
                               ^^^

bundle exec rubocop -a --only Rails/HttpStatus

Rubocop says:

app/controllers/Foos_controller.rb:3:30: C: [Corrected] Rails/HttpStatus: Prefer  over :ng to define HTTP status code.
      render json: {}, status: :ng
                               ^^^

And actual code turns into:

class FoosController < ApplicationController
  def index
    render json: {}, status:
  end
end

It raises Lint/Syntax violation.

app/controllers/Foos_controller.rb:4:3: F: Lint/Syntax: unexpected token kEND
(Using Ruby 3.0 parser; configure using TargetRubyVersion parameter, under AllCops)
  end
  ^^^

Steps to reproduce the problem

class FoosController < ApplicationController
  def index
    render json: {}, status:
  end
end

RuboCop version

$ bundle exec rubocop -V
1.50.2 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.0.6) [x86_64-darwin22]
  - rubocop-erb 0.2.4
  - rubocop-performance 1.17.1
  - rubocop-rails 2.19.1
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.20.0
@eggplants eggplants changed the title Rails/HttpStatus: invalid status symbol are incorrectly vanished after autocorrection Rails/HttpStatus: invalid status symbol is incorrectly replaced with `` after autocorrection Aug 3, 2023
@eggplants eggplants changed the title Rails/HttpStatus: invalid status symbol is incorrectly replaced with `` after autocorrection Rails/HttpStatus: invalid status symbol is replaced with `` after safe autocorrection Aug 3, 2023
@koic koic added the bug Something isn't working label Aug 3, 2023
koic added a commit to koic/rubocop-rails that referenced this issue Aug 3, 2023
Fixes rubocop#1060.

This PR fixes a false positive for `Rails/HttpStatus` when
using symbolic value that have no numeric value mapping.
@koic koic closed this as completed in #1061 Aug 4, 2023
koic added a commit that referenced this issue Aug 4, 2023
…p_status

[Fix #1060] Fix a false positive for `Rails/HttpStatus`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants