From 2ae3a31c448e49cc939292fb1622c2f814bdfbb6 Mon Sep 17 00:00:00 2001 From: Aurimas Liutikas Date: Thu, 10 Nov 2016 13:36:31 -0800 Subject: [PATCH] Skip all the ckecks for test data files. Test: None Change-Id: I492f1c7f97455fa08f135b375db7abb9d734c4b7 --- tools/checkstyle/checkstyle.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/checkstyle/checkstyle.py b/tools/checkstyle/checkstyle.py index 828e61fb6..63f183fd4 100755 --- a/tools/checkstyle/checkstyle.py +++ b/tools/checkstyle/checkstyle.py @@ -36,7 +36,8 @@ FORCED_RULES = ['com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck 'com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck'] SKIPPED_RULES_FOR_TEST_FILES = ['com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck', '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_UNTRACKED = 'You have untracked java files that are not being checked:\n' @@ -175,13 +176,15 @@ def _ParseAndFilterOutput(stdout, sha) test_class = any(substring in file_name for substring 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) errors = file_element.getElementsByTagName('error') for error in errors: line = int(error.attributes['line'].value) rule = error.attributes['source'].value if _ShouldSkip(commit_modified_files, modified_lines, line, rule, - test_class): + test_class, test_data_class): continue column = '' @@ -202,7 +205,8 @@ def _ParseAndFilterOutput(stdout, 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. Args: @@ -211,11 +215,14 @@ def _ShouldSkip(commit_check, modified_lines, line, rule, test_class=False): line: The line that has a rule violation. rule: The type of rule that a given line is violating. 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: 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. + if test_data_class: + return True if test_class and rule in SKIPPED_RULES_FOR_TEST_FILES: return True if not commit_check: