| OLD | NEW |
| 1 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org) | 1 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org) |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions | 4 # modification, are permitted provided that the following conditions |
| 5 # are met: | 5 # are met: |
| 6 # 1. Redistributions of source code must retain the above copyright | 6 # 1. Redistributions of source code must retain the above copyright |
| 7 # notice, this list of conditions and the following disclaimer. | 7 # notice, this list of conditions and the following disclaimer. |
| 8 # 2. Redistributions in binary form must reproduce the above copyright | 8 # 2. Redistributions in binary form must reproduce the above copyright |
| 9 # notice, this list of conditions and the following disclaimer in the | 9 # notice, this list of conditions and the following disclaimer in the |
| 10 # documentation and/or other materials provided with the distribution. | 10 # documentation and/or other materials provided with the distribution. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 Args: | 39 Args: |
| 40 line_number: The integer line number of the line containing the error. | 40 line_number: The integer line number of the line containing the error. |
| 41 category: The name of the category of the error, for example | 41 category: The name of the category of the error, for example |
| 42 "whitespace/newline". | 42 "whitespace/newline". |
| 43 confidence: An integer between 1 and 5 inclusive that represents the | 43 confidence: An integer between 1 and 5 inclusive that represents the |
| 44 application's level of confidence in the error. The value | 44 application's level of confidence in the error. The value |
| 45 5 means that we are certain of the problem, and the | 45 5 means that we are certain of the problem, and the |
| 46 value 1 means that it could be a legitimate construct. | 46 value 1 means that it could be a legitimate construct. |
| 47 message: The error message to report. | 47 message: The error message to report. |
| 48 | |
| 49 """ | 48 """ |
| 50 | 49 |
| 51 | 50 |
| 52 class DefaultStyleErrorHandler(object): | 51 class DefaultStyleErrorHandler(object): |
| 53 | 52 |
| 54 """The default style error handler.""" | 53 """The default style error handler.""" |
| 55 | 54 |
| 56 def __init__(self, file_path, configuration, increment_error_count, | 55 def __init__(self, file_path, configuration, increment_error_count, |
| 57 line_numbers=None): | 56 line_numbers=None): |
| 58 """Create a default style error handler. | 57 """Create a default style error handler. |
| 59 | 58 |
| 60 Args: | 59 Args: |
| 61 file_path: The path to the file containing the error. This | 60 file_path: The path to the file containing the error. This |
| 62 is used for reporting to the user. | 61 is used for reporting to the user. |
| 63 configuration: A StyleProcessorConfiguration instance. | 62 configuration: A StyleProcessorConfiguration instance. |
| 64 increment_error_count: A function that takes no arguments and | 63 increment_error_count: A function that takes no arguments and |
| 65 increments the total count of reportable | 64 increments the total count of reportable |
| 66 errors. | 65 errors. |
| 67 line_numbers: An array of line numbers of the lines for which | 66 line_numbers: An array of line numbers of the lines for which |
| 68 style errors should be reported, or None if errors | 67 style errors should be reported, or None if errors |
| 69 for all lines should be reported. When it is not | 68 for all lines should be reported. When it is not |
| 70 None, this array normally contains the line numbers | 69 None, this array normally contains the line numbers |
| 71 corresponding to the modified lines of a patch. | 70 corresponding to the modified lines of a patch. |
| 72 | |
| 73 """ | 71 """ |
| 74 if line_numbers is not None: | 72 if line_numbers is not None: |
| 75 line_numbers = set(line_numbers) | 73 line_numbers = set(line_numbers) |
| 76 | 74 |
| 77 self._file_path = file_path | 75 self._file_path = file_path |
| 78 self._configuration = configuration | 76 self._configuration = configuration |
| 79 self._increment_error_count = increment_error_count | 77 self._increment_error_count = increment_error_count |
| 80 self._line_numbers = line_numbers | 78 self._line_numbers = line_numbers |
| 81 | 79 |
| 82 # A string to integer dictionary cache of the number of reportable | 80 # A string to integer dictionary cache of the number of reportable |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 # Was the line that was modified? | 123 # Was the line that was modified? |
| 126 return self._line_numbers is None or line_number in self._line_numbers | 124 return self._line_numbers is None or line_number in self._line_numbers |
| 127 | 125 |
| 128 def turn_off_line_filtering(self): | 126 def turn_off_line_filtering(self): |
| 129 self._line_numbers = None | 127 self._line_numbers = None |
| 130 | 128 |
| 131 def __call__(self, line_number, category, confidence, message): | 129 def __call__(self, line_number, category, confidence, message): |
| 132 """Handle the occurrence of a style error. | 130 """Handle the occurrence of a style error. |
| 133 | 131 |
| 134 See the docstring of this module for more information. | 132 See the docstring of this module for more information. |
| 135 | |
| 136 """ | 133 """ |
| 137 if not self.should_line_be_checked(line_number): | 134 if not self.should_line_be_checked(line_number): |
| 138 return False | 135 return False |
| 139 | 136 |
| 140 if not self._configuration.is_reportable(category=category, | 137 if not self._configuration.is_reportable(category=category, |
| 141 confidence_in_error=confidence, | 138 confidence_in_error=confidence, |
| 142 file_path=self._file_path): | 139 file_path=self._file_path): |
| 143 return False | 140 return False |
| 144 | 141 |
| 145 category_total = self._add_reportable_error(category) | 142 category_total = self._add_reportable_error(category) |
| 146 | 143 |
| 147 max_reports = self._max_reports(category) | 144 max_reports = self._max_reports(category) |
| 148 | 145 |
| 149 if (max_reports is not None) and (category_total > max_reports): | 146 if (max_reports is not None) and (category_total > max_reports): |
| 150 # Then suppress displaying the error. | 147 # Then suppress displaying the error. |
| 151 return False | 148 return False |
| 152 | 149 |
| 153 self._configuration.write_style_error(category=category, | 150 self._configuration.write_style_error(category=category, |
| 154 confidence_in_error=confidence, | 151 confidence_in_error=confidence, |
| 155 file_path=self._file_path, | 152 file_path=self._file_path, |
| 156 line_number=line_number, | 153 line_number=line_number, |
| 157 message=message) | 154 message=message) |
| 158 if category_total == max_reports: | 155 if category_total == max_reports: |
| 159 self._configuration.stderr_write("Suppressing further [%s] reports " | 156 self._configuration.stderr_write("Suppressing further [%s] reports " |
| 160 "for this file.\n" % category) | 157 "for this file.\n" % category) |
| 161 return True | 158 return True |
| OLD | NEW |