Skip to content

Commit 453a71d

Browse files
liutikasGerrit Code Review
authored andcommitted
Merge "Support for ignore checkstyle files"
2 parents d5f8802 + 99f3d7a commit 453a71d

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

tools/checkstyle/checkstyle.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,30 @@
2828
import xml.dom.minidom
2929
import gitlint.git as git
3030

31+
def _FindFoldersContaining(root, wanted):
32+
"""Searches recursively from root to find directories that has a file with
33+
the given name.
34+
35+
Args:
36+
root: Root folder to start the search from.
37+
wanted: The filename that we are looking for.
38+
39+
Returns:
40+
List of folders that has a file with the given name
41+
"""
42+
43+
if os.path.islink(root):
44+
return []
45+
result = []
46+
for fileName in os.listdir(root):
47+
filePath = os.path.join(root, fileName)
48+
if os.path.isdir(filePath):
49+
subResult = _FindFoldersContaining(filePath, wanted)
50+
result.extend(subResult)
51+
else:
52+
if fileName == wanted:
53+
result.append(root)
54+
return result
3155

3256
MAIN_DIRECTORY = os.path.normpath(os.path.dirname(__file__))
3357
CHECKSTYLE_JAR = os.path.join(MAIN_DIRECTORY, 'checkstyle.jar')
@@ -37,7 +61,8 @@
3761
SKIPPED_RULES_FOR_TEST_FILES = ['com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck',
3862
'com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck']
3963
SUBPATH_FOR_TEST_FILES = ['/tests/', '/test/']
40-
SUBPATH_FOR_TEST_DATA_FILES = ['src/tests/test-data/']
64+
SUBPATH_FOR_TEST_DATA_FILES = _FindFoldersContaining(os.path.dirname(os.getcwd()),
65+
"IGNORE_CHECKSTYLE")
4166
ERROR_UNCOMMITTED = 'You need to commit all modified files before running Checkstyle\n'
4267
ERROR_UNTRACKED = 'You have untracked java files that are not being checked:\n'
4368

0 commit comments

Comments
 (0)