using SQLLinter.Common;
using System.Text;
namespace SQLLinter.Infrastructure.Reporters;
public class HTMLReporter : FileReporter
{
public string GetContent()
{
var violations = Violations;
if (violations.Count == 0)
{
return "
Нет нарушений
";
}
var groupedByFile = violations
.GroupBy(v => v.FileName)
.OrderBy(g => g.Key);
var sb = new StringBuilder();
sb.AppendLine("");
sb.AppendLine("");
sb.AppendLine("");
sb.AppendLine("");
sb.AppendLine("Отчёт по SQL‑проверкам");
sb.AppendLine("");
sb.AppendLine("");
sb.AppendLine("");
//sb.AppendLine("Отчёт по SQL‑проверкам
");
int fileIndex = 0;
foreach (var fileGroup in groupedByFile)
{
string divId = $"file_{fileIndex}";
sb.AppendLine($"");
sb.AppendLine($"
Файл: {fileGroup.Key}
");
var groupedBySeverity = fileGroup
.GroupBy(v => v.Severity)
.OrderByDescending(g => g.Key);
foreach (var severityGroup in groupedBySeverity)
{
string severityClass = severityGroup.Key switch
{
RuleViolationSeverity.Critical => "critical",
RuleViolationSeverity.Warning => "warning",
RuleViolationSeverity.Info => "info",
_ => ""
};
sb.AppendLine($"
");
sb.AppendLine($"
{severityGroup.Key}
");
sb.AppendLine("
");
sb.AppendLine("");
sb.AppendLine("| # | Строка | Колонка | Правило | Описание |
");
sb.AppendLine("");
sb.AppendLine("");
int rowIndex = 1;
foreach (var v in severityGroup
.OrderBy(x => x.Line)
.ThenBy(x => x.Column))
{
sb.AppendLine($"| {rowIndex} | {v.Line} | {v.Column} | {v.RuleName} | {v.Text} |
");
rowIndex++;
}
sb.AppendLine("");
sb.AppendLine("
");
sb.AppendLine("
");
}
sb.AppendLine("
");
fileIndex++;
}
// Табы снизу
sb.AppendLine("");
fileIndex = 0;
foreach (var fileGroup in groupedByFile)
{
sb.AppendLine($"
{fileGroup.Key}
");
fileIndex++;
}
sb.AppendLine("
");
// JS для переключения
sb.AppendLine("");
sb.AppendLine("");
sb.AppendLine("");
return sb.ToString();
}
}