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

Metrics/ParameterLists ignores Max value generate by rubocop --auto-gen-config #9465

Closed
ShockwaveNN opened this issue Jan 29, 2021 · 3 comments · Fixed by #9471
Closed

Metrics/ParameterLists ignores Max value generate by rubocop --auto-gen-config #9465

ShockwaveNN opened this issue Jan 29, 2021 · 3 comments · Fixed by #9471
Assignees

Comments

@ShockwaveNN
Copy link
Contributor

Steps to reproduce the problem

  1. Create test.rb file with content:
# frozen_string_literal: true

def foo(param1, param2, param3 = true, param4 = false, param5 = false, param6 = false)
  puts param1
  puts param2
  puts param3
  puts param4
  puts param5
  puts param6
end

  1. run rubocop --auto-gen-config and get this .rubocop_todo.yml
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2021-01-29 13:25:51 UTC using RuboCop version 1.9.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 2
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
Metrics/ParameterLists:
  Max: 6

# Offense count: 4
# Configuration parameters: AllowedMethods.
# AllowedMethods: respond_to_missing?
Style/OptionalBooleanParameter:
  Exclude:
    - 'test.rb'
  1. Metrics/ParameterLists max is 6, so it should be no warning for running rubocop now, but there is one:
rubocop
...
Offenses:

test.rb:3:1: C: Metrics/ParameterLists: Method has too many optional parameters. [4/3]
def foo(param1, param2, param3 = true, param4 = false, param5 = false, param6 = false) ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected

RuboCop version

1.9.0 (using Parser 3.0.0.0, rubocop-ast 1.4.1, running on ruby 2.7.2 x86_64-linux)
@dvandersluis
Copy link
Member

dvandersluis commented Jan 29, 2021

Optional parameters have a separate configuration, MaxOptionalParameters, which is why you're seeing [4/3] and not [6/4]. You could add that config to the todo file in the meantime until this is fixed.

@dvandersluis dvandersluis self-assigned this Jan 29, 2021
@ShockwaveNN
Copy link
Contributor Author

Shouldn't --auto-gen-config generate config which will not result any warning on next rubocop run?

@dvandersluis
Copy link
Member

Definitely, I'm opening a PR momentarily.

dvandersluis added a commit to dvandersluis/rubocop that referenced this issue Jan 31, 2021
…e `MaxOptionalParameters` in rubocop_todo.yml.
bbatsov pushed a commit that referenced this issue Feb 1, 2021
…ptionalParameters` in rubocop_todo.yml.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants