Добавьте файлы проекта.
This commit is contained in:
51
SQLLinter/Infrastructure/Rules/DuplicateEmptyLineRule.cs
Normal file
51
SQLLinter/Infrastructure/Rules/DuplicateEmptyLineRule.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using Microsoft.SqlServer.TransactSql.ScriptDom;
|
||||
using SQLLinter.Common;
|
||||
using SQLLinter.Common.Helpers;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SQLLinter.Infrastructure.Rules;
|
||||
|
||||
public class DuplicateEmptyLineRule : BaseRuleVisitor, IRule
|
||||
{
|
||||
private static readonly Regex EmptyLineRegex = new(@"^\s*$", RegexOptions.Compiled);
|
||||
|
||||
|
||||
public override string Text => "Обнаружен дубликат новой строки";
|
||||
|
||||
public override void Visit(TSqlScript node)
|
||||
{
|
||||
var isEmptyLine = false;
|
||||
var fileLines = FixHelpers.GetString(node)
|
||||
.Split('\n')
|
||||
.ToList();
|
||||
|
||||
for (var i = 0; i < fileLines.Count; i++)
|
||||
{
|
||||
if (EmptyLineRegex.IsMatch(fileLines[i]))
|
||||
{
|
||||
if (isEmptyLine)
|
||||
{
|
||||
AddViolation(Name, Text, i + 1, 1);
|
||||
}
|
||||
|
||||
isEmptyLine = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
isEmptyLine = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void FixViolation(List<string> fileLines, IRuleViolation ruleViolation, FileLineActions actions)
|
||||
{
|
||||
if (ruleViolation.Line - 1 == fileLines.Count)
|
||||
{
|
||||
actions.RemoveAt(ruleViolation.Line - 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
actions.RemoveAt(ruleViolation.Line - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user