Ejemplo n.º 1
0
 private static IValidationError MultipleStatementsCheck(IAstNode node, LintOptions options, bool projectedBuffer)
 {
     if (options.MultipleStatements && node is TokenNode t && t.Token.TokenType == RTokenType.Semicolon)
     {
         var tp = node.Root.TextProvider;
         if (!tp.IsNewLineAfterPosition(node.End))
         {
             // # comment is OK but comments are not part of the AST.
             var lineBreakIndex  = tp.IndexOf('\n', node.End);
             var trailingTextEnd = lineBreakIndex >= 0 ? lineBreakIndex : tp.Length;
             var trailingText    = tp.GetText(TextRange.FromBounds(node.End, trailingTextEnd));
             var tokens          = new RTokenizer().Tokenize(trailingText);
             var offendingTokens = tokens.Where(x => x.TokenType != RTokenType.Comment);
             if (offendingTokens.Any())
             {
                 var squiggle = TextRange.FromBounds(node.End + offendingTokens.First().Start, node.End + offendingTokens.Last().End);
                 return(new ValidationWarning(squiggle, Resources.Lint_MultipleStatementsInLine, ErrorLocation.Token));
             }
         }
     }
     return(null);
 }