addons/metrics.py: count comments
This commit is contained in:
parent
5db9345a08
commit
0e6e8ecda1
|
@ -6,13 +6,25 @@
|
||||||
import cppcheckdata
|
import cppcheckdata
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
class FunctionMetrics:
|
def getNumberOfComments(rawtokens):
|
||||||
lines = 0
|
numberOfComments = 0
|
||||||
complexity = 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):
|
def getMetrics(data):
|
||||||
variables = {}
|
print('number of comments:' + str(getNumberOfComments(data.rawTokens)))
|
||||||
functions = {}
|
|
||||||
for cfg in data.configurations:
|
for cfg in data.configurations:
|
||||||
for func in cfg.functions:
|
for func in cfg.functions:
|
||||||
if func.tokenDef is None:
|
if func.tokenDef is None:
|
||||||
|
|
Loading…
Reference in New Issue