59 lines
1.5 KiB
C#
59 lines
1.5 KiB
C#
using SQLLinter.Common;
|
|
using SQLLinter.Infrastructure.Rules.RuleViolations;
|
|
using System.Collections.Concurrent;
|
|
|
|
namespace SQLLinter.Infrastructure.Reporters;
|
|
|
|
public class Reporter : IReporter
|
|
{
|
|
private readonly List<string> _log = new();
|
|
private readonly bool _useLogging;
|
|
|
|
public int? FixedCount { get; set; }
|
|
|
|
private readonly ConcurrentBag<IRuleViolation> ruleViolations = new();
|
|
|
|
public List<IRuleViolation> Violations => ruleViolations.ToList();
|
|
|
|
public Reporter(bool useLogging = false)
|
|
{
|
|
_useLogging = useLogging;
|
|
}
|
|
|
|
public virtual void Report(string message)
|
|
{
|
|
if (_useLogging) _log.Add(message);
|
|
}
|
|
|
|
public List<string> GetLog() => _log;
|
|
|
|
public void ClearViolations()
|
|
{
|
|
Report("Очистка ошибок");
|
|
|
|
ruleViolations.Clear();
|
|
}
|
|
|
|
public void ReportViolation(IRuleViolation violation)
|
|
{
|
|
ruleViolations.Add(violation);
|
|
|
|
Report(violation.ToString());
|
|
}
|
|
|
|
public void ReportViolation(string fileName, int line, int column, RuleViolationSeverity severity, string ruleName, string template, BaseRuleVisitor.ExtractedBlock? snippet, params string[] param)
|
|
{
|
|
ReportViolation(new RuleTemplateViolation()
|
|
{
|
|
FileName = fileName,
|
|
RuleName = ruleName,
|
|
RuleTemplate = template,
|
|
Line = line,
|
|
Column = column,
|
|
Severity = severity,
|
|
Params = param.ToList(),
|
|
Snippet = snippet,
|
|
});
|
|
}
|
|
}
|