Доработан js и минимизация json

This commit is contained in:
FrigaT
2025-12-26 22:45:08 +03:00
parent 4a0e9d7d6b
commit 52ac8f509e
3 changed files with 171 additions and 70 deletions

View File

@@ -1,5 +1,7 @@
using SQLLinter.Common;
using SQLLinter.Infrastructure.Diagram;
using SQLLinter.Infrastructure.Rules.RuleViolations;
using System.Data;
using System.Reflection;
using System.Text;
using System.Text.Json;
@@ -66,38 +68,76 @@ public class HtmlReportFormatter : IReportFormatter
foreach (var fileGroup in groupedByFile)
{
var fileData = new FileReportData
var fileData = new FileReport
{
FileName = fileGroup.Key
Name = fileGroup.Key,
};
// Группировка по severity
var severityGroups = fileGroup
.GroupBy(v => v.Severity)
.OrderByDescending(g => g.Key)
.ToList();
foreach (var severityGroup in severityGroups)
foreach (var violation in fileGroup.Select(t => t).OrderBy(v => v.Line).ThenBy(v => v.Column))
{
var violationsList = severityGroup
.OrderBy(v => v.Line)
.ThenBy(v => v.Column)
.Select(v => new ViolationData
{
Line = v.Line,
Column = v.Column,
RuleName = v.RuleName,
Text = EscapeHtml(v.Text),
Index = severityGroup.ToList().IndexOf(v) + 1
})
.ToList();
int ruleId;
List<string> args = new();
if (severityGroup.Key == RuleViolationSeverity.Critical)
fileData.CriticalViolations = violationsList;
else if (severityGroup.Key == RuleViolationSeverity.Warning)
fileData.WarningViolations = violationsList;
else if (severityGroup.Key == RuleViolationSeverity.Info)
fileData.InfoViolations = violationsList;
if (violation is RuleTemplateViolation templateRule)
{
args = templateRule.Params.Select(p => EscapeHtml(p)).ToList();
if (reportData.Rules.Any(t => t.Value.Name == templateRule.RuleName))
{
ruleId = reportData.Rules.First(t => t.Value.Name == templateRule.RuleName).Key;
}
else
{
ruleId = reportData.Rules.Count + 1;
reportData.Rules.Add(ruleId, new Rule
{
Name = templateRule.RuleName,
Template = templateRule.RuleTemplate
});
}
}
else
{
ruleId = reportData.Rules.Count + 1;
reportData.Rules.Add(ruleId, new Rule
{
Name = violation.RuleName,
Template = violation.Text,
});
}
var v = new Violation()
{
RuleId = ruleId,
Args = args,
Column = violation.Column,
Line = violation.Line,
};
if (violation.Severity == RuleViolationSeverity.Critical)
{
v.Index = fileData.Violations.Critical.Count + 1;
fileData.Violations.Critical.Add(v);
}
else if (violation.Severity == RuleViolationSeverity.Warning)
{
v.Index = fileData.Violations.Warning.Count + 1;
fileData.Violations.Warning.Add(v);
}
else if (violation.Severity == RuleViolationSeverity.Info)
{
v.Index = fileData.Violations.Info.Count + 1;
fileData.Violations.Info.Add(v);
}
}
reportData.Files.Add(fileData);
@@ -106,9 +146,9 @@ public class HtmlReportFormatter : IReportFormatter
// Добавление диаграммы, если есть
if (diagram != null)
{
reportData.Diagram = new DiagramData
reportData.Diagram = new Diagram
{
MermaidContent = MermaidRenderer.ToMermaidContent(diagram),
Content = MermaidRenderer.ToMermaidContent(diagram),
HasDiagram = true
};
}
@@ -173,36 +213,70 @@ public class HtmlReportFormatter : IReportFormatter
// Классы для сериализации
private class ReportData
{
public List<FileReportData> Files { get; set; } = new();
public DiagramData? Diagram { get; set; }
[JsonPropertyName("f")] // files
public List<FileReport> Files { get; set; } = new();
[JsonPropertyName("r")] // rules
public Dictionary<int, Rule> Rules { get; set; } = new();
[JsonPropertyName("d")] // diagram
public Diagram Diagram { get; set; } = new();
}
private class FileReportData
private class FileReport
{
public string FileName { get; set; } = string.Empty;
public List<ViolationData>? CriticalViolations { get; set; }
public List<ViolationData>? WarningViolations { get; set; }
public List<ViolationData>? InfoViolations { get; set; }
[JsonPropertyName("n")] // name
public string Name { get; set; } = string.Empty;
[JsonIgnore]
public int TotalViolations =>
(CriticalViolations?.Count ?? 0) +
(WarningViolations?.Count ?? 0) +
(InfoViolations?.Count ?? 0);
[JsonPropertyName("v")] // violations
public Violations Violations { get; set; } = new();
}
private class ViolationData
private class Violations
{
[JsonPropertyName("c")] // critical
public List<Violation> Critical { get; set; } = new();
[JsonPropertyName("w")] // warning
public List<Violation> Warning { get; set; } = new();
[JsonPropertyName("i")] // info
public List<Violation> Info { get; set; } = new();
}
private class Violation
{
[JsonPropertyName("i")] // index
public int Index { get; set; }
[JsonPropertyName("l")] // line
public int Line { get; set; }
[JsonPropertyName("c")] // column
public int Column { get; set; }
public string RuleName { get; set; } = string.Empty;
public string Text { get; set; } = string.Empty;
[JsonPropertyName("r")] // ruleId
public int RuleId { get; set; }
[JsonPropertyName("a")] // args (optional)
public List<string>? Args { get; set; }
}
private class DiagramData
private class Rule
{
public string MermaidContent { get; set; } = string.Empty;
[JsonPropertyName("n")] // name
public string Name { get; set; } = string.Empty;
[JsonPropertyName("t")] // template
public string Template { get; set; } = string.Empty;
}
private class Diagram
{
[JsonPropertyName("c")] // content
public string Content { get; set; } = string.Empty;
[JsonPropertyName("h")] // hasDiagram
public bool HasDiagram { get; set; }
}
}