import { splitLines } from '../../../shared/helpers/index.js';
export function pontuarJenkins(src, _relPath) {
    let score = 0;
    const maxScore = 100;
    const issues = [];
    const strengths = [];
    const _linhas = splitLines(src);
    const srcCompleto = src;
    if (!/\bsh\s+['"].*sudo\b/i.test(srcCompleto)) {
        score += 20;
        strengths.push('Sem uso de sudo em comandos');
    }
    else {
        issues.push('Uso de sudo detectado');
    }
    const hardcodedSecrets = (srcCompleto.match(/\b(password|token|secret)\s*=\s*['"][^$({][^'"]{5,}['"]/gi) || []).length;
    if (hardcodedSecrets === 0) {
        score += 25;
        strengths.push('Sem secrets hardcoded');
    }
    else {
        issues.push(`${hardcodedSecrets} secret(s) hardcoded`);
    }
    if (!/image\s*['"]?.*:latest['"]?/i.test(srcCompleto)) {
        score += 15;
        strengths.push('Imagens Docker com versão fixa');
    }
    else {
        issues.push('Uso de imagem :latest');
    }
    if (/timeout\s*\(.*\)/i.test(srcCompleto)) {
        score += 15;
        strengths.push('Timeout configurado');
    }
    else {
        issues.push('Timeout não configurado');
    }
    if (/cleanWs\s*\(\)/i.test(srcCompleto) || /deleteDir\s*\(\)/i.test(srcCompleto)) {
        score += 10;
        strengths.push('Limpeza de workspace configurada');
    }
    else {
        issues.push('Limpeza de workspace ausente');
    }
    if (/parallel\s*\{/i.test(srcCompleto)) {
        score += 10;
        strengths.push('Paralelismo configurado');
    }
    else {
        const stageCount = (srcCompleto.match(/stage\s*\(/g) || []).length;
        if (stageCount > 4) {
            issues.push('Pipeline longo sem paralelismo');
        }
    }
    if (/post\s*\{/i.test(srcCompleto)) {
        score += 5;
        strengths.push('Bloco post configurado');
    }
    else {
        issues.push('Bloco post ausente');
    }
    return {
        score,
        maxScore,
        percentage: Math.round(score / maxScore * 100),
        issues,
        strengths
    };
}
export const pontuadorJenkins = {
    nome: 'pontuador-jenkins',
    categoria: 'workflows',
    descricao: 'Pontua qualidade de Jenkinsfiles',
    pontuar: pontuarJenkins
};
//# sourceMappingURL=scorer-jenkins.js.map