lib/overcommit/configuration_validator.rb in overcommit-0.31.0 vs lib/overcommit/configuration_validator.rb in overcommit-0.32.0.rc1
- old
+ new
@@ -1,23 +1,25 @@
module Overcommit
# Validates and normalizes a configuration.
class ConfigurationValidator
# Validates hash for any invalid options, normalizing where possible.
#
+ # @param config [Overcommit::Configuration]
# @param hash [Hash] hash representation of YAML config
# @param options[Hash]
# @option default [Boolean] whether hash represents the default built-in config
# @option logger [Overcommit::Logger] logger to output warnings to
# @return [Hash] validated hash (potentially modified)
- def validate(hash, options)
+ def validate(config, hash, options)
@options = options.dup
@log = options[:logger]
hash = convert_nils_to_empty_hashes(hash)
ensure_hook_type_sections_exist(hash)
check_hook_name_format(hash)
check_for_missing_enabled_option(hash) unless @options[:default]
+ check_for_too_many_processors(config, hash)
check_for_verify_plugin_signatures_option(hash)
hash
end
@@ -92,9 +94,34 @@
end
end
end
@log.newline if any_warnings
+ end
+
+ # Prints a warning if any hook has a number of processors larger than the
+ # global `concurrency` setting.
+ def check_for_too_many_processors(config, hash)
+ concurrency = config.concurrency
+
+ errors = []
+ Overcommit::Utils.supported_hook_type_classes.each do |hook_type|
+ hash.fetch(hook_type, {}).each do |hook_name, hook_config|
+ processors = hook_config.fetch('processors', 1)
+ if processors > concurrency
+ errors << "#{hook_type}::#{hook_name} `processors` value " \
+ "(#{processors}) is larger than the global `concurrency` " \
+ "option (#{concurrency})"
+ end
+ end
+ end
+
+ if errors.any?
+ @log.error errors.join("\n") if @log
+ @log.newline if @log
+ raise Overcommit::Exceptions::ConfigurationError,
+ 'One or more hooks had invalid `processor` value configured'
+ end
end
# Prints a warning if the `verify_plugin_signatures` option is used instead
# of the new `verify_signatures` option.
def check_for_verify_plugin_signatures_option(hash)