From 0e6e8ecda108bb98b0ae8118bbf784f242d4e18d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 17 Feb 2018 17:31:59 +0100 Subject: [PATCH] addons/metrics.py: count comments --- addons/metrics.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/addons/metrics.py b/addons/metrics.py index ab42b528e..090e5b096 100644 --- a/addons/metrics.py +++ b/addons/metrics.py @@ -6,13 +6,25 @@ import cppcheckdata import sys -class FunctionMetrics: - lines = 0 - complexity = 0 +def getNumberOfComments(rawtokens): + numberOfComments = 0 + file = None + comment = False + for tok in rawtokens: + if file is None: + file = tok.file + if tok.file != file: + continue + if tok.str.startswith('//') or tok.str.startswith('/*'): + if not comment: + numberOfComments += 1 + comment = True + else: + comment = False + return numberOfComments def getMetrics(data): - variables = {} - functions = {} + print('number of comments:' + str(getNumberOfComments(data.rawTokens))) for cfg in data.configurations: for func in cfg.functions: if func.tokenDef is None: