Изменено формирование ошибок на темплейты
This commit is contained in:
@@ -19,7 +19,7 @@ public class ConditionalBeginEndRule : BaseRuleVisitor, IRule
|
||||
{
|
||||
if (node.ThenStatement is not BeginEndBlockStatement)
|
||||
{
|
||||
AddViolation(Name, Text, GetLineNumber(node), GetColumnNumber(node));
|
||||
AddViolation(node);
|
||||
}
|
||||
|
||||
if (node.ElseStatement != null && node.ElseStatement is not BeginEndBlockStatement && node.ElseStatement is not IfStatement)
|
||||
|
||||
@@ -11,7 +11,7 @@ public class IndexHintRule : BaseRuleVisitor
|
||||
{
|
||||
if (node.HintKind == TableHintKind.Index)
|
||||
{
|
||||
AddViolation(Name, Text, GetLineNumber(node), GetColumnNumber(node));
|
||||
AddViolation(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class InsertValuesInsteadOfSelectRule : BaseRuleVisitor
|
||||
// Если в SELECT нет таблиц (т.е. просто SELECT 1,2,3)
|
||||
if (query.FromClause == null || query.FromClause.TableReferences.Count == 0)
|
||||
{
|
||||
AddViolation(Name, Text, GetLineNumber(node), GetColumnNumber(node));
|
||||
AddViolation(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class KeywordCapitalizationRule : BaseRuleVisitor, IRule
|
||||
var tabsOnLine = ColumnNumberCalculator.CountTabsBeforeToken(token.Line, index, node.ScriptTokenStream);
|
||||
var column = ColumnNumberCalculator.GetColumnNumberBeforeToken(tabsOnLine, token);
|
||||
|
||||
AddViolation(Name, GetText(token.Text), GetLineNumber(token), column + dynamicSQLAdjustment);
|
||||
AddViolation(Name, Text, GetLineNumber(token), column + dynamicSQLAdjustment, token.Text);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public class MultiTableAliasRule : BaseRuleVisitor, IRule
|
||||
tableName = SQLHelpers.ObjectGetFullName(namedTable.SchemaObject);
|
||||
}
|
||||
|
||||
AddViolation(Name, GetText(tableName), GetLineNumber(childNode), column + dynamicSqlAdjustment);
|
||||
AddViolation(Name, Text, GetLineNumber(childNode), column + dynamicSqlAdjustment, tableName);
|
||||
}
|
||||
|
||||
var childTableJoinVisitor = new ChildTableJoinVisitor();
|
||||
|
||||
@@ -79,7 +79,7 @@ public class ProcedureLoggingReturnRule : BaseRuleVisitor
|
||||
|
||||
if ((hasDebugLog || hasLabelFinish) || hasReturn)
|
||||
{
|
||||
returnPositions.ForEach(t => AddViolation(Name, GetText(name), t.Line, t.Column));
|
||||
returnPositions.ForEach(t => AddViolation(Name, Text, t.Line, t.Column, name));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,46 +4,25 @@ namespace SQLLinter.Infrastructure.Rules.RuleViolations
|
||||
{
|
||||
public class RuleViolation : IRuleViolation
|
||||
{
|
||||
public RuleViolation(string fileName, string ruleName, string text, int startLine, int startColumn, RuleViolationSeverity severity)
|
||||
{
|
||||
FileName = fileName;
|
||||
RuleName = ruleName;
|
||||
Text = text;
|
||||
Line = startLine;
|
||||
Column = startColumn;
|
||||
Severity = severity;
|
||||
}
|
||||
required public string FileName { get; init; }
|
||||
|
||||
public RuleViolation(string fileName, string ruleName, int startLine, int startColumn)
|
||||
{
|
||||
FileName = fileName;
|
||||
RuleName = ruleName;
|
||||
Line = startLine;
|
||||
Column = startColumn;
|
||||
}
|
||||
required public int Column { get; set; }
|
||||
|
||||
public RuleViolation(string ruleName, int startLine, int startColumn)
|
||||
{
|
||||
RuleName = ruleName;
|
||||
Line = startLine;
|
||||
Column = startColumn;
|
||||
}
|
||||
required public int Line { get; set; }
|
||||
|
||||
public int Column { get; set; }
|
||||
required public string RuleName { get; init; }
|
||||
|
||||
public string FileName { get; set; }
|
||||
required public RuleViolationSeverity Severity { get; init; }
|
||||
|
||||
public int Line { get; set; }
|
||||
virtual public string Text { get; set; }
|
||||
}
|
||||
|
||||
public string RuleName { get; set; }
|
||||
public class RuleTemplateViolation : RuleViolation
|
||||
{
|
||||
override public string Text => string.Format(RuleTemplate, Params.ToArray());
|
||||
|
||||
public RuleViolationSeverity Severity { get; set; }
|
||||
required public string RuleTemplate { get; init; }
|
||||
|
||||
public string Text { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $@"{Severity.ToString().ToUpper()}: L{Line} C{Column} {FileName} ""{Text}""";
|
||||
}
|
||||
public List<string> Params { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user