Skip to content
Snippets Groups Projects
Commit abd8d292 authored by Atkins, Charles Vernon's avatar Atkins, Charles Vernon
Browse files

Allow a regex to exclude files from format checks

parent 4825e586
No related branches found
No related tags found
1 merge request!82Add googletest
......@@ -3,3 +3,4 @@ max-line-length = 80
max-complexity = 14
format = pylint
ignore = F403,F405,F999
exclude = thirdparty/
......@@ -112,6 +112,8 @@ def main():
help='passed to clang-format'),
p.add_argument('-v', '--verbose', action='count', default=0,
help='print extra information')
p.add_argument('-x', '--exclude',
help='Regex to match for files to exclude from checking')
# We gather all the remaining positional arguments into 'args' since we need
# to use some heuristics to determine whether or not <commit> was present.
# However, to print pretty messages, we make use of metavar and help.
......@@ -134,6 +136,7 @@ def main():
changed_lines = compute_diff_and_extract_lines(commits, files)
if opts.verbose >= 1:
ignored_files = set(changed_lines)
filter_by_exclude(changed_lines, opts.exclude)
filter_by_extension(changed_lines, opts.extensions.lower().split(','))
if opts.verbose >= 1:
ignored_files.difference_update(changed_lines)
......@@ -314,6 +317,16 @@ def extract_lines(patch_file):
return matches
def filter_by_exclude(dictionary, exclude_re):
"""Delete every key in `dictionary` that matches the exclusion regex.
`exclude_re` must be a valid regex."""
exre = re.compile(exclude_re)
for filename in dictionary.keys():
if exre.match(filename):
del dictionary[filename]
def filter_by_extension(dictionary, allowed_extensions):
"""Delete every key in `dictionary` that doesn't have an allowed extension.
......
......@@ -15,7 +15,7 @@ cd ${SOURCE_DIR}
# Check C and C++ code with clang-format
echo "Checking formatting for commit range: ${COMMIT_RANGE}"
DIFF="$(./scripts/developer/git/git-clang-format --diff ${COMMIT_RANGE})"
DIFF="$(./scripts/developer/git/git-clang-format -x '^thirdparty/' --diff ${COMMIT_RANGE})"
if [ -n "${DIFF}" ] && [ "${DIFF}" != "no modified files to format" ]
then
echo "clang-format:"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment