def main(argv=None): """Main function. Args: argv: Sequence of command line arguments. """ if argv is None: argv = flags.FLAGS(sys.argv) suffixes = ['.js'] if FLAGS.additional_extensions: suffixes += ['.%s' % ext for ext in FLAGS.additional_extensions] files = fileflags.GetFileList(argv, 'JavaScript', suffixes) output_buffer = None if FLAGS.dry_run: output_buffer = StringIO.StringIO() fixer = error_fixer.ErrorFixer(output_buffer) # Check the list of files. for filename in files: runner.Run(filename, fixer) if FLAGS.dry_run: print output_buffer.getvalue()
def _GetFilePaths(argv): suffixes = ['.js'] if FLAGS.additional_extensions: suffixes += ['.%s' % ext for ext in FLAGS.additional_extensions] if FLAGS.check_html: suffixes += ['.html', '.htm'] return fileflags.GetFileList(argv, 'JavaScript', suffixes)
def main(argv=None): """Main function. Args: argv: Sequence of command line arguments. """ if argv is None: argv = flags.FLAGS(sys.argv) suffixes = ['.js', '.k', '.kl', '.htm', '.html'] if FLAGS.additional_extensions: suffixes += ['.%s' % ext for ext in FLAGS.additional_extensions] files = fileflags.GetFileList(argv, 'JavaScript', suffixes) style_checker = checker.JavaScriptStyleChecker(error_fixer.ErrorFixer()) # Check the list of files. for filename in files: # if we have a js file if (filename.endswith('.js') or filename.endswith('.k') or filename.endswith('.kl')): style_checker.Check(filename) else: # HM: extract the js code from the html page, # run it through the checker, and composite the page again lines = open(filename).read().split('\n') insidejscode = 0 htmlprev = [] htmlpost = [] jscode = [] for line in lines: stripline = line.strip().lower() if (stripline.startswith('<')): stripline = stripline[1:10000].strip() if (insidejscode == 0): htmlprev.append(line) if (stripline.startswith('script') and stripline.find('src') == -1): insidejscode = 1 elif (insidejscode == 1): if (stripline.startswith('/') and stripline[1:10000].strip().startswith('script')): insidejscode = 2 htmlpost.append(line) else: jscode.append(line) else: htmlpost.append(line) jscode = '\n'.join(jscode) open(filename + '.tmp.js', 'w').write(jscode) style_checker.Check(filename + '.tmp.js') jscode = open(filename + '.tmp.js').read() htmlcode = '\n'.join(htmlprev) + '\n' + jscode + '\n' + '\n'.join( htmlpost) open(filename, 'w').write(htmlcode) os.remove(filename + '.tmp.js')
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.additional_extensions: suffixes += ['.%s' % ext for ext in FLAGS.additional_extensions] if FLAGS.check_html: suffixes += ['.html', '.htm'] paths = fileflags.GetFileList(argv, 'JavaScript', suffixes) if FLAGS.multiprocess: records_iter = _MultiprocessCheckPaths(paths) else: records_iter = _CheckPaths(paths) records_iter, records_iter_copy = itertools.tee(records_iter, 2) _PrintErrorRecords(records_iter_copy) error_records = list(records_iter) _PrintSummary(paths, error_records) exit_code = 0 # If there are any errors if error_records: exit_code += 1 # If there are any new errors if [r for r in error_records if r.new_error]: exit_code += 2 if exit_code: if FLAGS.summary: _PrintFileSummary(paths, error_records) if FLAGS.beep: # Make a beep noise. sys.stdout.write(chr(7)) if FLAGS.time: print 'Done in %s.' % _FormatTime(time.time() - start_time) sys.exit(exit_code)
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) files = fileflags.GetFileList(argv, 'JavaScript', ['.js']) style_checker = checker.JavaScriptStyleChecker(error_fixer.ErrorFixer()) # Check the list of files. for filename in files: style_checker.Check(filename)
def main(argv=None): """Main function. Args: argv: Sequence of command line arguments. """ if argv is None: argv = flags.FLAGS(sys.argv) suffixes = ['.js'] if FLAGS.additional_extensions: suffixes += ['.%s' % ext for ext in FLAGS.additional_extensions] files = fileflags.GetFileList(argv, 'JavaScript', suffixes) style_checker = checker.JavaScriptStyleChecker(error_fixer.ErrorFixer()) # Check the list of files. for filename in files: style_checker.Check(filename)
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.additional_extensions: suffixes += ['.%s' % ext for ext in FLAGS.additional_extensions] if FLAGS.check_html: suffixes += ['.html', '.htm'] paths = fileflags.GetFileList(argv, 'JavaScript', suffixes) if FLAGS.multiprocess: records_iter = _MultiprocessCheckPaths(paths) else: records_iter = _CheckPaths(paths) records_iter, records_iter_copy = itertools.tee(records_iter, 2) _PrintErrorRecords(records_iter_copy) error_records = list(records_iter) _PrintSummary(paths, error_records) exit_code = 0 # If there are any errors if error_records: exit_code += 1 # If there are any new errors if [r for r in error_records if r.new_error]: exit_code += 2 if exit_code: if FLAGS.summary: _PrintFileSummary(paths, error_records) 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)
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() # Emacs sets the environment variable INSIDE_EMACS in the subshell. # Request Unix mode as emacs will expect output to be in Unix format # for integration. # See https://www.gnu.org/software/emacs/manual/html_node/emacs/ # Interactive-Shell.html if 'INSIDE_EMACS' in os.environ: FLAGS.unix_mode = True suffixes = ['.js'] if FLAGS.additional_extensions: suffixes += ['.%s' % ext for ext in FLAGS.additional_extensions] if FLAGS.check_html: suffixes += ['.html', '.htm'] paths = fileflags.GetFileList(argv, 'JavaScript', suffixes) if FLAGS.multiprocess: records_iter = _MultiprocessCheckPaths(paths) else: records_iter = _CheckPaths(paths) records_iter, records_iter_copy = itertools.tee(records_iter, 2) _PrintErrorRecords(records_iter_copy) error_records = list(records_iter) _PrintSummary(paths, error_records) exit_code = 0 # If there are any errors if error_records: exit_code += 1 # If there are any new errors if [r for r in error_records if r.new_error]: exit_code += 2 if exit_code: if FLAGS.summary: _PrintFileSummary(paths, error_records) 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) if not FLAGS.quiet: 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)
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)