mirror of
https://github.com/ejwa/gitinspector.git
synced 2025-03-16 13:28:04 +01:00
Modified the comment module to properly detect comments mixed in with code.
This commit is contained in:
parent
4fb37bf914
commit
842ca6b87c
3 changed files with 22 additions and 18 deletions
4
blame.py
4
blame.py
|
@ -48,13 +48,13 @@ class Blame:
|
|||
if self.blames.get(author, None) == None:
|
||||
self.blames[author] = BlameEntry()
|
||||
|
||||
if comment.is_comment_begining(FileDiff.get_extension(i), content):
|
||||
if comment.has_comment_begining(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
|
||||
|
||||
if comment.is_comment_end(FileDiff.get_extension(i), content):
|
||||
if comment.has_comment_end(FileDiff.get_extension(i), content):
|
||||
is_inside_comment = False
|
||||
|
||||
self.blames[author].rows += 1
|
||||
|
|
32
comment.py
32
comment.py
|
@ -26,20 +26,24 @@ __comment_end__ = {"java": "*/", "c": "*/", "cpp": "*/", "h": "*/", "hpp": "*/",
|
|||
__comment__ = {"java": "//", "c": "//", "cpp": "//", "h": "//", "hpp": "//", "py": "#", "glsl": "//",
|
||||
"rb": "#", "js": "//", "sql": "--"}
|
||||
|
||||
def is_comment_begining(extension, string):
|
||||
if __comment_begining__.get(extension, None) != None:
|
||||
return string.strip().startswith(__comment_begining__[extension])
|
||||
else:
|
||||
return False
|
||||
|
||||
def is_comment_end(extension, string):
|
||||
if __comment_end__.get(extension, None) != None:
|
||||
return string.strip().endswith(__comment_end__[extension])
|
||||
else:
|
||||
return False
|
||||
|
||||
def is_comment(extension, string):
|
||||
if __comment__.get(extension, None) != None:
|
||||
return string.strip().startswith(__comment__[extension])
|
||||
if __comment_begining__.get(extension, None) != None and string.strip().startswith(__comment__[extension]):
|
||||
return True
|
||||
if __comment_end__.get(extension, None) != None and string.strip().endswith(__comment__[extension]):
|
||||
return True
|
||||
if __comment__.get(extension, None) != None and string.strip().startswith(__comment__[extension]):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def has_comment_begining(extension, string):
|
||||
if __comment_begining__.get(extension, None) != None:
|
||||
return string.find(__comment_begining__[extension]) != -1
|
||||
else:
|
||||
return False
|
||||
|
||||
def has_comment_end(extension, string):
|
||||
if __comment_end__.get(extension, None) != None:
|
||||
return string.find(__comment_end__[extension]) != -1
|
||||
else:
|
||||
return False
|
||||
|
|
|
@ -46,13 +46,13 @@ class Metrics:
|
|||
eloc_counter = 0
|
||||
|
||||
for j in file_r.readlines():
|
||||
if comment.is_comment_begining(extension, j):
|
||||
if comment.has_comment_begining(extension, j):
|
||||
is_inside_comment = True
|
||||
|
||||
if not comment.is_comment(extension, j) and not is_inside_comment:
|
||||
eloc_counter += 1
|
||||
|
||||
if comment.is_comment_end(extension, j):
|
||||
if comment.has_comment_end(extension, j):
|
||||
is_inside_comment = False
|
||||
|
||||
return eloc_counter
|
||||
|
|
Loading…
Add table
Reference in a new issue