import { splitLines } from '../../../shared/helpers/index.js';
export function pontuarShell(src, _relPath) {
    let score = 0;
    const maxScore = 100;
    const issues = [];
    const strengths = [];
    const linhas = splitLines(src);
    const srcCompleto = src;
    if (linhas.length > 0 && linhas[0].startsWith('#!')) {
        score += 10;
        strengths.push('Shebang presente');
    }
    else {
        issues.push('Shebang ausente');
    }
    if (/set\s+(-e|-o\s+pipefail)/.test(srcCompleto)) {
        score += 15;
        strengths.push('Error handling configurado');
    }
    else {
        issues.push('Sem set -e');
    }
    if (!/\beval\s+/.test(srcCompleto)) {
        score += 20;
        strengths.push('Sem eval');
    }
    else {
        issues.push('eval detectado');
    }
    if (!/(curl|wget).*\|\s*(ba)?sh/.test(srcCompleto)) {
        score += 15;
        strengths.push('Sem curl|sh');
    }
    else {
        issues.push('curl|sh detectado');
    }
    const hardcodedPasswords = (srcCompleto.match(/\b(password|pass|secret|token)\b\s*=\s*['"]/gi) || []).length;
    if (hardcodedPasswords === 0) {
        score += 15;
        strengths.push('Sem senhas hardcoded');
    }
    else {
        issues.push(`${hardcodedPasswords} senha(s) hardcoded`);
    }
    const unquotedVars = (srcCompleto.match(/\b(echo|ls|cd|rm|cp|mv)\s+.*\$\w+/g) || []).filter(linha => !/["'].*\$\w+.*["']/.test(linha)).length;
    if (unquotedVars === 0) {
        score += 15;
        strengths.push('Variáveis corretamente aspeadas');
    }
    else {
        score += Math.max(0, 15 - unquotedVars * 3);
        issues.push(`${unquotedVars} variável(is) sem aspas`);
    }
    if (!/\brm\s+-rf\s+\/(\s|$)/.test(srcCompleto)) {
        score += 10;
        strengths.push('Sem rm -rf /');
    }
    else {
        issues.push('rm -rf / detectado!');
    }
    return {
        score,
        maxScore,
        percentage: Math.round(score / maxScore * 100),
        issues,
        strengths
    };
}
export const pontuadorShell = {
    nome: 'pontuador-shell',
    categoria: 'infrastructure',
    descricao: 'Pontua qualidade de Shell Script',
    pontuar: pontuarShell
};
//# sourceMappingURL=scorer-shell.js.map