From 9df4e2060a93c3b3336fd785135b85aec5c3d187 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sun, 23 Oct 2022 09:41:42 -0700 Subject: [PATCH] Revert "Merge pull request #823 from anthony-robin/http-status-routes" This reverts commit e40d8b9e41daba64364b23df469d534383804951, reversing changes made to 6051ed83c97e99c008fa9d5c91ed5955d915c804. The auto-corrected code is not compatible with Rails/Puma, resulting the error: Puma caught this error: undefined method `to_i' for :moved_permanently:Symbol status = status.to_i ^^^^^ Did you mean? to_s (NoMethodError) /.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/puma-5.6.5/lib/puma/request.rb:82:in `handle_request' /.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/puma-5.6.5/lib/puma/server.rb:443:in `process_client' /.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/puma-5.6.5/lib/puma/thread_pool.rb:147:in `block in spawn_thread' --- changelog/change_revert_merge_pull_request_823_from.md | 1 + lib/rubocop/cop/rails/http_status.rb | 7 +------ spec/rubocop/cop/rails/http_status_spec.rb | 9 --------- 3 files changed, 2 insertions(+), 15 deletions(-) create mode 100644 changelog/change_revert_merge_pull_request_823_from.md diff --git a/changelog/change_revert_merge_pull_request_823_from.md b/changelog/change_revert_merge_pull_request_823_from.md new file mode 100644 index 0000000000..a399f41d2a --- /dev/null +++ b/changelog/change_revert_merge_pull_request_823_from.md @@ -0,0 +1 @@ +* [#x](https://github.com/rubocop/rubocop-rails/pull/x): Reverted "Extends `Rails/HttpStatus` cop to check `routes.rb`" introduced in 2.17.0. ([@jdufresne][]) diff --git a/lib/rubocop/cop/rails/http_status.rb b/lib/rubocop/cop/rails/http_status.rb index 7b9d6e4d33..b80498c27e 100644 --- a/lib/rubocop/cop/rails/http_status.rb +++ b/lib/rubocop/cop/rails/http_status.rb @@ -12,7 +12,6 @@ module Rails # render plain: 'foo/bar', status: 304 # redirect_to root_url, status: 301 # head 200 - # get '/foobar', to: redirect('/foobar/baz', status: 301) # # # good # render :foo, status: :ok @@ -20,7 +19,6 @@ module Rails # render plain: 'foo/bar', status: :not_modified # redirect_to root_url, status: :moved_permanently # head :ok - # get '/foobar', to: redirect('/foobar/baz', status: :moved_permanently) # # @example EnforcedStyle: numeric # # bad @@ -29,7 +27,6 @@ module Rails # render plain: 'foo/bar', status: :not_modified # redirect_to root_url, status: :moved_permanently # head :ok - # get '/foobar', to: redirect('/foobar/baz', status: :moved_permanently) # # # good # render :foo, status: 200 @@ -37,20 +34,18 @@ module Rails # render plain: 'foo/bar', status: 304 # redirect_to root_url, status: 301 # head 200 - # get '/foobar', to: redirect('/foobar/baz', status: 301) # class HttpStatus < Base include ConfigurableEnforcedStyle extend AutoCorrector - RESTRICT_ON_SEND = %i[render redirect_to head redirect].freeze + RESTRICT_ON_SEND = %i[render redirect_to head].freeze def_node_matcher :http_status, <<~PATTERN { (send nil? {:render :redirect_to} _ $hash) (send nil? {:render :redirect_to} $hash) (send nil? :head ${int sym} ...) - (send nil? :redirect _ $hash) } PATTERN diff --git a/spec/rubocop/cop/rails/http_status_spec.rb b/spec/rubocop/cop/rails/http_status_spec.rb index f254746e47..4500be01ce 100644 --- a/spec/rubocop/cop/rails/http_status_spec.rb +++ b/spec/rubocop/cop/rails/http_status_spec.rb @@ -24,8 +24,6 @@ ^^^ Prefer `:ok` over `200` to define HTTP status code. head 200, location: 'accounts' ^^^ Prefer `:ok` over `200` to define HTTP status code. - get '/foobar', to: redirect('/foobar/baz', status: 301) - ^^^ Prefer `:moved_permanently` over `301` to define HTTP status code. RUBY expect_correction(<<~RUBY) @@ -38,7 +36,6 @@ redirect_to root_path(utm_source: :pr, utm_medium: :web), status: :moved_permanently head :ok head :ok, location: 'accounts' - get '/foobar', to: redirect('/foobar/baz', status: :moved_permanently) RUBY end @@ -50,7 +47,6 @@ redirect_to root_url, status: :moved_permanently redirect_to root_path(utm_source: :pr, utm_medium: :web), status: :moved_permanently head :ok - get '/foobar', to: redirect('/foobar/baz', status: :moved_permanently) RUBY end @@ -62,7 +58,6 @@ redirect_to root_url, status: 550 redirect_to root_path(utm_source: :pr, utm_medium: :web), status: 550 head 550 - get '/foobar', to: redirect('/foobar/baz', status: 550) RUBY end end @@ -90,8 +85,6 @@ ^^^ Prefer `200` over `:ok` to define HTTP status code. head :ok, location: 'accounts' ^^^ Prefer `200` over `:ok` to define HTTP status code. - get '/foobar', to: redirect('/foobar/baz', status: :moved_permanently) - ^^^^^^^^^^^^^^^^^^ Prefer `301` over `:moved_permanently` to define HTTP status code. RUBY expect_correction(<<~RUBY) @@ -104,7 +97,6 @@ redirect_to root_path(utm_source: :pr, utm_medium: :web), status: 301 head 200 head 200, location: 'accounts' - get '/foobar', to: redirect('/foobar/baz', status: 301) RUBY end @@ -116,7 +108,6 @@ redirect_to root_url, status: 301 redirect_to root_path(utm_source: :pr, utm_medium: :web), status: 301 head 200 - get '/foobar', to: redirect('/foobar/baz', status: 301) RUBY end