import { maskPythonComments, splitLines } from '../../../shared/helpers/index.js';
export function pontuarPython(src, _relPath) {
    let score = 0;
    const maxScore = 100;
    const issues = [];
    const strengths = [];
    const scan = maskPythonComments(src);
    const _linhas = splitLines(scan);
    const srcCompleto = scan;
    const funcs = (srcCompleto.match(/def\s+\w+/g) || []).length;
    const funcsWithHints = (srcCompleto.match(/def\s+\w+\s*\([^)]*\)\s*->/g) || []).length;
    if (funcs > 0) {
        const ratio = funcsWithHints / funcs;
        score += Math.round(ratio * 25);
        if (ratio > 0.8)
            strengths.push('Boa cobertura de type hints');
        else if (ratio > 0.5)
            issues.push('Type hints parciais');
        else
            issues.push('Poucas funções com type hints');
    }
    else {
        score += 25;
    }
    if (!/\b(eval|exec)\s*\(/.test(srcCompleto)) {
        score += 20;
        strengths.push('Sem uso de eval/exec');
    }
    else {
        issues.push('eval/exec detectado - risco de segurança');
    }
    const bareExcept = (srcCompleto.match(/^\s*except\s*:/gm) || []).length;
    if (bareExcept === 0) {
        score += 20;
        strengths.push('Error handling adequado');
    }
    else {
        score += Math.max(0, 20 - bareExcept * 5);
        issues.push(`${bareExcept} bare except(s) detectado(s)`);
    }
    const mutableDefaults = (srcCompleto.match(/def\s+\w+\s*\([^)]*=\s*(?:\[|\{)/g) || []).length;
    if (mutableDefaults === 0) {
        score += 15;
        strengths.push('Sem argumentos default mutáveis');
    }
    else {
        issues.push(`${mutableDefaults} função(ões) com default mutável`);
    }
    const printCount = (srcCompleto.match(/^\s*print\s*\(/gm) || []).length;
    const loggingCount = (srcCompleto.match(/logging\.\w+\(/g) || []).length;
    if (printCount === 0 || loggingCount > printCount) {
        score += 10;
        strengths.push('Uso adequado de logging');
    }
    else {
        issues.push(`${printCount} print(s) - considere usar logging`);
    }
    if (!/subprocess.*shell\s*=\s*True/.test(srcCompleto)) {
        score += 10;
        strengths.push('Sem subprocess com shell=True');
    }
    else {
        issues.push('subprocess com shell=True detectado');
    }
    return {
        score,
        maxScore,
        percentage: Math.round((score / maxScore) * 100),
        issues,
        strengths
    };
}
export const pontuadorPython = {
    nome: 'pontuador-python',
    categoria: 'framework',
    descricao: 'Pontua qualidade de código Python',
    pontuar: pontuarPython
};
//# sourceMappingURL=scorer-python.js.map