diff --git a/SQLLinter.CLI/Program.cs b/SQLLinter.CLI/Program.cs index 7cb035c..6d6590f 100644 --- a/SQLLinter.CLI/Program.cs +++ b/SQLLinter.CLI/Program.cs @@ -43,7 +43,8 @@ namespace SQLLinter.CLI ["UpdateWhere"] = Common.RuleViolationSeverity.Critical, ["UpperLower"] = Common.RuleViolationSeverity.Critical, ["SetVariable"] = Common.RuleViolationSeverity.Critical, - } + }, + GenerateDetails = false, }; //var linter = new Linter(con, rep); diff --git a/SQLLinter/Common/BaseRuleVisitor.cs b/SQLLinter/Common/BaseRuleVisitor.cs index 80ffa50..36a1ad8 100644 --- a/SQLLinter/Common/BaseRuleVisitor.cs +++ b/SQLLinter/Common/BaseRuleVisitor.cs @@ -7,14 +7,13 @@ public abstract class BaseRuleVisitor : TSqlFragmentVisitor, IRule { protected readonly List _violations = new(); - protected Dictionary _parents - = new Dictionary(); + protected Dictionary? _parents = null; - public void SetParents(Dictionary parents) + public void SetParents(Dictionary? 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; } diff --git a/SQLLinter/Common/IRule.cs b/SQLLinter/Common/IRule.cs index 82e805f..b0cb822 100644 --- a/SQLLinter/Common/IRule.cs +++ b/SQLLinter/Common/IRule.cs @@ -13,5 +13,5 @@ public interface IRule int DynamicSqlStartLine { get; set; } IEnumerable Analyze(TSqlFragment fragment); - void SetParents(Dictionary parents); + void SetParents(Dictionary? parents); } \ No newline at end of file diff --git a/SQLLinter/Core/Interfaces/IConfig.cs b/SQLLinter/Core/Interfaces/IConfig.cs index 54f3eba..69e317c 100644 --- a/SQLLinter/Core/Interfaces/IConfig.cs +++ b/SQLLinter/Core/Interfaces/IConfig.cs @@ -20,5 +20,10 @@ namespace SQLLinter.Core.Interfaces /// Список сторонних плагинов. /// List Plugins { get; set; } + + /// + /// Генерировать деталировку ошибки. + /// + bool GenerateDetails { get; set; } } } diff --git a/SQLLinter/Core/Interfaces/IRuleVisitor.cs b/SQLLinter/Core/Interfaces/IRuleVisitor.cs index 9474f05..45e461b 100644 --- a/SQLLinter/Core/Interfaces/IRuleVisitor.cs +++ b/SQLLinter/Core/Interfaces/IRuleVisitor.cs @@ -4,5 +4,5 @@ namespace SQLLinter.Core.Interfaces; public interface IRuleVisitor { - void VisitRules(string path, IEnumerable igoredRules, Stream sqlFileStream); + void VisitRules(string path, IEnumerable igoredRules, Stream sqlFileStream, bool generateDetails); } diff --git a/SQLLinter/Infrastructure/Configuration/Config.cs b/SQLLinter/Infrastructure/Configuration/Config.cs index ddcf1ac..5ccd1eb 100644 --- a/SQLLinter/Infrastructure/Configuration/Config.cs +++ b/SQLLinter/Infrastructure/Configuration/Config.cs @@ -8,5 +8,6 @@ namespace SQLLinter.Infrastructure.Configuration public int CompatibilityLevel { get; set; } public Dictionary Rules { get; set; } = new(); public List Plugins { get; set; } = new(); + public bool GenerateDetails { get; set; } = false; } } diff --git a/SQLLinter/Infrastructure/Parser/SqlFileProcessor.cs b/SQLLinter/Infrastructure/Parser/SqlFileProcessor.cs index d85387a..5f4a1b4 100644 --- a/SQLLinter/Infrastructure/Parser/SqlFileProcessor.cs +++ b/SQLLinter/Infrastructure/Parser/SqlFileProcessor.cs @@ -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 ignoredRules, string filePath) { - ruleVisitor.VisitRules(filePath, ignoredRules, fileStream); + ruleVisitor.VisitRules(filePath, ignoredRules, fileStream, this._config.GenerateDetails); } private Stream GetFileContents(string filePath) diff --git a/SQLLinter/Infrastructure/Parser/SqlRuleVisitor.cs b/SQLLinter/Infrastructure/Parser/SqlRuleVisitor.cs index 2380083..68be2eb 100644 --- a/SQLLinter/Infrastructure/Parser/SqlRuleVisitor.cs +++ b/SQLLinter/Infrastructure/Parser/SqlRuleVisitor.cs @@ -30,7 +30,7 @@ public class SqlRuleVisitor : IRuleVisitor this._sqlStreamReaderBuilder = sqlStreamReaderBuilder; } - public void VisitRules(string sqlPath, IEnumerable ignoredRules, Stream sqlFileStream) + public void VisitRules(string sqlPath, IEnumerable 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? parentMap = generateDetails ? ParentMapBuilder.Build(sqlFragment) : null; var ruleExceptions = ignoredRules as IRuleException[] ?? ignoredRules.ToArray(); if (errors.Any()) diff --git a/SQLLinter/Infrastructure/Reporters/Formatters/Html/v2/HtmlFormatter_v2.js b/SQLLinter/Infrastructure/Reporters/Formatters/Html/v2/HtmlFormatter_v2.js index f01ad0a..e366a5c 100644 --- a/SQLLinter/Infrastructure/Reporters/Formatters/Html/v2/HtmlFormatter_v2.js +++ b/SQLLinter/Infrastructure/Reporters/Formatters/Html/v2/HtmlFormatter_v2.js @@ -339,11 +339,7 @@ class ReportRenderer { ${details ? ` -
-
- ${details} -
-
+ ${details} ` : ''} diff --git a/SQLLinter/Linter.cs b/SQLLinter/Linter.cs index 99b0773..0152eb4 100644 --- a/SQLLinter/Linter.cs +++ b/SQLLinter/Linter.cs @@ -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 загружен..."); }