Добавьте файлы проекта.
This commit is contained in:
35
SQLLinter/Infrastructure/Rules/AliasStyleConsistencyRule.cs
Normal file
35
SQLLinter/Infrastructure/Rules/AliasStyleConsistencyRule.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Microsoft.SqlServer.TransactSql.ScriptDom;
|
||||
using SQLLinter.Common;
|
||||
|
||||
namespace SQLLinter.Infrastructure.Rules;
|
||||
|
||||
public class AliasStyleConsistencyRule : BaseRuleVisitor
|
||||
{
|
||||
public override string Text => "Алиасы должны использовать единый стиль (AS): {0}";
|
||||
|
||||
public override void Visit(NamedTableReference node)
|
||||
{
|
||||
if (node.Alias != null && node.Alias.QuoteType == QuoteType.NotQuoted)
|
||||
{
|
||||
// ScriptDom не хранит явно "AS", но можно проверять TokenStream
|
||||
var aliasToken = node.Alias;
|
||||
var tokens = node.ScriptTokenStream;
|
||||
if (tokens != null)
|
||||
{
|
||||
int idx = node.FirstTokenIndex;
|
||||
bool hasAs = false;
|
||||
for (int i = idx; i <= node.LastTokenIndex; i++)
|
||||
{
|
||||
if (tokens[i].Text.Equals("AS", System.StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
hasAs = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!hasAs)
|
||||
AddViolation(node, $"[{node.Alias.Value}]");
|
||||
}
|
||||
}
|
||||
base.Visit(node);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user