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

[Fix #10919] Fix a huge performance regression between 1.32.0 and 1.33.0 #10953

Merged
merged 1 commit into from Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/fix_fix_a_huge_performance_regression.md
@@ -0,0 +1 @@
* [#10919](https://github.com/rubocop/rubocop/issues/10919): Fix a huge performance regression between 1.32.0 and 1.33.0. ([@ydah][])
15 changes: 10 additions & 5 deletions lib/rubocop/cop/mixin/allowed_methods.rb
Expand Up @@ -17,16 +17,21 @@ def allowed_method?(name)

# @api public
def allowed_methods
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[memo] The reason for the slow speed was due to this method.
If the following settings were used

Style/MethodCallWithArgsParentheses:
  IgnoredMethods:
    - abort
    - after_save
    - and
    - before_save
    - delegate
    - describe
    - exec
    - exit
    - load
    - not_to
    - p
    - print
    - puts
    - raise
    - require
    - shared_context
    - shared_examples
    - star_puts
    - throw
    - to
    - warn
    - yield

it was returning the following results (increasing with each file)

["abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield", "abort", "after_save", "and", "before_save", "delegate", "describe", "exec", "exit", "load", "not_to", "p", "print", "puts", "raise", "require", "shared_context", "shared_examples", "star_puts", "throw", "to", "warn", "yield"]

deprecated_values = cop_config_deprecated_values
if deprecated_values.any?(Regexp)
cop_config.fetch('AllowedMethods', [])
if cop_config_deprecated_values.any?(Regexp)
cop_config_allowed_methods
else
Array(cop_config['AllowedMethods']).concat(deprecated_values)
cop_config_allowed_methods + cop_config_deprecated_values
end
end

def cop_config_allowed_methods
@cop_config_allowed_methods ||= Array(cop_config.fetch('AllowedMethods', []))
end

def cop_config_deprecated_values
Array(cop_config['IgnoredMethods']).concat(Array(cop_config['ExcludedMethods']))
@cop_config_deprecated_values ||=
Array(cop_config.fetch('IgnoredMethods', [])) +
Array(cop_config.fetch('ExcludedMethods', []))
end
end
# @deprecated IgnoredMethods class has been replaced with AllowedMethods.
Expand Down
18 changes: 13 additions & 5 deletions lib/rubocop/cop/mixin/allowed_pattern.rb
Expand Up @@ -30,15 +30,23 @@ def matches_allowed_pattern?(line)
def allowed_patterns
# Since there could be a pattern specified in the default config, merge the two
# arrays together.
patterns = Array(cop_config['AllowedPatterns']).concat(Array(cop_config['IgnoredPatterns']))
deprecated_values = cop_config_deprecated_methods_values
return patterns unless deprecated_values.any?(Regexp)
if cop_config_deprecated_methods_values.any?(Regexp)
cop_config_patterns_values + cop_config_deprecated_methods_values
else
cop_config_patterns_values
end
end

Array(patterns.concat(deprecated_values))
def cop_config_patterns_values
@cop_config_patterns_values ||=
Array(cop_config.fetch('AllowedPatterns', [])) +
Array(cop_config.fetch('IgnoredPatterns', []))
end

def cop_config_deprecated_methods_values
Array(cop_config['IgnoredMethods']).concat(Array(cop_config['ExcludedMethods']))
@cop_config_deprecated_methods_values ||=
Array(cop_config.fetch('IgnoredMethods', [])) +
Array(cop_config.fetch('ExcludedMethods', []))
end
end

Expand Down
37 changes: 21 additions & 16 deletions spec/rubocop/cli/auto_gen_config_spec.rb
Expand Up @@ -951,29 +951,34 @@ def a; end
YAML
end

context 'when configurable parameter is an obsolete parameter' do
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a test added in #10875. However, this specification was incorrect. In fact, I think the cop_config was broken, causing duplicates to be displayed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it necessary to update the test as originally intended? I'm worried about losing a regression spec for #10875.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed it is. I will modify the test a bit and add it.

Copy link
Member Author

@ydah ydah Aug 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm. I've tried running the following test and it seems to fail.

Maybe there is some other problem.
Should we include the resolution of that issue as part of this PR?

    context 'when duplicated parameter' do
      it 'parameters are displayed without duplication' do
        create_file('.rubocop.yml', <<~YAML)
          AllCops:
            NewCops: enable
          Lint/AmbiguousBlockAssociation:
            AllowedMethods:
              - change
              - not_change
              - change
        YAML
        create_file('example1.rb', ['# frozen_string_literal: true', '', 'def fooBar; end'])
        create_file('example2.rb', ['# frozen_string_literal: true', '', 'def fooBar; end'])

        expect(cli.run(['--auto-gen-config'])).to eq(0)
        File.readlines('.rubocop_todo.yml')
        expect(File.readlines('.rubocop_todo.yml')[9..].join)
          .to eq(<<~YAML)
            # Configuration parameters: AllowedPatterns, IgnoredPatterns.
            # SupportedStyles: snake_case, camelCase
            # AllowedPatterns: change, not_change
            Naming/MethodName:
              EnforcedStyle: camelCase
          YAML
      end
    end
Failures:

  1) RuboCop::CLI --auto-gen-config --auto-gen-config when duplicated parameter parameters are displayed without duplication
     Failure/Error:
       expect(File.readlines('.rubocop_todo.yml')[9..].join)
         .to eq(<<~YAML)
           # Configuration parameters: AllowedPatterns, IgnoredPatterns.
           # SupportedStyles: snake_case, camelCase
           # AllowedPatterns: change, not_change
           Naming/MethodName:
             EnforcedStyle: camelCase
         YAML
     
       expected: "# Configuration parameters: AllowedPatterns, IgnoredPatterns.\n# SupportedStyles: snake_case, camelCase\n# AllowedPatterns: change, not_change\nNaming/MethodName:\n  EnforcedStyle: camelCase\n"
            got: "# Configuration parameters: AllowedPatterns, IgnoredPatterns.\n# SupportedStyles: snake_case, camelCase\nNaming/MethodName:\n  EnforcedStyle: camelCase\n"
     
       (compared using ==)
     
       Diff:
       @@ -1,6 +1,5 @@
        # Configuration parameters: AllowedPatterns, IgnoredPatterns.
        # SupportedStyles: snake_case, camelCase
       -# AllowedPatterns: change, not_change
        Naming/MethodName:
          EnforcedStyle: camelCase
       
     # ./spec/rubocop/cli/auto_gen_config_spec.rb:970:in `block (4 levels) in <top (required)>'
     # ./spec/support/cli_spec_behavior.rb:26:in `block (2 levels) in <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:30:in `block (4 levels) in <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:30:in `chdir'
     # ./lib/rubocop/rspec/shared_contexts.rb:30:in `block (3 levels) in <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:7:in `block (2 levels) in <top (required)>'

Finished in 7.11 seconds (files took 1.06 seconds to load)
40 examples, 1 failure

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like we need guarantees for existing behavior against performance regression solutions. I'm wondering whether another issue is included due to the test failing.

Copy link
Member Author

@ydah ydah Aug 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I would like to run the same test code on the old version to check the existing behavior first. Thank you.

Copy link
Member Author

@ydah ydah Aug 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted below, the display of this configuration value is the configuration value in config/default.yml and we have decided to modify the test.
#10953 (comment)

it 'displayed as a new parameter setting value without duplication' do
context 'when duplicated default configuration parameter' do
before do
RuboCop::ConfigLoader.default_configuration['Naming/MethodParameterName']
.merge!('AllowedNames' => %w[at by at])
end
Comment on lines +955 to +958
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The configuration values like # AllowedNames: at, by that appear in .rubocop_todo.yml were not configuration values in .rubocop.yml, but default values in config/defautl.yml.
However, what appeared to be the .rubocop.yml configuration values in #10875 . This was due to the default values being corrupted by the problem fixed in this PR.
Therefore, it was necessary to duplicate parameter the config/defautl.yml here.


it 'parameters are displayed without duplication' do
create_file('.rubocop.yml', <<~YAML)
AllCops:
NewCops: enable
Naming/MethodName:
# `IgnoredPatterns` is obsolete. `AllowedPatterns` is newly used.
IgnoredPatterns:
- change
- not_change
Naming/VariableName:
Enabled: false
YAML
create_file('example1.rb', ['# frozen_string_literal: true', '', 'def fooBar; end'])
create_file('example2.rb', ['# frozen_string_literal: true', '', 'def fooBar; end'])
create_file('example1.rb', <<~TEXT)
# frozen_string_literal: true

def bar(varOne, varTwo)
varOne + varTwo
end
TEXT

expect(cli.run(['--auto-gen-config'])).to eq(0)
File.readlines('.rubocop_todo.yml')
expect(File.readlines('.rubocop_todo.yml')[9..].join)
.to eq(<<~YAML)
# Configuration parameters: AllowedPatterns, IgnoredPatterns.
# SupportedStyles: snake_case, camelCase
# AllowedPatterns: change, not_change
Naming/MethodName:
EnforcedStyle: camelCase
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: at, by
Naming/MethodParameterName:
Exclude:
- 'example1.rb'
YAML
end
end
Expand Down