file_size = metrics.get_file_len(f)
if file_size > MAX_FILE_SIZE:
- p = problem.FileSizeProblem(fname, file_size)
+ p = problem.FileSizeItem(fname, file_size)
if ProblemVault.register_problem(p):
return 1
return 0
include_count = metrics.get_include_count(f)
if include_count > MAX_INCLUDE_COUNT:
- p = problem.IncludeCountProblem(fname, include_count)
+ p = problem.IncludeCountItem(fname, include_count)
if ProblemVault.register_problem(p):
return 1
return 0
# That's a big function! Issue a problem!
canonical_function_name = "%s:%s()" % (fname, name)
- p = problem.FunctionSizeProblem(canonical_function_name, lines)
+ p = problem.FunctionSizeItem(canonical_function_name, lines)
if ProblemVault.register_problem(p):
found_new_issues += 1
if fn is not None:
ex.metric_value = fn(ex.metric_value)
-class Problem(object):
+class Item(object):
"""
- A generic problem in our source code. See the subclasses below for the
- specific problems we are trying to tackle.
+ A generic measurement about some aspect of our source code. See
+ the subclasses below for the specific problems we are trying to tackle.
"""
def __init__(self, problem_type, problem_location, metric_value):
self.problem_location = problem_location
def key(self):
"""Generate a unique key that describes this problem that can be used as a dictionary key"""
- # Problem location is a filesystem path, so we need to normalize this
+ # Item location is a filesystem path, so we need to normalize this
# across platforms otherwise same paths are not gonna match.
canonical_location = os.path.normcase(self.problem_location)
return "%s:%s" % (canonical_location, self.problem_type)
def __str__(self):
return "problem %s %s %s" % (self.problem_type, self.problem_location, self.metric_value)
-class FileSizeProblem(Problem):
+class FileSizeItem(Item):
"""
Denotes a problem with the size of a .c file.
'metric_value' is the number of lines in the .c file.
"""
def __init__(self, problem_location, metric_value):
- super(FileSizeProblem, self).__init__("file-size", problem_location, metric_value)
+ super(FileSizeItem, self).__init__("file-size", problem_location, metric_value)
-class IncludeCountProblem(Problem):
+class IncludeCountItem(Item):
"""
Denotes a problem with the number of #includes in a .c file.
'metric_value' is the number of #includes in the .c file.
"""
def __init__(self, problem_location, metric_value):
- super(IncludeCountProblem, self).__init__("include-count", problem_location, metric_value)
+ super(IncludeCountItem, self).__init__("include-count", problem_location, metric_value)
-class FunctionSizeProblem(Problem):
+class FunctionSizeItem(Item):
"""
Denotes a problem with a size of a function in a .c file.
The 'metric_value' is the size of the offending function in lines.
"""
def __init__(self, problem_location, metric_value):
- super(FunctionSizeProblem, self).__init__("function-size", problem_location, metric_value)
+ super(FunctionSizeItem, self).__init__("function-size", problem_location, metric_value)
comment_re = re.compile(r'#.*$')
raise ValueError("Misformatted line {!r}".format(orig_str))
if problem_type == "file-size":
- return FileSizeProblem(problem_location, metric_value)
+ return FileSizeItem(problem_location, metric_value)
elif problem_type == "include-count":
- return IncludeCountProblem(problem_location, metric_value)
+ return IncludeCountItem(problem_location, metric_value)
elif problem_type == "function-size":
- return FunctionSizeProblem(problem_location, metric_value)
+ return FunctionSizeItem(problem_location, metric_value)
else:
raise ValueError("Unknown exception type {!r}".format(orig_str))