Improve #include counting func and move it to metrics.py.

This commit is contained in:
George Kadianakis 2019-02-27 17:05:00 +02:00
parent a7684fcb57
commit 371ea65c08
2 changed files with 9 additions and 4 deletions

View File

@ -8,6 +8,14 @@ def file_len(f):
pass pass
return i + 1 return i + 1
def get_include_count(f):
"""Get number of #include statements in the file"""
include_count = 0
for line in f:
if re.match(r' *# *include', line):
include_count += 1
return include_count
def function_lines(f): def function_lines(f):
""" """
Return iterator which iterates over functions and returns (function name, function lines) Return iterator which iterates over functions and returns (function name, function lines)

View File

@ -57,10 +57,7 @@ def consider_file_size(fname, f, exceptions_str):
print_violation_if_not_exception(violation_str, exceptions_str) print_violation_if_not_exception(violation_str, exceptions_str)
def consider_includes(fname, f, exceptions_str): def consider_includes(fname, f, exceptions_str):
include_count = 0 include_count = metrics.get_include_count(f)
for _, line in enumerate(f):
if line.startswith("#include "):
include_count += 1
if include_count > MAX_INCLUDE_COUNT: if include_count > MAX_INCLUDE_COUNT:
violation_str = "violation include-count %s %d" % (fname, include_count) violation_str = "violation include-count %s %d" % (fname, include_count)