Добавлена настройка генерации деталировки
This commit is contained in:
@@ -7,14 +7,13 @@ public abstract class BaseRuleVisitor : TSqlFragmentVisitor, IRule
|
||||
{
|
||||
protected readonly List<Violation> _violations = new();
|
||||
|
||||
protected Dictionary<TSqlFragment, TSqlFragment?> _parents
|
||||
= new Dictionary<TSqlFragment, TSqlFragment?>();
|
||||
protected Dictionary<TSqlFragment, TSqlFragment?>? _parents = null;
|
||||
|
||||
public void SetParents(Dictionary<TSqlFragment, TSqlFragment?> parents)
|
||||
public void SetParents(Dictionary<TSqlFragment, TSqlFragment?>? parents)
|
||||
=> _parents = parents;
|
||||
|
||||
protected TSqlFragment? GetParent(TSqlFragment node)
|
||||
=> _parents.TryGetValue(node, out var parent) ? parent : null;
|
||||
=> _parents is null ? null : _parents.TryGetValue(node, out var parent) ? parent : null;
|
||||
|
||||
|
||||
public int DynamicSqlStartColumn { get; set; }
|
||||
|
||||
@@ -13,5 +13,5 @@ public interface IRule
|
||||
int DynamicSqlStartLine { get; set; }
|
||||
|
||||
IEnumerable<Violation> Analyze(TSqlFragment fragment);
|
||||
void SetParents(Dictionary<TSqlFragment, TSqlFragment?> parents);
|
||||
void SetParents(Dictionary<TSqlFragment, TSqlFragment?>? parents);
|
||||
}
|
||||
@@ -20,5 +20,10 @@ namespace SQLLinter.Core.Interfaces
|
||||
/// Список сторонних плагинов.
|
||||
/// </summary>
|
||||
List<string> Plugins { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Генерировать деталировку ошибки.
|
||||
/// </summary>
|
||||
bool GenerateDetails { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,5 +4,5 @@ namespace SQLLinter.Core.Interfaces;
|
||||
|
||||
public interface IRuleVisitor
|
||||
{
|
||||
void VisitRules(string path, IEnumerable<IRuleException> igoredRules, Stream sqlFileStream);
|
||||
void VisitRules(string path, IEnumerable<IRuleException> igoredRules, Stream sqlFileStream, bool generateDetails);
|
||||
}
|
||||
|
||||
@@ -8,5 +8,6 @@ namespace SQLLinter.Infrastructure.Configuration
|
||||
public int CompatibilityLevel { get; set; }
|
||||
public Dictionary<string, RuleViolationSeverity> Rules { get; set; } = new();
|
||||
public List<string> Plugins { get; set; } = new();
|
||||
public bool GenerateDetails { get; set; } = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,14 +7,16 @@ namespace SQLLinter.Infrastructure.Parser;
|
||||
public class SqlFileProcessor : ISqlFileProcessor
|
||||
{
|
||||
private readonly IRuleVisitor ruleVisitor;
|
||||
private readonly IConfig _config;
|
||||
|
||||
private readonly IRuleExceptionFinder ruleExceptionFinder;
|
||||
|
||||
public SqlFileProcessor(
|
||||
public SqlFileProcessor(IConfig config,
|
||||
IRuleVisitor ruleVisitor,
|
||||
IPluginHandler pluginHandler
|
||||
)
|
||||
{
|
||||
this._config = config;
|
||||
this.ruleVisitor = ruleVisitor;
|
||||
ruleExceptionFinder = new RuleExceptionFinder(pluginHandler.RuleWithNames);
|
||||
}
|
||||
@@ -93,7 +95,7 @@ public class SqlFileProcessor : ISqlFileProcessor
|
||||
|
||||
private void ProcessRules(Stream fileStream, IEnumerable<IRuleException> ignoredRules, string filePath)
|
||||
{
|
||||
ruleVisitor.VisitRules(filePath, ignoredRules, fileStream);
|
||||
ruleVisitor.VisitRules(filePath, ignoredRules, fileStream, this._config.GenerateDetails);
|
||||
}
|
||||
|
||||
private Stream GetFileContents(string filePath)
|
||||
|
||||
@@ -30,7 +30,7 @@ public class SqlRuleVisitor : IRuleVisitor
|
||||
this._sqlStreamReaderBuilder = sqlStreamReaderBuilder;
|
||||
}
|
||||
|
||||
public void VisitRules(string sqlPath, IEnumerable<IRuleException> ignoredRules, Stream sqlFileStream)
|
||||
public void VisitRules(string sqlPath, IEnumerable<IRuleException> ignoredRules, Stream sqlFileStream, bool generateDetails)
|
||||
{
|
||||
var overrides = _overrideFinder.GetOverrideList(sqlFileStream);
|
||||
var overrideArray = overrides as IOverride[] ?? overrides.ToArray();
|
||||
@@ -39,7 +39,7 @@ public class SqlRuleVisitor : IRuleVisitor
|
||||
|
||||
if (sqlFragment == null) return;
|
||||
|
||||
var parentMap = ParentMapBuilder.Build(sqlFragment);
|
||||
Dictionary<TSqlFragment, TSqlFragment?>? parentMap = generateDetails ? ParentMapBuilder.Build(sqlFragment) : null;
|
||||
|
||||
var ruleExceptions = ignoredRules as IRuleException[] ?? ignoredRules.ToArray();
|
||||
if (errors.Any())
|
||||
|
||||
@@ -339,11 +339,7 @@ class ReportRenderer {
|
||||
${details ? `
|
||||
<tr class="violation-detail-row" id="${detailId}" style="display: none;">
|
||||
<td colspan="5" class="detail-cell">
|
||||
<div class="code-block">
|
||||
<div class="code-container">
|
||||
${details} <!-- HTML вставляется как есть, предполагается доверенный источник -->
|
||||
</div>
|
||||
</div>
|
||||
${details} <!-- HTML вставляется как есть, предполагается доверенный источник -->
|
||||
</td>
|
||||
</tr>
|
||||
` : ''}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class Linter
|
||||
|
||||
var ruleVisitor = new SqlRuleVisitor(_pluginHandler, fragmentBuilder, _reporter, sqlStreamReaderBuilder);
|
||||
|
||||
_fileProcessor = new SqlFileProcessor(ruleVisitor, _pluginHandler);
|
||||
_fileProcessor = new SqlFileProcessor(config, ruleVisitor, _pluginHandler);
|
||||
|
||||
_reporter.Report($"SQL Linter загружен...");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user