| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Runs Closure compiler on a JavaScript file to check for errors.""" | 6 """Runs Closure compiler on a JavaScript file to check for errors.""" |
| 7 | 7 |
| 8 import argparse | 8 import argparse |
| 9 import os | 9 import os |
| 10 import re | 10 import re |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 real_file = self._processor.get_file_from_line(match.group(1)) | 131 real_file = self._processor.get_file_from_line(match.group(1)) |
| 132 return "%s:%d" % (os.path.abspath(real_file.file), real_file.line_number) | 132 return "%s:%d" % (os.path.abspath(real_file.file), real_file.line_number) |
| 133 | 133 |
| 134 def _fix_up_error(self, error): | 134 def _fix_up_error(self, error): |
| 135 """Filter out irrelevant errors or fix line numbers. | 135 """Filter out irrelevant errors or fix line numbers. |
| 136 | 136 |
| 137 Args: | 137 Args: |
| 138 error: A Closure compiler error (2 line string with error and source). | 138 error: A Closure compiler error (2 line string with error and source). |
| 139 | 139 |
| 140 Return: | 140 Return: |
| 141 The fixed up erorr string (blank if it should be ignored). | 141 The fixed up error string (blank if it should be ignored). |
| 142 """ | 142 """ |
| 143 if " first declared in " in error: | 143 if " first declared in " in error: |
| 144 # Ignore "Variable x first declared in /same/file". | 144 # Ignore "Variable x first declared in /same/file". |
| 145 return "" | 145 return "" |
| 146 | 146 |
| 147 expanded_file = self._expanded_file | 147 expanded_file = self._expanded_file |
| 148 fixed = re.sub("%s:(\d+)" % expanded_file, self._fix_line_number, error) | 148 fixed = re.sub("%s:(\d+)" % expanded_file, self._fix_line_number, error) |
| 149 return fixed.replace(expanded_file, os.path.abspath(self._file_arg)) | 149 return fixed.replace(expanded_file, os.path.abspath(self._file_arg)) |
| 150 | 150 |
| 151 def _format_errors(self, errors): | 151 def _format_errors(self, errors): |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 errors = stderr.strip().split("\n\n") | 214 errors = stderr.strip().split("\n\n") |
| 215 | 215 |
| 216 # Filter out false-positive promise chain errors. | 216 # Filter out false-positive promise chain errors. |
| 217 # See https://github.com/google/closure-compiler/issues/715 for details. | 217 # See https://github.com/google/closure-compiler/issues/715 for details. |
| 218 errors = self._error_filter.filter(errors); | 218 errors = self._error_filter.filter(errors); |
| 219 | 219 |
| 220 self._debug("Summary: %s" % errors.pop()) | 220 self._debug("Summary: %s" % errors.pop()) |
| 221 | 221 |
| 222 output = self._format_errors(map(self._fix_up_error, errors)) | 222 output = self._format_errors(map(self._fix_up_error, errors)) |
| 223 if errors: | 223 if errors: |
| 224 self._error("Error in: %s%s" % (source_file, "\n" + output if output else
"")) | 224 prefix = "\n" if output else "" |
| 225 self._error("Error in: %s%s%s" % (source_file, prefix, output)) |
| 225 elif output: | 226 elif output: |
| 226 self._debug("Output: %s" % output) | 227 self._debug("Output: %s" % output) |
| 227 | 228 |
| 228 self._clean_up() | 229 self._clean_up() |
| 229 | 230 |
| 230 return bool(errors), output | 231 return bool(errors), output |
| 231 | 232 |
| 232 | 233 |
| 233 if __name__ == "__main__": | 234 if __name__ == "__main__": |
| 234 parser = argparse.ArgumentParser( | 235 parser = argparse.ArgumentParser( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 251 exit, _ = checker.check(source, depends=depends, externs=externs) | 252 exit, _ = checker.check(source, depends=depends, externs=externs) |
| 252 if exit != 0: | 253 if exit != 0: |
| 253 sys.exit(exit) | 254 sys.exit(exit) |
| 254 | 255 |
| 255 if opts.out_file: | 256 if opts.out_file: |
| 256 out_dir = os.path.dirname(opts.out_file) | 257 out_dir = os.path.dirname(opts.out_file) |
| 257 if not os.path.exists(out_dir): | 258 if not os.path.exists(out_dir): |
| 258 os.makedirs(out_dir) | 259 os.makedirs(out_dir) |
| 259 # TODO(dbeam): write compiled file to |opts.out_file|. | 260 # TODO(dbeam): write compiled file to |opts.out_file|. |
| 260 open(opts.out_file, "w").write("") | 261 open(opts.out_file, "w").write("") |
| OLD | NEW |