Skip all the ckecks for test data files.

Test: None
Change-Id: I492f1c7f97455fa08f135b375db7abb9d734c4b7
This commit is contained in:
Aurimas Liutikas
2016-11-10 13:36:31 -08:00
parent f5da6805de
commit 2ae3a31c44

View File

@@ -36,7 +36,8 @@ FORCED_RULES = ['com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck
'com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck'] 'com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck']
SKIPPED_RULES_FOR_TEST_FILES = ['com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck', SKIPPED_RULES_FOR_TEST_FILES = ['com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck',
'com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck'] 'com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck']
SUBPATH_FOR_TEST_FILES = ['/tests/java/', '/tests/src/', '/tests/test-data/', '/src/test/'] SUBPATH_FOR_TEST_FILES = ['/tests/java/', '/tests/src/', '/src/test/']
SUBPATH_FOR_TEST_DATA_FILES = ['src/tests/test-data/']
ERROR_UNCOMMITTED = 'You need to commit all modified files before running Checkstyle\n' ERROR_UNCOMMITTED = 'You need to commit all modified files before running Checkstyle\n'
ERROR_UNTRACKED = 'You have untracked java files that are not being checked:\n' ERROR_UNTRACKED = 'You have untracked java files that are not being checked:\n'
@@ -175,13 +176,15 @@ def _ParseAndFilterOutput(stdout,
sha) sha)
test_class = any(substring in file_name for substring test_class = any(substring in file_name for substring
in SUBPATH_FOR_TEST_FILES) in SUBPATH_FOR_TEST_FILES)
test_data_class = any(substring in file_name for substring
in SUBPATH_FOR_TEST_DATA_FILES)
file_name = os.path.relpath(file_name) file_name = os.path.relpath(file_name)
errors = file_element.getElementsByTagName('error') errors = file_element.getElementsByTagName('error')
for error in errors: for error in errors:
line = int(error.attributes['line'].value) line = int(error.attributes['line'].value)
rule = error.attributes['source'].value rule = error.attributes['source'].value
if _ShouldSkip(commit_modified_files, modified_lines, line, rule, if _ShouldSkip(commit_modified_files, modified_lines, line, rule,
test_class): test_class, test_data_class):
continue continue
column = '' column = ''
@@ -202,7 +205,8 @@ def _ParseAndFilterOutput(stdout,
return result_errors, result_warnings return result_errors, result_warnings
def _ShouldSkip(commit_check, modified_lines, line, rule, test_class=False): def _ShouldSkip(commit_check, modified_lines, line, rule, test_class=False,
test_data_class=False):
"""Returns whether an error on a given line should be skipped. """Returns whether an error on a given line should be skipped.
Args: Args:
@@ -211,11 +215,14 @@ def _ShouldSkip(commit_check, modified_lines, line, rule, test_class=False):
line: The line that has a rule violation. line: The line that has a rule violation.
rule: The type of rule that a given line is violating. rule: The type of rule that a given line is violating.
test_class: Whether the file being checked is a test class. test_class: Whether the file being checked is a test class.
test_data_class: Whether the file being check is a class used as test data.
Returns: Returns:
A boolean whether a given line should be skipped in the reporting. A boolean whether a given line should be skipped in the reporting.
""" """
# None modified_lines means checked file is new and nothing should be skipped. # None modified_lines means checked file is new and nothing should be skipped.
if test_data_class:
return True
if test_class and rule in SKIPPED_RULES_FOR_TEST_FILES: if test_class and rule in SKIPPED_RULES_FOR_TEST_FILES:
return True return True
if not commit_check: if not commit_check: