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

Extends Rails/HttpStatus cop to check routes.rb #822

Closed
anthony-robin opened this issue Oct 21, 2022 · 0 comments · Fixed by #823
Closed

Extends Rails/HttpStatus cop to check routes.rb #822

anthony-robin opened this issue Oct 21, 2022 · 0 comments · Fixed by #823

Comments

@anthony-robin
Copy link
Contributor

Is your feature request related to a problem? Please describe.

Currently, the Rails/HttpStatus cop detects offenses in controllers but not in routes.rb.

# Offense properly detected in controller
class FoobarController < ApplicationController
  def show
    # ...
    redirect_to foobarbaz_path, status: 301
  end
end

# Offense not detected in routes
Rails.application.routes.draw do
  get '/foobar', to: redirect('/foobar/baz', status: 301)
end

Describe the solution you'd like

It could be interesting to extends Rails/HttpStatus to detect offenses in redirect method as well.

Rails.application.routes.draw do
  # Detect offense
  get '/foobar', to: redirect('/foobar/baz', status: 301)

  # Autocorrect it
  get '/foobar', to: redirect('/foobar/baz', status: :moved_permanently)
end

Thank you :)

anthony-robin added a commit to anthony-robin/rubocop-rails that referenced this issue Oct 21, 2022
Fixes rubocop#822.

This PR extends `Rails/HttpStatus` to detects offenses in `routes.rb` on redirections:

```ruby
Rails.application.routes.draw do
  get '/foobar', to: redirect('/foobar/baz', status: 301)
end
```
anthony-robin added a commit to anthony-robin/rubocop-rails that referenced this issue Oct 21, 2022
Fixes rubocop#822.

This PR extends `Rails/HttpStatus` to detects offenses in `routes.rb` on redirections:

```ruby
Rails.application.routes.draw do
  get '/foobar', to: redirect('/foobar/baz', status: 301)
end
```
@koic koic closed this as completed in #823 Oct 22, 2022
koic added a commit that referenced this issue Oct 22, 2022
[Fix #822] Extends `Rails/HttpStatus` cop to check `routes.rb`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant