eslint-plugin/gather-fragment-imports-for-context.js
/**
 * Wrapper function to setup most parameters from the context object to call gatherFragmentImports.
 *
 * @param {object} context - Context object that was passed to the `create` function of an eslint rule
 * @param {boolean} throwIfImportNotFound - If set to true, throws error if import not found
 * @returns {Map<number, Map<string, Object>>}
 */
Wrapper function to setup most parameters from the context object to call gatherFragmentImports.
@param {object} context - Context object that was passed to the `create` function of an eslint rule
@param {boolean} throwIfImportNotFound - If set to true, throws error if import not found
@returns {Map>}
Wrapper function to setup most parameters from the context object to call gatherFragmentImports . @param { object } context - Context object that was passed to the ` create ` function of an eslint rule @param { boolean } throwIfImportNotFound - If set to true throws error if import not found @returns { Map > }
function gatherFragmentImportsForContext(context, throwIfImportNotFound) {
  let resolveImport;
  let importResolver =
    Array.isArray(context.options) &&
    context.options.length > 0 &&
    context.options[0].importResolver;
  if (typeof importResolver === 'string') {
    if (!path.isAbsolute(importResolver)) {
      throw new Error(`Option "importResolver" must be an absolute path, not "${importResolver}"`);
    }
    resolveImport = require(importResolver);
  } else {
    resolveImport = require('resolve').sync;
  }
  return gatherFragmentImports({
    source: context.getSourceCode().text,
    sourceLocation: context.getFilename(),
    resolveImport,
    fragmentParserGenerator: context.parserServices.getFragmentDefinitionsFromSource,
    throwIfImportNotFound,
  });
}
function gatherFragmentImportsForContext ( context , throwIfImportNotFound ) { let resolveImport ; let importResolver = Array . isArray ( context . options ) && context . options . length > 0 && context . options [ 0 ] . importResolver ; if ( typeof importResolver === 'string' ) { if ( ! path . isAbsolute ( importResolver ) ) { throw new Error ( ` ${ importResolver } ` ) ; } resolveImport = require ( importResolver ) ; } else { resolveImport = require ( 'resolve' ) . sync ; } return gatherFragmentImports ( { source : context . getSourceCode ( ) . text , sourceLocation : context . getFilename ( ) , resolveImport , fragmentParserGenerator : context . parserServices . getFragmentDefinitionsFromSource , throwIfImportNotFound , } ) ; }
Wrapper function to setup most parameters from the context object to call gatherFragmentImports.
Wrapper function to setup most parameters from the context object to call gatherFragmentImports .