From f24fae8c38713c2db49e2bfb0e51999d362fe98f Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Mon, 27 Jan 2020 19:25:29 +0900 Subject: [PATCH] [Fix #180] Fix a false positive for `HttpPositionalArguments` Fixes #180 This PR fixes a false positive for `HttpPositionalArguments` when using `get` method with `:to` option. --- CHANGELOG.md | 4 ++++ lib/rubocop/cop/rails/http_positional_arguments.rb | 2 +- spec/rubocop/cop/rails/http_positional_arguments_spec.rb | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7fda4e620..772bdc0217 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## master (unreleased) +### Bug fixes + +* [#180](https://github.com/rubocop-hq/rubocop-rails/issues/180): Fix a false positive for `HttpPositionalArguments` when using `get` method with `:to` option. ([@koic][]) + ## 2.4.2 (2020-01-26) ### Bug fixes diff --git a/lib/rubocop/cop/rails/http_positional_arguments.rb b/lib/rubocop/cop/rails/http_positional_arguments.rb index 27661eabb7..5d2634f089 100644 --- a/lib/rubocop/cop/rails/http_positional_arguments.rb +++ b/lib/rubocop/cop/rails/http_positional_arguments.rb @@ -22,7 +22,7 @@ class HttpPositionalArguments < Cop MSG = 'Use keyword arguments instead of ' \ 'positional arguments for http call: `%s`.' KEYWORD_ARGS = %i[ - method params session body flash xhr as headers env + method params session body flash xhr as headers env to ].freeze HTTP_METHODS = %i[get post put patch delete head].freeze diff --git a/spec/rubocop/cop/rails/http_positional_arguments_spec.rb b/spec/rubocop/cop/rails/http_positional_arguments_spec.rb index 8c9193f5da..5c0803cfa3 100644 --- a/spec/rubocop/cop/rails/http_positional_arguments_spec.rb +++ b/spec/rubocop/cop/rails/http_positional_arguments_spec.rb @@ -113,6 +113,12 @@ RUBY end + it 'registers an offense for get method with `:to` option' do + expect_no_offenses(<<~RUBY) + get '/test', to: 'admin/admin#test' + RUBY + end + it 'registers an offense for post method' do expect_offense(<<~RUBY) post :create, user_id: @user.id