Skip to content

Commit

Permalink
Update RuboCop/Performance
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre committed Oct 16, 2020
1 parent 7f57dc4 commit 972401c
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .rubocop.yml
Expand Up @@ -130,3 +130,8 @@ RSpec/EmptyExampleGroup:
- 'spec/rubocop/cop/lint/script_permission_spec.rb'
- 'spec/rubocop/cop/style/empty_else_spec.rb'
- 'spec/rubocop/result_cache_spec.rb'

Performance/CollectionLiteralInLoop:
Exclude:
- 'Rakefile'
- 'spec/**/*.rb'
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -9,7 +9,7 @@ gem 'memory_profiler', platform: :mri
gem 'pry'
gem 'rake', '~> 13.0'
gem 'rspec', '~> 3.7'
gem 'rubocop-performance', '~> 1.7.0'
gem 'rubocop-performance', '~> 1.8.1'
gem 'rubocop-rspec', '~> 1.43.2'
# Workaround for cc-test-reporter with SimpleCov 0.18.
# Stop upgrading SimpleCov until the following issue will be resolved.
Expand Down
13 changes: 7 additions & 6 deletions lib/rubocop/config_validator.rb
Expand Up @@ -18,6 +18,11 @@ class ConfigValidator
# @api private
NEW_COPS_VALUES = %w[pending disable enable].freeze

# @api private
CONFIG_CHECK_KEYS = %w[Enabled Safe SafeAutoCorrect AutoCorrect].to_set.freeze
CONFIG_CHECK_DEPARTMENTS = %w[pending override_department].freeze
private_constant :CONFIG_CHECK_KEYS, :CONFIG_CHECK_DEPARTMENTS

def_delegators :@config, :smart_loaded_path, :for_all_cops

def initialize(config)
Expand Down Expand Up @@ -202,13 +207,9 @@ def check_cop_config_value(hash, parent = nil)
hash.each do |key, value|
check_cop_config_value(value, key) if value.is_a?(Hash)

next unless %w[Enabled
Safe
SafeAutoCorrect
AutoCorrect].include?(key) && value.is_a?(String)
next unless CONFIG_CHECK_KEYS.include?(key) && value.is_a?(String)

next if key == 'Enabled' &&
%w[pending override_department].include?(value)
next if key == 'Enabled' && CONFIG_CHECK_DEPARTMENTS.include?(value)

raise ValidationError, msg_not_boolean(parent, key, value)
end
Expand Down
5 changes: 4 additions & 1 deletion lib/rubocop/cop/metrics/parameter_lists.rb
Expand Up @@ -12,6 +12,9 @@ class ParameterLists < Base
MSG = 'Avoid parameter lists longer than %<max>d parameters. ' \
'[%<count>d/%<max>d]'

NAMED_KEYWORD_TYPES = %i[kwoptarg kwarg].freeze
private_constant :NAMED_KEYWORD_TYPES

def on_args(node)
count = args_count(node)
return unless count > max_params
Expand All @@ -33,7 +36,7 @@ def args_count(node)
if count_keyword_args?
node.children.size
else
node.children.count { |a| !%i[kwoptarg kwarg].include?(a.type) }
node.children.count { |a| !NAMED_KEYWORD_TYPES.include?(a.type) }
end
end

Expand Down
4 changes: 3 additions & 1 deletion lib/rubocop/cop/style/trailing_underscore_variable.rb
Expand Up @@ -36,6 +36,8 @@ class TrailingUnderscoreVariable < Base
MSG = 'Do not use trailing `_`s in parallel assignment. ' \
'Prefer `%<code>s`.'
UNDERSCORE = '_'
DISALLOW = %i[lvasgn splat].freeze
private_constant :DISALLOW

def on_masgn(node)
ranges = unneeded_ranges(node)
Expand Down Expand Up @@ -64,7 +66,7 @@ def find_first_offense(variables)

def find_first_possible_offense(variables)
variables.reduce(nil) do |offense, variable|
break offense unless %i[lvasgn splat].include?(variable.type)
break offense unless DISALLOW.include?(variable.type)

var, = *variable
var, = *var
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/formatter/offense_count_formatter.rb
Expand Up @@ -67,7 +67,7 @@ def ordered_offense_counts(offense_counts)
end

def total_offense_count(offense_counts)
offense_counts.values.inject(0, :+)
offense_counts.values.sum
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/formatter/worst_offenders_formatter.rb
Expand Up @@ -55,7 +55,7 @@ def ordered_offense_counts(offense_counts)
end

def total_offense_count(offense_counts)
offense_counts.values.inject(0, :+)
offense_counts.values.sum
end
end
end
Expand Down
5 changes: 4 additions & 1 deletion lib/rubocop/options.rb
Expand Up @@ -242,6 +242,9 @@ def long_opt_symbol(args)
# @api private
class OptionsValidator
class << self
SYNTAX_DEPARTMENTS = %w[Syntax Lint/Syntax].freeze
private_constant :SYNTAX_DEPARTMENTS

# Cop name validation must be done later than option parsing, so it's not
# called from within Options.
def validate_cop_list(names)
Expand All @@ -253,7 +256,7 @@ def validate_cop_list(names)
names.each do |name|
next if cop_names.include?(name)
next if departments.include?(name)
next if %w[Syntax Lint/Syntax].include?(name)
next if SYNTAX_DEPARTMENTS.include?(name)

raise IncorrectCopNameError, format_message_from(name, cop_names)
end
Expand Down

0 comments on commit 972401c

Please sign in to comment.