diff --git a/SQLLinter.CLI/Program.cs b/SQLLinter.CLI/Program.cs index f7056e2..ffa0487 100644 --- a/SQLLinter.CLI/Program.cs +++ b/SQLLinter.CLI/Program.cs @@ -62,7 +62,7 @@ namespace SQLLinter.CLI //linter.Run(@"C:\Users\frost\Desktop\DISTR-2599\test.sql"); - var formatter = new HtmlReportFormatter(); + var formatter = new HtmlReportFormatter_v2(); var content = formatter.Format(rep.Violations, bpmn); File.WriteAllText(@"C:\Users\frost\Downloads\Telegram Desktop\test.html", content); diff --git a/SQLLinter/Infrastructure/Reporters/HtmlReportFormatter_v1.cs b/SQLLinter/Infrastructure/Reporters/HtmlReportFormatter_v1.cs new file mode 100644 index 0000000..cccd209 --- /dev/null +++ b/SQLLinter/Infrastructure/Reporters/HtmlReportFormatter_v1.cs @@ -0,0 +1,148 @@ +using SQLLinter.Common; +using SQLLinter.Infrastructure.Diagram; +using System.Text; + +namespace SQLLinter.Infrastructure.Reporters; + +public class HtmlReportFormatter_v1 : IReportFormatter +{ + public string Format(List violations) + => Format(violations, null); + + public string Format(List violations, BpmnDiagram? diagram) + { + 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++; + } + + sb.AppendLine(""); + sb.AppendLine("
#СтрокаКолонкаПравилоОписание
{rowIndex}{v.Line}{v.Column}{v.RuleName}{v.Text}
"); + 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(); + } +} diff --git a/SQLLinter/Infrastructure/Reporters/HtmlReportFormatter.cs b/SQLLinter/Infrastructure/Reporters/HtmlReportFormatter_v2.cs similarity index 99% rename from SQLLinter/Infrastructure/Reporters/HtmlReportFormatter.cs rename to SQLLinter/Infrastructure/Reporters/HtmlReportFormatter_v2.cs index 7774dee..72f9c85 100644 --- a/SQLLinter/Infrastructure/Reporters/HtmlReportFormatter.cs +++ b/SQLLinter/Infrastructure/Reporters/HtmlReportFormatter_v2.cs @@ -9,7 +9,7 @@ using System.Text.Json.Serialization; namespace SQLLinter.Infrastructure.Reporters; -public class HtmlReportFormatter : IReportFormatter +public class HtmlReportFormatter_v2 : IReportFormatter { public string Format(List violations) => Format(violations, null);