public override void Analyze(KustoCode code, List<Diagnostic> diagnostics, CancellationToken cancellationToken)
        {
            foreach (var node in code.Syntax.GetDescendants<BinaryExpression>())
            {
                if (!node.Right.IsConstant && !node.Left.IsConstant)
                {
                    continue;
                }

                if (node.Kind == SyntaxKind.EqualExpression ||
                    node.Kind == SyntaxKind.HasExpression ||
                    node.Kind == SyntaxKind.NotEqualExpression ||
                    node.Kind == SyntaxKind.NotHasExpression ||
                    node.Kind == SyntaxKind.StartsWithExpression ||
                    node.Kind == SyntaxKind.NotStartsWithExpression)
                {
                    string constValue = null;

                    if (node.Right.IsConstant && node.Right.ResultType == ScalarTypes.String)
                    {
                        constValue = node.Right.ConstantValue as string;
                    }
                    else if (node.Left.IsConstant && node.Left.ResultType == ScalarTypes.String)
                    {
                        constValue = node.Left.ConstantValue as string;
                    }

                    if (!string.IsNullOrEmpty(constValue) && constValue.Length < 4)
                    {
                        diagnostics.Add(_diagnostic.WithLocation(node));
                    }
                }
            }
        }
 public override void Analyze(KustoCode code, List <Diagnostic> diagnostics, CancellationToken cancellationToken)
 {
     foreach (var node in code.Syntax.GetDescendants <FunctionCallExpression>(fc => fc.ReferencedSymbol == Functions.FormatDatetime))
     {
         if (IsInFilter(node) || IsInPredicate(node))
         {
             diagnostics.Add(_diagnostic.WithLocation(node));
         }
     }
 }
Beispiel #3
0
 public override void Analyze(KustoCode code, List <Diagnostic> diagnostics, CancellationToken cancellationToken)
 {
     foreach (var node in code.Syntax.GetDescendants <BinaryExpression>())
     {
         if (node.Kind == SyntaxKind.ContainsExpression ||
             node.Kind == SyntaxKind.NotContainsExpression ||
             node.Kind == SyntaxKind.ContainsCsExpression ||
             node.Kind == SyntaxKind.NotContainsCsExpression)
         {
             diagnostics.Add(_diagnostic.WithLocation(node.Operator));
         }
     }
 }
        public override IReadOnlyList <Diagnostic> Analyze(KustoCode code, CancellationToken cancellationToken)
        {
            var diagnostics = new List <Diagnostic>();

            foreach (var node in code.Syntax.GetDescendants <BinaryExpression>())
            {
                if (node.Kind == SyntaxKind.ContainsExpression ||
                    node.Kind == SyntaxKind.NotContainsExpression ||
                    node.Kind == SyntaxKind.ContainsCsExpression ||
                    node.Kind == SyntaxKind.NotContainsCsExpression)
                {
                    diagnostics.Add(_diagnostic.WithLocation(node.Operator));
                }
            }

            return(diagnostics);
        }
 public override void Analyze(KustoCode code, List <Diagnostic> diagnostics, CancellationToken cancellationToken)
 {
     foreach (var node in code.Syntax.GetDescendants <FunctionCallExpression>())
     {
         if ((node.ReferencedSymbol == Functions.IsNull ||
              node.ReferencedSymbol == Functions.IsNotNull) &&
             node.ArgumentList.Expressions.Count > 0 &&
             node.ArgumentList.Expressions[0].Element.ResultType == ScalarTypes.String)
         {
             if (node.ReferencedSymbol == Functions.IsNull)
             {
                 diagnostics.Add(_diagnostic_equals.WithLocation(node));
             }
             else
             {
                 diagnostics.Add(_diagnostic_not_equals.WithLocation(node));
             }
         }
     }
 }
 public override void Analyze(KustoCode code, List <Diagnostic> diagnostics, CancellationToken cancellationToken)
 {
     foreach (var node in code.Syntax.GetDescendants <FunctionCallExpression>())
     {
         if ((node.ReferencedSymbol == Functions.ToBool || node.ReferencedSymbol == Functions.ToBoolean) && node.ArgumentList.Expressions.Count > 0)
         {
             var firstArgumentType = node.ArgumentList.Expressions[0].Element.ResultType;
             if (firstArgumentType == ScalarTypes.DateTime ||
                 firstArgumentType == ScalarTypes.Int ||
                 firstArgumentType == ScalarTypes.Decimal ||
                 firstArgumentType == ScalarTypes.Guid ||
                 firstArgumentType == ScalarTypes.Long ||
                 firstArgumentType == ScalarTypes.Real ||
                 firstArgumentType == ScalarTypes.TimeSpan)
             {
                 diagnostics.Add(_diagnostic.WithLocation(node));
             }
         }
     }
 }
        private static Diagnostic SetLocation(Diagnostic d, SyntaxElement location)
        {
            if (location.Width == 0)
            {
                if (location is SyntaxToken token)
                {
                    // move location to next token if it is
                    // lest than two spaces away and not separated by line breaks
                    var next = token.GetNextToken();

                    if (next != null &&
                        (next.TextStart - token.End) < 2 &&
                        !TextFacts.HasLineBreaks(next.Trivia))
                    {
                        location = next;
                    }
                }
            }

            return(d.WithLocation(location));
        }
Beispiel #8
0
 public static string DumpDiagnostic(Diagnostic diagnostic)
 {
     return(string.Format("'{0}' {1}",
                          diagnostic.Location.SourceTree.GetText().ToString(diagnostic.Location.SourceSpan),
                          DiagnosticFormatter.Instance.Format(diagnostic.WithLocation(Location.None), EnsureEnglishUICulture.PreferredOrNull)));
 }
 internal override Diagnostic WithLocation(Location location)
 {
     return(new CompilerDiagnostic(_original.WithLocation(location), _properties));
 }
Beispiel #10
0
 public static string DumpDiagnostic(Diagnostic diagnostic)
 {
     return string.Format("'{0}' {1}",
         diagnostic.Location.SourceTree.GetText().ToString(diagnostic.Location.SourceSpan),
         DiagnosticFormatter.Instance.Format(diagnostic.WithLocation(Location.None), EnsureEnglishUICulture.PreferredOrNull));
 }
 public static string DumpDiagnostic(Diagnostic diagnostic)
 {
     return string.Format("'{0}' {1}",
         diagnostic.Location.SourceTree.GetText().ToString(diagnostic.Location.SourceSpan),
         diagnostic.WithLocation(Location.None).ToString());
 }
Beispiel #12
0
 public static string DumpDiagnostic(Diagnostic diagnostic)
 {
     return(string.Format("'{0}' {1}",
                          diagnostic.Location.SourceTree.GetText().ToString(diagnostic.Location.SourceSpan),
                          diagnostic.WithLocation(Location.None).ToString()));
 }