Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cli/commands/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ def analyze_command(file, all, json_output, LANG_FILE):
available_stats = [
"line_count",
"function_count",
"comment_line_count"
"comment_line_count",
"identation_level"
]

# dictionary for the stats UPDATE THIS WHEN NEEDED PLEASE !!!!!!!!
stats_labels = {
"line_count": messages.get("line_count_option", "Line Count"),
"function_count": messages.get("function_count_option", "Function Count"),
"comment_line_count": messages.get("comment_line_count_option", "Comment Line Count")
"comment_line_count": messages.get("comment_line_count_option", "Comment Line Count"),
"identation_level": messages.get("identation_level", "Identation Level")
}

# If --all flag is used, skip the selection menu and use all stats
Expand Down
13 changes: 5 additions & 8 deletions spice/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,8 @@ def count_comment_lines(code):
return comment_count

def analyze_code_structure(code):
indentation_info = detect_indentation(code)

print(f"Detected Indentation Type: {indentation_info['indent_type']}")
print(f"Detected Indentation Size: {indentation_info['indent_size']}")
for line, level in indentation_info["levels"]:
# print(f"Indentation Level {level}: {line}")
print(f"Detected Indentation Type: {indentation_info['indent_type']}")
print(f"Detected Indentation Size: {indentation_info['indent_size']}")
indentation_info = detect_indentation(code)

print(f"Detected Indentation Type: {indentation_info['indent_type']}")
print(f"Detected Indentation Size: {indentation_info['indent_size']}")

27 changes: 19 additions & 8 deletions spice/identation.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
import os
import re

def detect_indentation(code):
lines = code.split('\n')
indentation_counts = {'tab': 0, 'space': 0}
indentation_levels = []
indent_sizes = {}

for line in lines:
if line.strip() == '':
continue # skip empty lines
if line.strip() == '': # Skip empty lines
continue

leading_whitespace = re.match(r'^\s*', line).group()
#detect space, tab or new line within the function

if '\t' in leading_whitespace:
indentation_counts['tab'] += 1
if ' ' in leading_whitespace:
indentation_counts['space'] += 1
if '\t' in leading_whitespace and ' ' in leading_whitespace:
print(f"Identação mista detectada: {line}")
print(f"⚠ Identação mista detectada: {line}")

indent_level = len(leading_whitespace)
indentation_levels.append((line.strip(), indent_level))

# Track indentation levels (ignoring zero indents)
if indent_level > 0:
indentation_levels.append((line.strip(), indent_level))
indent_sizes[indent_level] = indent_sizes.get(indent_level, 0) + 1

# Decide indentation type
indent_type = 'tab' if indentation_counts['tab'] > indentation_counts['space'] else 'space'
# qual estilo de identaçao for mais frequente será enviado para a variavel
indent_size = 4 # tipo um padrao de identacao

# Determine the most common indent size
if indent_sizes:
indent_size = max(indent_sizes, key=indent_sizes.get)
else:
indent_size = 4 # Default if no indentation found

return {
"indent_type": indent_type,
Expand Down