Skip to content

Commit 2ea1851

Browse files
committed
fix comment line counter
1 parent 47e6d3b commit 2ea1851

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

spice/analyze.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def analyze_file(file_path: str, selected_stats=None):
6666

6767
# process comment line count if requested
6868
if "comment_line_count" in selected_stats:
69-
results["comment_line_count"] = count_comment_lines(tokens)
69+
results["comment_line_count"] = count_comment_lines(code)
7070

7171
# only put the code through the parser and proceed with parsing if we need function count (UPDATE THIS WHEN NEEDED PLEASE !!!!!!!!)
7272
if "function_count" in selected_stats:
@@ -141,13 +141,14 @@ def search_node(node):
141141
# so like: y = 5 #sets y to 5 IS NOT A COMMENT LINE!!!!!!!!
142142
def count_comment_lines(code):
143143
"""Count lines that are exclusively comments (no code on the same line)"""
144-
lines = code.split('\n')
144+
# split the code into lines
145+
lines = code.splitlines()
145146
comment_count = 0
146147

147148
for line in lines:
148-
# remove leading whitespace
149+
# Remove leading whitespace
149150
stripped = line.strip()
150-
# check if this line consists only of a comment
151+
# Check if this line consists only of a comment
151152
if stripped and stripped.startswith('#'):
152153
comment_count += 1
153154

0 commit comments

Comments
 (0)