Добавьте файлы проекта.
This commit is contained in:
39
SQLLinter/Infrastructure/Rules/DuplicateGoRule.cs
Normal file
39
SQLLinter/Infrastructure/Rules/DuplicateGoRule.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using Microsoft.SqlServer.TransactSql.ScriptDom;
|
||||
using SQLLinter.Common;
|
||||
|
||||
namespace SQLLinter.Infrastructure.Rules;
|
||||
|
||||
public class DuplicateGoRule : BaseRuleVisitor, IRule
|
||||
{
|
||||
|
||||
public override string Text => "Обнаружен дублирующийся оператор GO";
|
||||
|
||||
public override void Visit(TSqlScript node)
|
||||
{
|
||||
TSqlParserToken lastToken = null;
|
||||
TSqlParserToken currentToken;
|
||||
for (var index = 0; index <= node.LastTokenIndex; index++)
|
||||
{
|
||||
var tokenType = node.ScriptTokenStream[index].TokenType;
|
||||
|
||||
// Skip these
|
||||
switch (tokenType)
|
||||
{
|
||||
case TSqlTokenType.MultilineComment:
|
||||
case TSqlTokenType.WhiteSpace:
|
||||
case TSqlTokenType.Semicolon:
|
||||
continue;
|
||||
}
|
||||
|
||||
currentToken = node.ScriptTokenStream[index];
|
||||
|
||||
if (tokenType is TSqlTokenType.Go &&
|
||||
lastToken?.TokenType is TSqlTokenType.Go)
|
||||
{
|
||||
AddViolation(Name, Text, currentToken.Line, currentToken.Column);
|
||||
}
|
||||
|
||||
lastToken = currentToken;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user