| OLD | NEW | 
|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 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 """ | 5 """ | 
| 6 Presubmit for Chromium HTML/CSS/JS resources. See chrome/browser/PRESUBMIT.py. | 6 Presubmit for Chromium HTML/CSS/JS resources. See chrome/browser/PRESUBMIT.py. | 
| 7 """ | 7 """ | 
| 8 | 8 | 
| 9 import regex_check | 9 import regex_check | 
| 10 | 10 | 
| 11 | 11 | 
| 12 class ResourceChecker(object): | 12 class ResourceChecker(object): | 
| 13   def __init__(self, input_api, output_api, file_filter=None): | 13   def __init__(self, input_api, output_api, file_filter=None): | 
| 14     self.input_api = input_api | 14     self.input_api = input_api | 
| 15     self.output_api = output_api | 15     self.output_api = output_api | 
| 16     self.file_filter = file_filter | 16     self.file_filter = file_filter | 
| 17 | 17 | 
| 18   def IncludeCheck(self, line_number, line): | 18   def IncludeCheck(self, line_number, line): | 
| 19     return regex_check.RegexCheck(self.input_api.re, line_number, line, | 19     return regex_check.RegexCheck(self.input_api.re, line_number, line, | 
| 20         "(</include>|<include.*/>)", "Closing <include> tags is unnecessary.") | 20         "(</include>|<include.*/>)", "Closing <include> tags is unnecessary.") | 
| 21 | 21 | 
| 22   def RunChecks(self): | 22   def RunChecks(self): | 
| 23     """Check for violations of the Chromium web development style guide. See | 23     """Check for violations of the Chromium web development style guide. See | 
| 24        https://chromium.googlesource.com/chromium/src/+/master/styleguide/web/we
    b.md | 24        https://chromium.googlesource.com/chromium/src/+/master/styleguide/web/we
    b.md | 
| 25     """ | 25     """ | 
| 26     results = [] | 26     results = [] | 
| 27 | 27 | 
| 28     affected_files = self.input_api.change.AffectedFiles( | 28     affected_files = self.input_api.AffectedFiles(file_filter=self.file_filter, | 
| 29         file_filter=self.file_filter, include_deletes=False) | 29                                                   include_deletes=False) | 
| 30 | 30 | 
| 31     for f in affected_files: | 31     for f in affected_files: | 
| 32       errors = [] | 32       errors = [] | 
| 33 | 33 | 
| 34       for line_number, line in enumerate(f.NewContents(), start=1): | 34       for line_number, line in enumerate(f.NewContents(), start=1): | 
| 35         error = self.IncludeCheck(line_number, line) | 35         error = self.IncludeCheck(line_number, line) | 
| 36         if error: | 36         if error: | 
| 37           errors.append(error) | 37           errors.append(error) | 
| 38 | 38 | 
| 39       if errors: | 39       if errors: | 
| 40         abs_local_path = f.AbsoluteLocalPath() | 40         abs_local_path = f.AbsoluteLocalPath() | 
| 41         file_indicator = 'Found resources style issues in %s' % abs_local_path | 41         file_indicator = 'Found resources style issues in %s' % abs_local_path | 
| 42         prompt_msg = file_indicator + '\n\n' + '\n'.join(errors) + '\n' | 42         prompt_msg = file_indicator + '\n\n' + '\n'.join(errors) + '\n' | 
| 43         results.append(self.output_api.PresubmitPromptWarning(prompt_msg)) | 43         results.append(self.output_api.PresubmitPromptWarning(prompt_msg)) | 
| 44 | 44 | 
| 45     return results | 45     return results | 
| OLD | NEW | 
|---|