From ddd4a804649c0fa4e7d31563c5e7029e4b59965e Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Thu, 3 Aug 2023 13:19:06 +0900 Subject: [PATCH] [Fix #1060] Fix a false positive for `Rails/HttpStatus` Fixes #1060. This PR fixes a false positive for `Rails/HttpStatus` when using symbolic value that have no numeric value mapping. --- changelog/fix_a_false_positive_for_rails_http_status.md | 1 + lib/rubocop/cop/rails/http_status.rb | 2 +- spec/rubocop/cop/rails/http_status_spec.rb | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changelog/fix_a_false_positive_for_rails_http_status.md diff --git a/changelog/fix_a_false_positive_for_rails_http_status.md b/changelog/fix_a_false_positive_for_rails_http_status.md new file mode 100644 index 0000000000..6397cf0fd4 --- /dev/null +++ b/changelog/fix_a_false_positive_for_rails_http_status.md @@ -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][]) diff --git a/lib/rubocop/cop/rails/http_status.rb b/lib/rubocop/cop/rails/http_status.rb index 52eb64966a..63c91823b9 100644 --- a/lib/rubocop/cop/rails/http_status.rb +++ b/lib/rubocop/cop/rails/http_status.rb @@ -133,7 +133,7 @@ def initialize(node) end def offensive? - !node.int_type? && !permitted_symbol? + !node.int_type? && !permitted_symbol? && number end def message diff --git a/spec/rubocop/cop/rails/http_status_spec.rb b/spec/rubocop/cop/rails/http_status_spec.rb index b0f1c35bc8..f7a6874113 100644 --- a/spec/rubocop/cop/rails/http_status_spec.rb +++ b/spec/rubocop/cop/rails/http_status_spec.rb @@ -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