From 507c466b5d7551ce9f5f8160db92a1884c2f6b92 Mon Sep 17 00:00:00 2001 From: FrigaT Date: Mon, 29 Dec 2025 01:40:25 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=BD=D1=8B=20=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Infrastructure/Rules/ConditionalBeginEndRule.cs | 12 +++++++++--- .../Rules/TempTableModificationRule.cs | 6 +++--- SQLLinter/Infrastructure/Rules/UpdateWhereRule.cs | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/SQLLinter/Infrastructure/Rules/ConditionalBeginEndRule.cs b/SQLLinter/Infrastructure/Rules/ConditionalBeginEndRule.cs index 7b758fb..d364b17 100644 --- a/SQLLinter/Infrastructure/Rules/ConditionalBeginEndRule.cs +++ b/SQLLinter/Infrastructure/Rules/ConditionalBeginEndRule.cs @@ -17,14 +17,20 @@ public class ConditionalBeginEndRule : BaseRuleVisitor, IRule public override void Visit(IfStatement node) { - if (node.ThenStatement is not BeginEndBlockStatement) + if (node.ThenStatement != null && node.ThenStatement is not BeginEndBlockStatement) { - AddViolation(node); + if (node.ThenStatement.StartLine != node.StartLine || node.ScriptTokenStream.Where(t => t.Offset <= node.ThenStatement.StartOffset + node.ThenStatement.FragmentLength).Max(t => t.Line) != node.StartLine) + { + AddViolation(node.ThenStatement); + } } if (node.ElseStatement != null && node.ElseStatement is not BeginEndBlockStatement && node.ElseStatement is not IfStatement) { - AddViolation(Name, Text, GetLineNumber(node.ElseStatement), GetColumnNumber(node.ElseStatement)); + if (node.ElseStatement.StartLine != node.StartLine || node.ScriptTokenStream.Where(t => t.Offset <= node.ElseStatement.StartOffset + node.ElseStatement.FragmentLength).Max(t => t.Line) != node.StartLine) + { + AddViolation(node.ElseStatement); + } } } diff --git a/SQLLinter/Infrastructure/Rules/TempTableModificationRule.cs b/SQLLinter/Infrastructure/Rules/TempTableModificationRule.cs index 36b14bd..915614b 100644 --- a/SQLLinter/Infrastructure/Rules/TempTableModificationRule.cs +++ b/SQLLinter/Infrastructure/Rules/TempTableModificationRule.cs @@ -12,7 +12,7 @@ public class TempTableModificationRule : BaseRuleVisitor { if (node.UpdateSpecification.Target is NamedTableReference tbl && tbl.SchemaObject.BaseIdentifier.Value.StartsWith("#")) { - AddViolation(node, SQLHelpers.ObjectGetFullName(tbl.SchemaObject)); + AddViolation(node.UpdateSpecification.Target, SQLHelpers.ObjectGetFullName(tbl.SchemaObject)); } } @@ -20,7 +20,7 @@ public class TempTableModificationRule : BaseRuleVisitor { if (node.DeleteSpecification.Target is NamedTableReference tbl && tbl.SchemaObject.BaseIdentifier.Value.StartsWith("#")) { - AddViolation(node, SQLHelpers.ObjectGetFullName(tbl.SchemaObject)); + AddViolation(node.DeleteSpecification.Target, SQLHelpers.ObjectGetFullName(tbl.SchemaObject)); } } @@ -28,7 +28,7 @@ public class TempTableModificationRule : BaseRuleVisitor { if (node.SchemaObjectName.BaseIdentifier.Value.StartsWith("#")) { - AddViolation(node, SQLHelpers.ObjectGetFullName(node.SchemaObjectName)); + AddViolation(node.SchemaObjectName, SQLHelpers.ObjectGetFullName(node.SchemaObjectName)); } } } diff --git a/SQLLinter/Infrastructure/Rules/UpdateWhereRule.cs b/SQLLinter/Infrastructure/Rules/UpdateWhereRule.cs index 6d65e69..2dfa6a1 100644 --- a/SQLLinter/Infrastructure/Rules/UpdateWhereRule.cs +++ b/SQLLinter/Infrastructure/Rules/UpdateWhereRule.cs @@ -23,6 +23,6 @@ public class UpdateWhereRule : BaseRuleVisitor, IRule .Select(t => t.Text) ); - AddViolation(node, name); + AddViolation(node.Target, name); } }