Skip to content

Commit dd4a0c7

Browse files
committed
account for inline comments
1 parent cab9baf commit dd4a0c7

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

spice/analyze.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ def analyze_file(file_path: str, selected_stats: Optional[List[str]] = None) ->
1010
Args:
1111
file_path (str): Path to the file to analyze
1212
selected_stats (list, optional): List of stats to compute. If None, compute all stats.
13-
Valid stats are: "line_count", "function_count", "comment_line_count", "indentation_level"
13+
Valid stats are: "line_count", "function_count", "comment_line_count",
14+
"inline_comment_count", "indentation_level"
1415
1516
Returns:
1617
dict: Dictionary containing the requested stats and file information
@@ -34,7 +35,7 @@ def analyze_file(file_path: str, selected_stats: Optional[List[str]] = None) ->
3435
raise ValueError("File has no extension")
3536

3637
# Define valid stats
37-
valid_stats = ["line_count", "function_count", "comment_line_count", "indentation_level"]
38+
valid_stats = ["line_count", "function_count", "comment_line_count", "inline_comment_count", "indentation_level"]
3839

3940
# default to all stats if none specified
4041
if selected_stats is None:
@@ -71,6 +72,14 @@ def analyze_file(file_path: str, selected_stats: Optional[List[str]] = None) ->
7172
lexer = LexerClass(source_code=code) # Pass source_code explicitly
7273
results["comment_line_count"] = count_comment_lines(file_path)
7374

75+
# inline comment count if requested
76+
if "inline_comment_count" in selected_stats:
77+
from spice.analyzers.count_inline_comments import count_inline_comments
78+
from utils.get_lexer import get_lexer_for_file
79+
LexerClass = get_lexer_for_file(file_path)
80+
lexer = LexerClass(source_code=code) # Pass source_code explicitly
81+
results["inline_comment_count"] = count_inline_comments(file_path)
82+
7483
# indentation analysis if requested
7584
if "indentation_level" in selected_stats:
7685
indentation_info = detect_indentation(code)

0 commit comments

Comments
 (0)