Create analizador_jshint.py
Browse files- analizador_jshint.py +40 -0
analizador_jshint.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import subprocess
|
2 |
+
import tempfile
|
3 |
+
import os
|
4 |
+
|
5 |
+
def analizar_js_con_jshint(codigo_js):
|
6 |
+
# Crear un archivo temporal con el código
|
7 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".js", mode='w', encoding='utf-8') as temp_file:
|
8 |
+
temp_file.write(codigo_js)
|
9 |
+
temp_path = temp_file.name
|
10 |
+
|
11 |
+
try:
|
12 |
+
# Ejecutar jshint sobre el archivo
|
13 |
+
resultado = subprocess.run(["jshint", temp_path], capture_output=True, text=True)
|
14 |
+
|
15 |
+
# Verificar salida
|
16 |
+
if resultado.returncode == 0:
|
17 |
+
salida = "✅ No se encontraron errores de sintaxis ni estilo."
|
18 |
+
else:
|
19 |
+
salida = f"❌ Problemas encontrados:\n{resultado.stdout}"
|
20 |
+
except Exception as e:
|
21 |
+
salida = f"❌ Error al ejecutar JSHint: {str(e)}"
|
22 |
+
finally:
|
23 |
+
os.remove(temp_path)
|
24 |
+
|
25 |
+
return salida
|
26 |
+
|
27 |
+
# Prueba rápida
|
28 |
+
if __name__ == "__main__":
|
29 |
+
codigo = """
|
30 |
+
function mayor(x, y) {
|
31 |
+
if (x > y) {
|
32 |
+
return x;
|
33 |
+
} else {
|
34 |
+
return y;
|
35 |
+
}
|
36 |
+
}
|
37 |
+
let resultado = mayor(10, 20);
|
38 |
+
console.log(resultado);
|
39 |
+
"""
|
40 |
+
print(analizar_js_con_jshint(codigo))
|