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

Autocorrection of Rails/HttpPositionalArguments removes keyword-splat arguments #352

Closed
shepmaster opened this issue Sep 9, 2020 · 0 comments · Fixed by #354
Closed

Comments

@shepmaster
Copy link

Expected behavior

There would be no change to the code.

Actual behavior

The code is corrected in an incompatible manner

Steps to reproduce the problem

Gemfile

# frozen_string_literal: true

source 'https://rubygems.org'

git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

gem 'rubocop-rails', '=2.8'

.rubocop.yml

require: rubocop-rails

AllCops:
  NewCops: enable

spec/controllers/my_controller_spec.rb

# frozen_string_literal: true

describe do
  [{ format: :json }, { format: :html }].each do |args|
    it do
      get :nothing, **args
    end
  end
end

Run rubocop:

rubocop -a
Inspecting 2 files
.W

Offenses:

spec/controllers/my_controller_spec.rb:4:51: W: [Corrected] Lint/UnusedBlockArgument: Unused block argument - args. You can omit the argument if you don't care about it.
  [{ format: :json }, { format: :html }].each do |args|
                                                  ^^^^
spec/controllers/my_controller_spec.rb:6:7: C: [Corrected] Rails/HttpPositionalArguments: Use keyword arguments instead of positional arguments for http call: get.
      get :nothing, **args
      ^^^
spec/controllers/my_controller_spec.rb:6:30: C: [Corrected] Layout/ExtraSpacing: Unnecessary spacing detected.
      get :nothing, params: {  }
                             ^
spec/controllers/my_controller_spec.rb:6:30: C: [Corrected] Layout/SpaceInsideHashLiteralBraces: Space inside empty hash literal braces detected.
      get :nothing, params: {  }
                             ^^

This results in the diff:

diff --git a/spec/controllers/my_controller_spec.rb b/spec/controllers/my_controller_spec.rb
index 2e9bbe4..b8e47ac 100644
--- a/spec/controllers/my_controller_spec.rb
+++ b/spec/controllers/my_controller_spec.rb
@@ -1,9 +1,9 @@
 # frozen_string_literal: true

 describe do
-  [{ format: :json }, { format: :html }].each do |args|
+  [{ format: :json }, { format: :html }].each do |_args|
     it do
-      get :nothing, **args
+      get :nothing, params: {}
     end
   end
 end

RuboCop version

% bundle exec rubocop -V
0.90.0 (using Parser 2.7.1.4, rubocop-ast 0.3.0, running on ruby 2.6.6 x86_64-darwin19)
dvandersluis added a commit to dvandersluis/rubocop-rails that referenced this issue Sep 10, 2020
dvandersluis added a commit to dvandersluis/rubocop-rails that referenced this issue Sep 11, 2020
dvandersluis added a commit to dvandersluis/rubocop-rails that referenced this issue Sep 11, 2020
@koic koic closed this as completed in #354 Sep 12, 2020
koic added a commit that referenced this issue Sep 12, 2020
[Fix #352] Do not register an offense for `Rails/HttpPositionalArguments` when given a splatted hash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant