except ImportError: # Python 3.9 onwards import xml.etree.ElementTree as etree from diff_cover.command_runner import run_command_for_code from diff_cover.git_path import GitPathTool from diff_cover.violationsreporters.base import BaseViolationReporter, Violation, RegexBasedDriver, QualityDriver """ Report checkstyle violations. http://checkstyle.sourceforge.net/apidocs/com/puppycrawl/tools/checkstyle/DefaultLogger.html https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/AuditEventDefaultFormatter.java """ checkstyle_driver = RegexBasedDriver( name='checkstyle', supported_extensions=['java'], command=['checkstyle'], expression=r'^\[\w+\]\s+([^:]+):(\d+):(?:\d+:)? (.*)$', command_to_check_install=[ 'java', 'com.puppycrawl.tools.checkstyle.Main', '-version' ]) class CheckstyleXmlDriver(QualityDriver): def __init__(self): """ See super for args """ super(CheckstyleXmlDriver, self).__init__('checkstyle', ['java'], [ 'java', 'com.puppycrawl.tools.checkstyle.Main', '-c', '/google_checks.xml' ]) self.command_to_check_install = [
self._cache_file(src_path) # Yield all lines not covered return self._info_cache[src_path][0] def measured_lines(self, src_path): """ See base class docstring. """ self._cache_file(src_path) return self._info_cache[src_path][1] pep8_driver = RegexBasedDriver(name='pep8', supported_extensions=['py'], command=['pep8'], expression=r'^([^:]+):(\d+).*([EW]\d{3}.*)$', command_to_check_install=['pep8', '--version']) pyflakes_driver = RegexBasedDriver( name='pyflakes', supported_extensions=['py'], command=['pyflakes'], # Match lines of the form: # path/to/file.py:328: undefined name '_thing' # path/to/file.py:418: 'random' imported but unused expression=r'^([^:]+):(\d+): (.*)$', command_to_check_install=['pyflakes', '--version']) """ Report Flake8 violations.
Violation, RegexBasedDriver, QualityDriver, ) """ Report checkstyle violations. http://checkstyle.sourceforge.net/apidocs/com/puppycrawl/tools/checkstyle/DefaultLogger.html https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/AuditEventDefaultFormatter.java """ checkstyle_driver = RegexBasedDriver( name="checkstyle", supported_extensions=["java"], command=["checkstyle"], expression=r"^\[\w+\]\s+([^:]+):(\d+):(?:\d+:)? (.*)$", command_to_check_install=[ "java", "com.puppycrawl.tools.checkstyle.Main", "-version", ], ) class CheckstyleXmlDriver(QualityDriver): def __init__(self): """ See super for args """ super().__init__( "checkstyle", ["java"],
# Yield all lines not covered return self._info_cache[src_path][0] def measured_lines(self, src_path): """ See base class docstring. """ self._cache_file(src_path) return self._info_cache[src_path][1] pycodestyle_driver = RegexBasedDriver( name="pycodestyle", supported_extensions=["py"], command=["pycodestyle"], expression=r"^([^:]+):(\d+).*([EW]\d{3}.*)$", command_to_check_install=["pycodestyle", "--version"], # pycodestyle exit code is 1 if there are violations # http://pycodestyle.pycqa.org/en/latest/intro.html exit_codes=[0, 1], ) pyflakes_driver = RegexBasedDriver( name="pyflakes", supported_extensions=["py"], command=["pyflakes"], # Match lines of the form: # path/to/file.py:328: undefined name '_thing' # path/to/file.py:418: 'random' imported but unused expression=r"^([^:]+):(\d+):\d* (.*)$", command_to_check_install=["pyflakes", "--version"], # pyflakes exit code is 1 if there are violations
self._cache_file(src_path) # Yield all lines not covered return self._info_cache[src_path][0] def measured_lines(self, src_path): """ See base class docstring. """ self._cache_file(src_path) return self._info_cache[src_path][1] pep8_driver = RegexBasedDriver(name='pep8', supported_extensions=['py'], command=['pep8'], expression=r'^([^:]+):(\d+).*([EW]\d{3}.*)$') pyflakes_driver = RegexBasedDriver( name='pyflakes', supported_extensions=['py'], command=['pyflakes'], # Match lines of the form: # path/to/file.py:328: undefined name '_thing' # path/to/file.py:418: 'random' imported but unused expression=r'^([^:]+):(\d+): (.*)$') """ Report Flake8 violations. Flake8 warning/error codes: E***/W***: pep8 errors and warnings