lib/overcommit/configuration_validator.rb
# 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)
Validates hash for any invalid options, normalizing where possible.
Validates hash for any invalid options normalizing where possible .
def check_hook_env(hash)
      errors = []
      Overcommit::Utils.supported_hook_type_classes.each do |hook_type|
        hash.fetch(hook_type) { {} }.each do |hook_name, hook_config|
          hook_env = hook_config.fetch('env') { {} }
          unless hook_env.is_a?(Hash)
            errors << "#{hook_type}::#{hook_name} has an invalid `env` specified: " \
                      'must be a hash of environment variable name to string value.'
            next
          end
          hook_env.each do |var_name, var_value|
            if var_name.include?('=')
              errors << "#{hook_type}::#{hook_name} has an invalid `env` specified: " \
                        "variable name `#{var_name}` cannot contain `=`."
            end
            unless var_value.nil? || var_value.is_a?(String)
              errors << "#{hook_type}::#{hook_name} has an invalid `env` specified: " \
                        "value of `#{var_name}` must be a string or `nil`, but was " \
                        "#{var_value.inspect} (#{var_value.class})"
            end
          end
        end
      end
      if errors.any?
        if @log
          @log.error errors.join("\n")
          @log.newline
        end
        raise Overcommit::Exceptions::ConfigurationError,
              'One or more hooks had an invalid `env` configuration option'
      end
    end
def check_hook_env ( hash ) errors = [ ] Overcommit :: Utils . supported_hook_type_classes . each do | hook_type | hash . fetch ( hook_type ) { { } } . each do | hook_name , hook_config | hook_env = hook_config . fetch ( 'env' ) { { } } unless hook_env . is_a? ( Hash ) errors << "#{hook_type}::#{hook_name} has an invalid `env` specified: " 'must be a hash of environment variable name to string value.' next end hook_env . each do | var_name , var_value | if var_name . include? ( '=' ) errors << "#{hook_type}::#{hook_name} has an invalid `env` specified: " "variable name `#{var_name}` cannot contain `=`." end unless var_value . nil? || var_value . is_a? ( String ) errors << "#{hook_type}::#{hook_name} has an invalid `env` specified: " "value of `#{var_name}` must be a string or `nil`, but was " "#{var_value.inspect} (#{var_value.class})" end end end end if errors . any? if @log @log . error errors . join ( "\n" ) @log . newline end raise Overcommit :: Exceptions :: ConfigurationError , 'One or more hooks had an invalid `env` configuration option' end end
Validates hash for any invalid options, normalizing where possible.
Validates hash for any invalid options normalizing where possible .
validated hash (potentially modified)
validated hash ( potentially modified )
Hash
hash
hash representation of YAML config
hash representation of YAML config
<not_specific>
None
default
<not_specific>
whether hash represents the default built-in config
whether hash represents the default built - in config
logger
<not_specific>
logger to output warnings to
logger to output warnings to