Support for ignore checkstyle files

This CL extends checkstyle check to search for IGNORE_CHECKSTYLE
files in folders which marks them as excluded from checkstyle,
including their sub folders

Change-Id: Id2390bb2a92e03f49c0014888e21549279e4bab6
This commit is contained in:
Yigit Boyar
2016-12-04 14:49:33 -08:00
parent fff72bd810
commit 99f3d7af24

View File

@@ -28,6 +28,30 @@ import tempfile
import xml.dom.minidom import xml.dom.minidom
import gitlint.git as git import gitlint.git as git
def _FindFoldersContaining(root, wanted):
"""Searches recursively from root to find directories that has a file with
the given name.
Args:
root: Root folder to start the search from.
wanted: The filename that we are looking for.
Returns:
List of folders that has a file with the given name
"""
if os.path.islink(root):
return []
result = []
for fileName in os.listdir(root):
filePath = os.path.join(root, fileName)
if os.path.isdir(filePath):
subResult = _FindFoldersContaining(filePath, wanted)
result.extend(subResult)
else:
if fileName == wanted:
result.append(root)
return result
MAIN_DIRECTORY = os.path.normpath(os.path.dirname(__file__)) MAIN_DIRECTORY = os.path.normpath(os.path.dirname(__file__))
CHECKSTYLE_JAR = os.path.join(MAIN_DIRECTORY, 'checkstyle.jar') CHECKSTYLE_JAR = os.path.join(MAIN_DIRECTORY, 'checkstyle.jar')
@@ -37,7 +61,8 @@ FORCED_RULES = ['com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck
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/', '/test/'] SUBPATH_FOR_TEST_FILES = ['/tests/', '/test/']
SUBPATH_FOR_TEST_DATA_FILES = ['src/tests/test-data/'] SUBPATH_FOR_TEST_DATA_FILES = _FindFoldersContaining(os.path.dirname(os.getcwd()),
"IGNORE_CHECKSTYLE")
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'