Exemple #1
0
def run_linter():
    print htmloutput.header('Running Google Closure Linter...')

    old_stdout = sys.stdout
    error_handler = errorprinter.ErrorPrinter(errors.NEW_ERRORS)
    error_handler.SetFormat(1)
    runner = checker.GJsLintRunner()

    # Hijack the stdout to capture the command output
    sys.stdout = mystdout = StringIO()

    # Run the linter
    result = runner.Run([
        os.environ['TM_FILEPATH'],
    ], error_handler)

    # Set the old stdout back
    sys.stdout = old_stdout

    # Reset the StringIO
    mystdout.seek(0)

    # Print the File Name
    first_line = mystdout.readline()
    print '<h3>%s</h3>' % first_line[first_line.find(':') + 2:-7]

    print '<pre>'
    for line in mystdout.readlines():
        sys.stdout.write(htmloutput.escape_for_html(line))
        sys.stdout.flush()
    print '</pre>'
    result.PrintSummary()
    print htmloutput.footer()
Exemple #2
0
def main(argv=None):
  """Main function.

  Args:
    argv: Sequence of command line arguments.
  """
  if argv is None:
    argv = sys.argv

  argv = flags.FLAGS(argv)

  if FLAGS.time:
    start_time = time.time()

  suffixes = ['.js']
  if FLAGS.additional_extensions:
    suffixes += ['.%s' % ext for ext in FLAGS.additional_extensions]
  if FLAGS.check_html:
    suffixes += ['.html', '.htm']
  files = fileflags.GetFileList(argv, 'JavaScript', suffixes)

  error_handler = None
  if FLAGS.unix_mode:
    error_handler = errorprinter.ErrorPrinter(errors.NEW_ERRORS)
    error_handler.SetFormat(errorprinter.UNIX_FORMAT)

  runner = checker.GJsLintRunner()
  result = runner.Run(files, error_handler)
  if FLAGS.summary:
    result.PrintSummary()

  exit_code = 0
  if result.HasOldErrors():
    exit_code += 1
  if result.HasNewErrors():
    exit_code += 2

  if exit_code:
    if FLAGS.summary:
      result.PrintFileSummary()

    if FLAGS.beep:
      # Make a beep noise.
      sys.stdout.write(chr(7))

  if FLAGS.time:
    print 'Done in %s.' % FormatTime(time.time() - start_time)

  return exit_code
Exemple #3
0
  def Run(self, filenames, error_handler=None):
    """Run GJsLint on the given filenames.

    Args:
      filenames: The filenames to check
      error_handler: An optional ErrorHandler object, an ErrorPrinter is used if
        none is specified.

    Returns:
      error_count, file_count: The number of errors and the number of files that
          contain errors.
    """
    if not error_handler:
      error_handler = errorprinter.ErrorPrinter(errors.NEW_ERRORS)

    checker = JavaScriptStyleChecker(error_handler)

    # Check the list of files.
    for filename in filenames:
      checker.Check(filename)

    return error_handler
Exemple #4
0
def main(argv=None):
    """Main function.

  Args:
    argv: Sequence of command line arguments.
  """
    if argv is None:
        argv = flags.FLAGS(sys.argv)

    if FLAGS.time:
        start_time = time.time()

    suffixes = ['.js']
    if FLAGS.check_html:
        suffixes += ['.html', '.htm']
    files = fileflags.GetFileList(argv, 'JavaScript', suffixes)

    error_handler = None
    if FLAGS.unix_mode:
        error_handler = errorprinter.ErrorPrinter(errors.NEW_ERRORS)
        error_handler.SetFormat(errorprinter.UNIX_FORMAT)

    runner = checker.GJsLintRunner()
    result = runner.Run(files, error_handler)
    result.PrintSummary()

    exit_code = 0
    if result.HasOldErrors():
        exit_code += 1
    if result.HasNewErrors():
        exit_code += 2

    if exit_code:
        if FLAGS.summary:
            result.PrintFileSummary()

        if FLAGS.beep:
            # Make a beep noise.
            sys.stdout.write(chr(7))

        # Write out instructions for using fixjsstyle script to fix some of the
        # reported errors.
        fix_args = []
        for flag in sys.argv[1:]:
            for f in GJSLINT_ONLY_FLAGS:
                if flag.startswith(f):
                    break
            else:
                fix_args.append(flag)

        print """
Some of the errors reported by GJsLint may be auto-fixable using the script
fixjsstyle. Please double check any changes it makes and report any bugs. The
script can be run by executing:

fixjsstyle %s
""" % ' '.join(fix_args)

    if FLAGS.time:
        print 'Done in %s.' % FormatTime(time.time() - start_time)

    sys.exit(exit_code)