src/getConfig.js
function validateConfig(config) {
  debug('Validating config')

  const deprecatedConfig = {
    gitDir: "lint-staged now automatically resolves '.git' directory.",
    verbose: `Use the command line flag ${chalk.bold('--debug')} instead.`
  }

  const errors = []

  try {
    schema.validateSync(config, { abortEarly: false, strict: true })
  } catch (error) {
    error.errors.forEach(message => errors.push(formatError(message)))
  }

  if (isObject(config.linters)) {
    Object.keys(config.linters).forEach(key => {
      if (
        (!isArray(config.linters[key]) || config.linters[key].some(item => !isString(item))) &&
        !isString(config.linters[key])
      ) {
        errors.push(
          createError(`linters[${key}]`, 'Should be a string or an array of strings', key)
        )
      }
    })
  }

  Object.keys(config)
    .filter(key => !defaultConfig.hasOwnProperty(key))
    .forEach(option => {
      if (deprecatedConfig.hasOwnProperty(option)) {
        logDeprecation(option, deprecatedConfig[option])
        return
      }

      unknownValidationReporter(config, option)
    })

  if (errors.length) {
    throw new Error(errors.join('\n'))
  }

  return config
}
function validateConfig(config) {
  debug('Validating config')

  const deprecatedConfig = {
    gitDir: "lint-staged now automatically resolves '.git' directory.",
    verbose: `Use the command line flag ${chalk.bold('--debug')} instead.`
  }

  const errors = []

  try {
    schema.validateSync(config, { abortEarly: false, strict: true })
  } catch (error) {
    error.errors.forEach(message => errors.push(formatError(message)))
  }

  if (isObject(config.linters)) {
    Object.keys(config.linters).forEach(key => {
      if (
        (!isArray(config.linters[key]) || config.linters[key].some(item => !isString(item))) &&
        !isString(config.linters[key])
      ) {
        errors.push(
          createError(`linters[${key}]`, 'Should be a string or an array of strings', key)
        )
      }
    })
  }

  Object.keys(config)
    .filter(key => !defaultConfig.hasOwnProperty(key))
    .forEach(option => {
      if (deprecatedConfig.hasOwnProperty(option)) {
        logDeprecation(option, deprecatedConfig[option])
        return
      }

      unknownValidationReporter(config, option)
    })

  if (errors.length) {
    throw new Error(errors.join('\n'))
  }

  return config
}
function validateConfig ( config ) { debug ( 'Validating config' ) const deprecatedConfig = { gitDir : "lint-staged now automatically resolves '.git' directory." , verbose : ` ${ chalk . bold ( '--debug' ) } ` } const errors = [ ] try { schema . validateSync ( config , { abortEarly : false , strict : true } ) } catch ( error ) { error . errors . forEach ( message => errors . push ( formatError ( message ) ) ) } if ( isObject ( config . linters ) ) { Object . keys ( config . linters ) . forEach ( key => { if ( ( ! isArray ( config . linters [ key ] ) || config . linters [ key ] . some ( item => ! isString ( item ) ) ) && ! isString ( config . linters [ key ] ) ) { errors . push ( createError ( ` ${ key } ` , 'Should be a string or an array of strings' , key ) ) } } ) } Object . keys ( config ) . filter ( key => ! defaultConfig . hasOwnProperty ( key ) ) . forEach ( option => { if ( deprecatedConfig . hasOwnProperty ( option ) ) { logDeprecation ( option , deprecatedConfig [ option ] ) return } unknownValidationReporter ( config , option ) } ) if ( errors . length ) { throw new Error ( errors . join ( '\n' ) ) } return config }
Runs config validation. Throws error if the config is not valid.
@param config {Object}
@returns config {Object}
Runs config validation . Throws error if the config is not valid .