mirror of
https://github.com/ejwa/gitinspector.git
synced 2024-09-30 03:11:29 +02:00
Improved the comments module yet again.
It should now be able to handle multi-line comments that are only on one line. Furthermore, it should also handle multi-line comments from languages such as python (where the identifiers for comment begining/end are identical).
This commit is contained in:
parent
842ca6b87c
commit
676cb5c114
15
blame.py
15
blame.py
@ -48,14 +48,15 @@ class Blame:
|
|||||||
if self.blames.get(author, None) == None:
|
if self.blames.get(author, None) == None:
|
||||||
self.blames[author] = BlameEntry()
|
self.blames[author] = BlameEntry()
|
||||||
|
|
||||||
if comment.has_comment_begining(FileDiff.get_extension(i), content):
|
if comment.is_comment(FileDiff.get_extension(i), content):
|
||||||
is_inside_comment = True
|
|
||||||
|
|
||||||
if comment.is_comment(FileDiff.get_extension(i), content) or is_inside_comment:
|
|
||||||
self.blames[author].comments += 1
|
self.blames[author].comments += 1
|
||||||
|
if is_inside_comment:
|
||||||
if comment.has_comment_end(FileDiff.get_extension(i), content):
|
if comment.has_comment_end(FileDiff.get_extension(i), content):
|
||||||
is_inside_comment = False
|
is_inside_comment = False
|
||||||
|
else:
|
||||||
|
self.blames[author].comments += 1
|
||||||
|
elif comment.has_comment_begining(FileDiff.get_extension(i), content):
|
||||||
|
is_inside_comment = True
|
||||||
|
|
||||||
self.blames[author].rows += 1
|
self.blames[author].rows += 1
|
||||||
|
|
||||||
|
@ -27,9 +27,9 @@ __comment__ = {"java": "//", "c": "//", "cpp": "//", "h": "//", "hpp": "//", "py
|
|||||||
"rb": "#", "js": "//", "sql": "--"}
|
"rb": "#", "js": "//", "sql": "--"}
|
||||||
|
|
||||||
def is_comment(extension, string):
|
def is_comment(extension, string):
|
||||||
if __comment_begining__.get(extension, None) != None and string.strip().startswith(__comment__[extension]):
|
if __comment_begining__.get(extension, None) != None and string.strip().startswith(__comment_begining__[extension]):
|
||||||
return True
|
return True
|
||||||
if __comment_end__.get(extension, None) != None and string.strip().endswith(__comment__[extension]):
|
if __comment_end__.get(extension, None) != None and string.strip().endswith(__comment_end__[extension]):
|
||||||
return True
|
return True
|
||||||
if __comment__.get(extension, None) != None and string.strip().startswith(__comment__[extension]):
|
if __comment__.get(extension, None) != None and string.strip().startswith(__comment__[extension]):
|
||||||
return True
|
return True
|
||||||
@ -37,7 +37,7 @@ def is_comment(extension, string):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def has_comment_begining(extension, string):
|
def has_comment_begining(extension, string):
|
||||||
if __comment_begining__.get(extension, None) != None:
|
if __comment_begining__.get(extension, None) != None and string.find(__comment_end__[extension], 2) == -1:
|
||||||
return string.find(__comment_begining__[extension]) != -1
|
return string.find(__comment_begining__[extension]) != -1
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
@ -46,15 +46,14 @@ class Metrics:
|
|||||||
eloc_counter = 0
|
eloc_counter = 0
|
||||||
|
|
||||||
for j in file_r.readlines():
|
for j in file_r.readlines():
|
||||||
if comment.has_comment_begining(extension, j):
|
if is_inside_comment and comment.has_comment_end(extension, j):
|
||||||
|
is_inside_comment = False
|
||||||
|
elif comment.has_comment_begining(extension, j):
|
||||||
is_inside_comment = True
|
is_inside_comment = True
|
||||||
|
|
||||||
if not comment.is_comment(extension, j) and not is_inside_comment:
|
if not is_inside_comment and not comment.is_comment(extension, j):
|
||||||
eloc_counter += 1
|
eloc_counter += 1
|
||||||
|
|
||||||
if comment.has_comment_end(extension, j):
|
|
||||||
is_inside_comment = False
|
|
||||||
|
|
||||||
return eloc_counter
|
return eloc_counter
|
||||||
|
|
||||||
def output(repo, hard):
|
def output(repo, hard):
|
||||||
|
Loading…
Reference in New Issue
Block a user