| OLD | NEW |
| 1 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import re | 5 import re |
| 6 | 6 |
| 7 import eslint | 7 import eslint |
| 8 from py_vulcanize import strip_js_comments | 8 from py_vulcanize import strip_js_comments |
| 9 | 9 |
| 10 from catapult_build import parse_html | 10 from catapult_build import parse_html |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 soup = parse_html.BeautifulSoup(contents) | 91 soup = parse_html.BeautifulSoup(contents) |
| 92 script_elements = soup.find_all('script', src=None) | 92 script_elements = soup.find_all('script', src=None) |
| 93 return [_FirstStatement(e.get_text()) for e in script_elements] | 93 return [_FirstStatement(e.get_text()) for e in script_elements] |
| 94 | 94 |
| 95 | 95 |
| 96 def _FirstStatement(contents): | 96 def _FirstStatement(contents): |
| 97 """Extracts the first statement in some JS source code.""" | 97 """Extracts the first statement in some JS source code.""" |
| 98 stripped_contents = strip_js_comments.StripJSComments(contents).strip() | 98 stripped_contents = strip_js_comments.StripJSComments(contents).strip() |
| 99 matches = re.match('^(.*?);', stripped_contents, re.DOTALL) | 99 matches = re.match('^(.*?);', stripped_contents, re.DOTALL) |
| 100 if not matches: | 100 if not matches: |
| 101 return '' | 101 return contents |
| 102 return matches.group(1).strip() | 102 return matches.group(1).strip() |
| 103 | 103 |
| 104 | 104 |
| 105 def RunChecks(input_api, output_api, excluded_paths=None): | 105 def RunChecks(input_api, output_api, excluded_paths=None): |
| 106 | 106 |
| 107 def ShouldCheck(affected_file): | 107 def ShouldCheck(affected_file): |
| 108 if not excluded_paths: | 108 if not excluded_paths: |
| 109 return True | 109 return True |
| 110 path = affected_file.LocalPath() | 110 path = affected_file.LocalPath() |
| 111 return not any(re.match(pattern, path) for pattern in excluded_paths) | 111 return not any(re.match(pattern, path) for pattern in excluded_paths) |
| 112 | 112 |
| 113 return JSChecker(input_api, output_api, file_filter=ShouldCheck).RunChecks() | 113 return JSChecker(input_api, output_api, file_filter=ShouldCheck).RunChecks() |
| OLD | NEW |