Skip to content

Commit

Permalink
Timer analyzer fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelldi committed Nov 27, 2023
1 parent 2063e24 commit aef605d
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected override void Run(IAttribute element, ElementProblemAnalyzerData data,

if (!FunctionAppFinder.IsTimerTriggerAttribute(typeElement)) return;

var expressionArgument = element.Arguments.First().Value;
var expressionArgument = element.Arguments.FirstOrDefault()?.Value;
if (expressionArgument is null || !expressionArgument.Type().IsString()) return;

var literal = (expressionArgument as ICSharpLiteralExpression)?.ConstantValue.StringValue;
Expand All @@ -65,24 +65,26 @@ protected override void Run(IAttribute element, ElementProblemAnalyzerData data,
var mayBeTimeSpanSchedule = literal.Contains(":");
if (mayBeTimeSpanSchedule)
{
if (IsValidTimeSpanSchedule(literal, out var errorMessage, out var description))
if (IsValidTimeSpanSchedule(literal, out var errorMessage, out var description) &&
!string.IsNullOrEmpty(description))
{
consumer.AddHighlighting(new TimerTriggerCronExpressionHint(description, expressionArgument,
expressionArgument.GetDocumentEndOffset()));
}
else if (!string.IsNullOrEmpty(description))
else
{
consumer.AddHighlighting(new TimerTriggerCronExpressionError(expressionArgument, errorMessage));
}
}
else
{
if (IsValidCrontabSchedule(literal, out var errorMessage, out var description))
if (IsValidCrontabSchedule(literal, out var errorMessage, out var description) &&
!string.IsNullOrEmpty(description))
{
consumer.AddHighlighting(new TimerTriggerCronExpressionHint(description, expressionArgument,
expressionArgument.GetDocumentEndOffset()));
}
else if (!string.IsNullOrEmpty(description))
else
{
consumer.AddHighlighting(new TimerTriggerCronExpressionError(expressionArgument, errorMessage));
}
Expand Down

0 comments on commit aef605d

Please sign in to comment.