Skip to content

Commit 67798eb

Browse files
committed
aweasdads
1 parent fb1a9f8 commit 67798eb

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

cli/main.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,16 @@ def analyze(
160160
available_stats = [
161161
"line_count",
162162
"function_count",
163-
"comment_line_count"
163+
"comment_line_count",
164+
"identation_level"
164165
]
165166

166167
# dictionary for the stats UPDATE THIS WHEN NEEDED PLEASE !!!!!!!!
167168
stats_labels = {
168169
"line_count": messages.get("line_count_option", "Line Count"),
169170
"function_count": messages.get("function_count_option", "Function Count"),
170-
"comment_line_count": messages.get("comment_line_count_option", "Comment Line Count")
171+
"comment_line_count": messages.get("comment_line_count_option", "Comment Line Count"),
172+
"identation_level": messages.get("key", "Identation Level")
171173
}
172174

173175
# If --all flag is used, skip the selection menu and use all stats

spice/analyze.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
from lexers.javascript.javascriptlexer import JavaScriptLexer
1010
from lexers.golang.golexer import GoLexer
1111

12+
# gustavo testando alguma coisa
13+
14+
from spice.identation import detect_indentation
1215

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

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

8184
# count functions
8285
results["function_count"] = count_functions(ast)
86+
if "identation_level" in selected_stats:
87+
analyze_code_structure(code)
8388

8489
return results
8590

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

155-
return comment_count
160+
return comment_count
161+
162+
def analyze_code_structure(code):
163+
indentation_info = detect_indentation(code)
164+
165+
print(f"Detected Indentation Type: {indentation_info['indent_type']}")
166+
print(f"Detected Indentation Size: {indentation_info['indent_size']}")
167+
for line, level in indentation_info["levels"]:
168+
# print(f"Indentation Level {level}: {line}")
169+
print(f"Detected Indentation Type: {indentation_info['indent_type']}")
170+
print(f"Detected Indentation Size: {indentation_info['indent_size']}")

spice/identation.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import os
2+
import re
3+
4+
def detect_indentation(code):
5+
lines = code.split('\n')
6+
indentation_counts = {'tab': 0, 'space': 0}
7+
indentation_levels = []
8+
9+
for line in lines:
10+
if line.strip() == '':
11+
continue # skip empty lines
12+
leading_whitespace = re.match(r'^\s*', line).group()
13+
#detect space, tab or new line within the function
14+
if '\t' in leading_whitespace:
15+
indentation_counts['tab'] += 1
16+
if ' ' in leading_whitespace:
17+
indentation_counts['space'] += 1
18+
if '\t' in leading_whitespace and ' ' in leading_whitespace:
19+
print(f"Identação mista detectada: {line}")
20+
indent_level = len(leading_whitespace)
21+
indentation_levels.append((line.strip(), indent_level))
22+
23+
indent_type = 'tab' if indentation_counts['tab'] > indentation_counts['space'] else 'space'
24+
# qual estilo de identaçao for mais frequente será enviado para a variavel
25+
indent_size = 4 # tipo um padrao de identacao
26+
27+
return {
28+
"indent_type": indent_type,
29+
"indent_size": indent_size,
30+
"levels": indentation_levels
31+
}

0 commit comments

Comments
 (0)