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