lib/config.js
function loadConfig(configToLoad) {
  var config = {};
  var filePath = '';

  if (configToLoad) {

    if (isObject(configToLoad)) {
      config = configToLoad;
    } else {
      filePath = configToLoad;
      config = readConfigFromFile(filePath);
    }

    if (!config.rules) {
      config.rules = {};
    }
    config.rules = Object.keys(config.rules).reduce(function(obj, ruleId) {
      if (!Array.isArray(config.rules[ruleId])) {
        obj[ruleId] = [config.rules[ruleId]];
      }
      return obj;
    }, {});

    validator.validate(config, filePath);

        // If an `extends` property is defined, it represents a configuration file to use as
        // a 'parent'. Load the referenced file and merge the configuration recursively.
    if (config.extends) {
      var configExtends = config.extends;

      if (!Array.isArray(config.extends)) {
        configExtends = [config.extends];
      }

            // Make the last element in an array take the highest precedence
      config = configExtends.reduceRight(function(previousValue, parentPath) {

        if (parentPath === 'nplint:recommended') {
                    // Add an explicit substitution for eslint:recommended to conf/eslint.json
                    // this lets us use the eslint.json file as the recommended rules
          parentPath = path.resolve(__dirname, '../conf/nplint.json');
        } else if (isFilePath(parentPath)) {
                  // If the `extends` path is relative, use the directory of the current configuration
                  // file as the reference point. Otherwise, use as-is.
          parentPath = (!isAbsolutePath(parentPath) ?
                    path.join(path.dirname(filePath), parentPath) :
                    parentPath
                );
        }

        try {
          return util.mergeConfigs(loadConfig(parentPath), previousValue);
        } catch (e) {
                  // If the file referenced by `extends` failed to load, add the path to the
                  // configuration file that referenced it to the error message so the user is
                  // able to see where it was referenced from, then re-throw
          e.message += '\nReferenced from: ' + filePath;
          throw e;
        }

      }, config);

    }

  }

  return config;
}
function loadConfig(configToLoad) {
  var config = {};
  var filePath = '';

  if (configToLoad) {

    if (isObject(configToLoad)) {
      config = configToLoad;
    } else {
      filePath = configToLoad;
      config = readConfigFromFile(filePath);
    }

    if (!config.rules) {
      config.rules = {};
    }
    config.rules = Object.keys(config.rules).reduce(function(obj, ruleId) {
      if (!Array.isArray(config.rules[ruleId])) {
        obj[ruleId] = [config.rules[ruleId]];
      }
      return obj;
    }, {});

    validator.validate(config, filePath);

        // If an `extends` property is defined, it represents a configuration file to use as
        // a 'parent'. Load the referenced file and merge the configuration recursively.
    if (config.extends) {
      var configExtends = config.extends;

      if (!Array.isArray(config.extends)) {
        configExtends = [config.extends];
      }

            // Make the last element in an array take the highest precedence
      config = configExtends.reduceRight(function(previousValue, parentPath) {

        if (parentPath === 'nplint:recommended') {
                    // Add an explicit substitution for eslint:recommended to conf/eslint.json
                    // this lets us use the eslint.json file as the recommended rules
          parentPath = path.resolve(__dirname, '../conf/nplint.json');
        } else if (isFilePath(parentPath)) {
                  // If the `extends` path is relative, use the directory of the current configuration
                  // file as the reference point. Otherwise, use as-is.
          parentPath = (!isAbsolutePath(parentPath) ?
                    path.join(path.dirname(filePath), parentPath) :
                    parentPath
                );
        }

        try {
          return util.mergeConfigs(loadConfig(parentPath), previousValue);
        } catch (e) {
                  // If the file referenced by `extends` failed to load, add the path to the
                  // configuration file that referenced it to the error message so the user is
                  // able to see where it was referenced from, then re-throw
          e.message += '\nReferenced from: ' + filePath;
          throw e;
        }

      }, config);

    }

  }

  return config;
}
function loadConfig ( configToLoad ) { var config = { } ; var filePath = '' ; if ( configToLoad ) { if ( isObject ( configToLoad ) ) { config = configToLoad ; } else { filePath = configToLoad ; config = readConfigFromFile ( filePath ) ; } if ( ! config . rules ) { config . rules = { } ; } config . rules = Object . keys ( config . rules ) . reduce ( function ( obj , ruleId ) { if ( ! Array . isArray ( config . rules [ ruleId ] ) ) { obj [ ruleId ] = [ config . rules [ ruleId ] ] ; } return obj ; } , { } ) ; validator . validate ( config , filePath ) ; // If an `extends` property is defined, it represents a configuration file to use as // a 'parent'. Load the referenced file and merge the configuration recursively. if ( config . extends ) { var configExtends = config . extends ; if ( ! Array . isArray ( config . extends ) ) { configExtends = [ config . extends ] ; } // Make the last element in an array take the highest precedence config = configExtends . reduceRight ( function ( previousValue , parentPath ) { if ( parentPath === 'nplint:recommended' ) { // Add an explicit substitution for eslint:recommended to conf/eslint.json // this lets us use the eslint.json file as the recommended rules parentPath = path . resolve ( __dirname , '../conf/nplint.json' ) ; } else if ( isFilePath ( parentPath ) ) { // If the `extends` path is relative, use the directory of the current configuration // file as the reference point. Otherwise, use as-is. parentPath = ( ! isAbsolutePath ( parentPath ) ? path . join ( path . dirname ( filePath ) , parentPath ) : parentPath ) ; } try { return util . mergeConfigs ( loadConfig ( parentPath ) , previousValue ) ; } catch ( e ) { // If the file referenced by `extends` failed to load, add the path to the // configuration file that referenced it to the error message so the user is // able to see where it was referenced from, then re-throw e . message += '\nReferenced from: ' + filePath ; throw e ; } } , config ) ; } } return config ; }
Load and parse a JSON config object from a file.
@param {string|Object} configToLoad the path to the JSON config file or the config object itself.
@returns {Object} the parsed config object (empty object if there was a parse error)
@private
Load and parse a JSON config object from a file .