jsxhint.js
function transformJSX(fileStream, fileName, opts, cb){

  // Allow omitting filename
  if (typeof fileName === "object"){
    cb = opts;
    opts = fileName;
    fileName = fileStream;
  }

  if (!babel && (opts['--babel'] || opts['--babel-experimental'])) {
    throw new Error("Optional babel parser not installed. Please `npm install [-g] babel-core`.");
  }

  // Allow passing strings into this method e.g. when using it as a lib
  if (typeof fileStream === "string"){
    fileStream = fs.createReadStream(fileStream, {encoding: "utf8"});
  }

  return utils.drainStream(fileStream)
  .then(function processFile(source) {
    var hasExtension = /\.jsx$/.exec(fileName) || fileName === "stdin";
    // console.error('has extension', hasExtension);
    // console.log(fileName);
    if ((opts['--jsx-only'] && hasExtension) || !opts['--jsx-only']) {
      try {
        return transformSource(source, opts);
      } catch(e) {
        // Seems that esprima has some problems with some js syntax.
        if (opts['--transform-errors'] === 'always' ||
            (opts['--transform-errors'] !== 'never' && hasExtension)) {
          console.error("Error while transforming file " + fileName + "\n", e.stack);
          throw utils.transformError(fileName, e, opts);
        }
      }
    }
    return source;
  })
  .nodeify(cb);
}
function transformJSX(fileStream, fileName, opts, cb){

  // Allow omitting filename
  if (typeof fileName === "object"){
    cb = opts;
    opts = fileName;
    fileName = fileStream;
  }

  if (!babel && (opts['--babel'] || opts['--babel-experimental'])) {
    throw new Error("Optional babel parser not installed. Please `npm install [-g] babel-core`.");
  }

  // Allow passing strings into this method e.g. when using it as a lib
  if (typeof fileStream === "string"){
    fileStream = fs.createReadStream(fileStream, {encoding: "utf8"});
  }

  return utils.drainStream(fileStream)
  .then(function processFile(source) {
    var hasExtension = /\.jsx$/.exec(fileName) || fileName === "stdin";
    // console.error('has extension', hasExtension);
    // console.log(fileName);
    if ((opts['--jsx-only'] && hasExtension) || !opts['--jsx-only']) {
      try {
        return transformSource(source, opts);
      } catch(e) {
        // Seems that esprima has some problems with some js syntax.
        if (opts['--transform-errors'] === 'always' ||
            (opts['--transform-errors'] !== 'never' && hasExtension)) {
          console.error("Error while transforming file " + fileName + "\n", e.stack);
          throw utils.transformError(fileName, e, opts);
        }
      }
    }
    return source;
  })
  .nodeify(cb);
}
function transformJSX ( fileStream , fileName , opts , cb ) { // Allow omitting filename if ( typeof fileName === "object" ) { cb = opts ; opts = fileName ; fileName = fileStream ; } if ( ! babel && ( opts [ '--babel' ] || opts [ '--babel-experimental' ] ) ) { throw new Error ( "Optional babel parser not installed. Please `npm install [-g] babel-core`." ) ; } // Allow passing strings into this method e.g. when using it as a lib if ( typeof fileStream === "string" ) { fileStream = fs . createReadStream ( fileStream , { encoding : "utf8" } ) ; } return utils . drainStream ( fileStream ) . then ( function processFile ( source ) { var hasExtension = / \.jsx$ / . exec ( fileName ) || fileName === "stdin" ; // console.error('has extension', hasExtension); // console.log(fileName); if ( ( opts [ '--jsx-only' ] && hasExtension ) || ! opts [ '--jsx-only' ] ) { try { return transformSource ( source , opts ) ; } catch ( e ) { // Seems that esprima has some problems with some js syntax. if ( opts [ '--transform-errors' ] === 'always' || ( opts [ '--transform-errors' ] !== 'never' && hasExtension ) ) { console . error ( "Error while transforming file " + fileName + "\n" , e . stack ) ; throw utils . transformError ( fileName , e , opts ) ; } } } return source ; } ) . nodeify ( cb ) ; }
Transform a JSX file into a JS file for linting.
@async
@param  {String}   fileStream Readable stream containing file contents.
@param  {String}   fileName   Name of the file; "stdin" if reading from stdio.
@param  {Object}   opts       Options.
@param  {Function} cb         The callback to call when it's ready.
Transform a JSX file into a JS file for linting .