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()
def __init__(self, tests=()): unittest.TestSuite.__init__(self, tests) argv = sys.argv and sys.argv[1:] or [] if argv: test_files = argv else: test_files = _TEST_FILES for test_file in test_files: resource_path = os.path.join(_RESOURCE_PREFIX, test_file) self.addTest( filetestcase.AnnotatedFileTestCase(resource_path, checker.GJsLintRunner(), errors.ByName))
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
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)