Skip to content

Commit

Permalink
[Fix #1060] Fix a false positive for Rails/HttpStatus
Browse files Browse the repository at this point in the history
Fixes #1060.

This PR fixes a false positive for `Rails/HttpStatus` when
using symbolic value that have no numeric value mapping.
  • Loading branch information
koic committed Aug 3, 2023
1 parent 34376e0 commit ddd4a80
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_a_false_positive_for_rails_http_status.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1060](https://github.com/rubocop/rubocop-rails/issues/1060): Fix a false positive for `Rails/HttpStatus` when using symbolic value that have no numeric value mapping. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/http_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def initialize(node)
end

def offensive?
!node.int_type? && !permitted_symbol?
!node.int_type? && !permitted_symbol? && number
end

def message
Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/rails/http_status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,11 @@
render :foo, status: :redirect
RUBY
end

it 'does not register an offense when using symbolic value that have no numeric value mapping' do
expect_no_offenses(<<~RUBY)
render json: { foo: 'bar' }, status: :ng
RUBY
end
end
end

0 comments on commit ddd4a80

Please sign in to comment.