def _create_checker(self, file_type, file_path, handle_style_error, min_confidence): """Instantiate and return a style checker based on file type.""" if file_type == FileType.NONE: checker = None elif file_type == FileType.CPP: file_extension = self._file_extension(file_path) checker = CppChecker(file_path, file_extension, handle_style_error, min_confidence) elif file_type == FileType.JSON: checker = JSONChecker(file_path, handle_style_error) elif file_type == FileType.PYTHON: checker = PythonChecker(file_path, handle_style_error) elif file_type == FileType.XML: checker = XMLChecker(file_path, handle_style_error) elif file_type == FileType.XCODEPROJ: checker = XcodeProjectFileChecker(file_path, handle_style_error) elif file_type == FileType.PNG: checker = PNGChecker(file_path, handle_style_error) elif file_type == FileType.TEXT: basename = os.path.basename(file_path) if basename == 'TestExpectations': checker = TestExpectationsChecker(file_path, handle_style_error) else: checker = TextChecker(file_path, handle_style_error) else: raise ValueError('Invalid file type "%(file_type)s": the only valid file types ' 'are %(NONE)s, %(CPP)s, and %(TEXT)s.' % {'file_type': file_type, 'NONE': FileType.NONE, 'CPP': FileType.CPP, 'TEXT': FileType.TEXT}) return checker
def _create_checker(self, file_type, file_path, handle_style_error, min_confidence, commit_queue): """Instantiate and return a style checker based on file type.""" if file_type == FileType.NONE: checker = None elif file_type == FileType.CHANGELOG: should_line_be_checked = None if handle_style_error: should_line_be_checked = handle_style_error.should_line_be_checked checker = ChangeLogChecker(file_path, handle_style_error, should_line_be_checked) elif file_type == FileType.CPP: file_extension = self._file_extension(file_path) checker = CppChecker(file_path, file_extension, handle_style_error, min_confidence) elif file_type == FileType.JS: basename = os.path.basename(file_path) # Do not attempt to check non-Inspector or 3rd-party JavaScript files as JS. if os.path.join('WebInspectorUI', 'UserInterface') in file_path and (not 'External' in file_path): checker = JSChecker(file_path, handle_style_error) elif basename in _NEVER_SKIPPED_JS_FILES: checker = JSTestChecker(file_path, handle_style_error) else: checker = TextChecker(file_path, handle_style_error) elif file_type == FileType.JSON: basename = os.path.basename(file_path) if basename == 'contributors.json': if commit_queue: checker = JSONContributorsChecker(file_path, handle_style_error) else: checker = ContributorsChecker(file_path, handle_style_error) elif basename == 'features.json': checker = JSONFeaturesChecker(file_path, handle_style_error) elif basename == 'CSSProperties.json': checker = JSONCSSPropertiesChecker(file_path, handle_style_error) else: checker = JSONChecker(file_path, handle_style_error) elif file_type == FileType.PYTHON: python3_paths = ['Tools/resultsdbpy'] for partial in python3_paths: if file_path.startswith(partial): return Python3Checker(file_path, handle_style_error) if apple_additions(): checker = apple_additions().python_checker( file_path, handle_style_error) else: checker = PythonChecker(file_path, handle_style_error) elif file_type == FileType.XML: checker = XMLChecker(file_path, handle_style_error) elif file_type == FileType.XCODEPROJ: checker = XcodeProjectFileChecker(file_path, handle_style_error) elif file_type == FileType.PNG: checker = PNGChecker(file_path, handle_style_error) elif file_type == FileType.CMAKE: checker = CMakeChecker(file_path, handle_style_error) elif file_type == FileType.TEXT: basename = os.path.basename(file_path) if basename == 'TestExpectations': checker = TestExpectationsChecker(file_path, handle_style_error) elif file_path.endswith('.messages.in'): checker = MessagesInChecker(file_path, handle_style_error) else: checker = TextChecker(file_path, handle_style_error) elif file_type == FileType.WATCHLIST: checker = WatchListChecker(file_path, handle_style_error) elif file_type == FileType.FEATUREDEFINES: checker = FeatureDefinesChecker(file_path, handle_style_error) elif file_type == FileType.SDKVARIANT: checker = SDKVariantChecker(file_path, handle_style_error) else: raise ValueError( 'Invalid file type "%(file_type)s": the only valid file types ' "are %(NONE)s, %(CPP)s, and %(TEXT)s." % { "file_type": file_type, "NONE": FileType.NONE, "CPP": FileType.CPP, "TEXT": FileType.TEXT }) return checker