Files
SQLLint/SQLLinter/Infrastructure/Rules/NullComparisonRule.cs

21 lines
718 B
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Microsoft.SqlServer.TransactSql.ScriptDom;
using SQLLinter.Common;
namespace SQLLinter.Infrastructure.Rules;
public class NullComparisonRule : BaseRuleVisitor
{
public override string Text => "Запрещено сравнение с NULL через '='. Используйте 'IS'': {0}";
public override void Visit(BooleanComparisonExpression node)
{
// Если один из операндов - NULL
if (node.FirstExpression is NullLiteral || node.SecondExpression is NullLiteral)
{
// Это значит, что используется = и т.п. с NULL
AddViolation(node, node.ToString());
}
base.Visit(node);
}
}