Skip to content

Commit aa4ab80

Browse files
authored
Merge pull request rubocop#829 from jdufresne/revert-http-status
Revert "Merge pull request rubocop#823 from anthony-robin/http-status-routes"
2 parents 1acb097 + e79a3e3 commit aa4ab80

File tree

3 files changed

+2
-15
lines changed

3 files changed

+2
-15
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#829](https://github.com/rubocop/rubocop-rails/pull/829): Revert "Extends `Rails/HttpStatus` cop to check `routes.rb`" introduced in 2.17.0. ([@jdufresne][])

lib/rubocop/cop/rails/http_status.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ module Rails
1212
# render plain: 'foo/bar', status: 304
1313
# redirect_to root_url, status: 301
1414
# head 200
15-
# get '/foobar', to: redirect('/foobar/baz', status: 301)
1615
#
1716
# # good
1817
# render :foo, status: :ok
1918
# render json: { foo: 'bar' }, status: :ok
2019
# render plain: 'foo/bar', status: :not_modified
2120
# redirect_to root_url, status: :moved_permanently
2221
# head :ok
23-
# get '/foobar', to: redirect('/foobar/baz', status: :moved_permanently)
2422
#
2523
# @example EnforcedStyle: numeric
2624
# # bad
@@ -29,28 +27,25 @@ module Rails
2927
# render plain: 'foo/bar', status: :not_modified
3028
# redirect_to root_url, status: :moved_permanently
3129
# head :ok
32-
# get '/foobar', to: redirect('/foobar/baz', status: :moved_permanently)
3330
#
3431
# # good
3532
# render :foo, status: 200
3633
# render json: { foo: 'bar' }, status: 404
3734
# render plain: 'foo/bar', status: 304
3835
# redirect_to root_url, status: 301
3936
# head 200
40-
# get '/foobar', to: redirect('/foobar/baz', status: 301)
4137
#
4238
class HttpStatus < Base
4339
include ConfigurableEnforcedStyle
4440
extend AutoCorrector
4541

46-
RESTRICT_ON_SEND = %i[render redirect_to head redirect].freeze
42+
RESTRICT_ON_SEND = %i[render redirect_to head].freeze
4743

4844
def_node_matcher :http_status, <<~PATTERN
4945
{
5046
(send nil? {:render :redirect_to} _ $hash)
5147
(send nil? {:render :redirect_to} $hash)
5248
(send nil? :head ${int sym} ...)
53-
(send nil? :redirect _ $hash)
5449
}
5550
PATTERN
5651

spec/rubocop/cop/rails/http_status_spec.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
^^^ Prefer `:ok` over `200` to define HTTP status code.
2525
head 200, location: 'accounts'
2626
^^^ Prefer `:ok` over `200` to define HTTP status code.
27-
get '/foobar', to: redirect('/foobar/baz', status: 301)
28-
^^^ Prefer `:moved_permanently` over `301` to define HTTP status code.
2927
RUBY
3028

3129
expect_correction(<<~RUBY)
@@ -38,7 +36,6 @@
3836
redirect_to root_path(utm_source: :pr, utm_medium: :web), status: :moved_permanently
3937
head :ok
4038
head :ok, location: 'accounts'
41-
get '/foobar', to: redirect('/foobar/baz', status: :moved_permanently)
4239
RUBY
4340
end
4441

@@ -50,7 +47,6 @@
5047
redirect_to root_url, status: :moved_permanently
5148
redirect_to root_path(utm_source: :pr, utm_medium: :web), status: :moved_permanently
5249
head :ok
53-
get '/foobar', to: redirect('/foobar/baz', status: :moved_permanently)
5450
RUBY
5551
end
5652

@@ -62,7 +58,6 @@
6258
redirect_to root_url, status: 550
6359
redirect_to root_path(utm_source: :pr, utm_medium: :web), status: 550
6460
head 550
65-
get '/foobar', to: redirect('/foobar/baz', status: 550)
6661
RUBY
6762
end
6863
end
@@ -90,8 +85,6 @@
9085
^^^ Prefer `200` over `:ok` to define HTTP status code.
9186
head :ok, location: 'accounts'
9287
^^^ Prefer `200` over `:ok` to define HTTP status code.
93-
get '/foobar', to: redirect('/foobar/baz', status: :moved_permanently)
94-
^^^^^^^^^^^^^^^^^^ Prefer `301` over `:moved_permanently` to define HTTP status code.
9588
RUBY
9689

9790
expect_correction(<<~RUBY)
@@ -104,7 +97,6 @@
10497
redirect_to root_path(utm_source: :pr, utm_medium: :web), status: 301
10598
head 200
10699
head 200, location: 'accounts'
107-
get '/foobar', to: redirect('/foobar/baz', status: 301)
108100
RUBY
109101
end
110102

@@ -116,7 +108,6 @@
116108
redirect_to root_url, status: 301
117109
redirect_to root_path(utm_source: :pr, utm_medium: :web), status: 301
118110
head 200
119-
get '/foobar', to: redirect('/foobar/baz', status: 301)
120111
RUBY
121112
end
122113

0 commit comments

Comments
 (0)