Skip to content
Merged
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
94 changes: 0 additions & 94 deletions cli/main.py

This file was deleted.

19 changes: 17 additions & 2 deletions spice/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from lexers.javascript.javascriptlexer import JavaScriptLexer
from lexers.golang.golexer import GoLexer

# gustavo testando alguma coisa

from spice.identation import detect_indentation

# this will read the file extension and return the correct lexer
def get_lexer_for_file(file_path):
Expand Down Expand Up @@ -40,7 +43,7 @@ def analyze_file(file_path: str, selected_stats=None):
"""
# default to all stats if none specified
if selected_stats is None:
selected_stats = ["line_count", "function_count", "comment_line_count"]
selected_stats = ["line_count", "function_count", "comment_line_count", "identation_level"]

# initialize results with the file name (dont change this please)
results = {
Expand Down Expand Up @@ -80,6 +83,8 @@ def analyze_file(file_path: str, selected_stats=None):

# count functions
results["function_count"] = count_functions(ast)
if "identation_level" in selected_stats:
analyze_code_structure(code)

return results

Expand Down Expand Up @@ -152,4 +157,14 @@ def count_comment_lines(code):
if stripped and stripped.startswith('#'):
comment_count += 1

return comment_count
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']}")
31 changes: 31 additions & 0 deletions spice/identation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os
import re

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

for line in lines:
if line.strip() == '':
continue # skip empty lines
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}")
indent_level = len(leading_whitespace)
indentation_levels.append((line.strip(), indent_level))

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

return {
"indent_type": indent_type,
"indent_size": indent_size,
"levels": indentation_levels
}