public override IList <SqlRuleProblem> Analyze(SqlRuleExecutionContext ruleExecutionContext) { var problems = new List <SqlRuleProblem>(); var sqlObject = ruleExecutionContext.ModelElement; var sqlObjectSourceInfo = sqlObject.GetSourceInformation(); if (ruleExecutionContext.ScriptFragment.ScriptTokenStream != null) { foreach (var token in ruleExecutionContext.ScriptFragment.ScriptTokenStream) { if (IsKeyword(token) && token.Text?.ToUpper() != token.Text) { var problem = new SqlRuleProblem(string.Format(Message, token.Text), sqlObject); problem.SetSourceInformation(new SourceInformation(sqlObjectSourceInfo.SourceName, token.Line, token.Column)); problems.Add(problem); } } } return(problems); }
protected override IList <SqlRuleProblem> ElicitProblems(TSqlFragment fragment, RuleDescriptor ruleDescriptor, string elementName, TSqlObject modelElement) { var problems = new List <SqlRuleProblem>(); var visitor = new DataTypesVisitor(); fragment.Accept(visitor); foreach (var columnDef in visitor.ColumnDefinitions) { var description = string.Format(CultureInfo.CurrentCulture, ruleDescriptor.DisplayDescription); var problem = new SqlRuleProblem(description, modelElement) { Severity = SqlRuleProblemSeverity.Error }; problem.SetSourceInformation(new SourceInformation(problem.SourceName, columnDef.StartLine, columnDef.StartColumn)); problems.Add(problem); } foreach (var parameter in visitor.ProcedureParameters) { var description = string.Format(CultureInfo.CurrentCulture, ruleDescriptor.DisplayDescription); var problem = new SqlRuleProblem(description, modelElement) { Severity = SqlRuleProblemSeverity.Error }; problem.SetSourceInformation(new SourceInformation(problem.SourceName, parameter.StartLine, parameter.StartColumn)); problems.Add(problem); } return(problems); }
protected override IList <SqlRuleProblem> ElicitProblems(TSqlFragment fragment, RuleDescriptor ruleDescriptor, string elementName, TSqlObject modelElement) { var problems = new List <SqlRuleProblem>(); foreach (var token in fragment.ScriptTokenStream) { if (token.IsKeyword() && token.Text.Any(char.IsLower)) { var description = string.Format(CultureInfo.CurrentCulture, ruleDescriptor.DisplayDescription); var problem = new SqlRuleProblem(description, modelElement) { Severity = SqlRuleProblemSeverity.Error }; problem.SetSourceInformation(new SourceInformation(problem.SourceName, token.Line, token.Column)); problems.Add(problem); } } return(problems); }