R# errant JavaScript warning about elided elements at end of array

Hello All,

It seems the heuristic code analysis suffers a failure with regard to the JavaScript warning for elements elided at the end of an array.

 

I'm passing a data set to an external script (CloudFlare chart) as JSON that is constructed on the fly from an object, with the following code:

 

Snippet

data: [
    @foreach (var inv in p.Inventory.OrderBy(i => i.DateCreated))
    {
        invi++;
        <text>{
        x: new Date(@inv.DateCreated.Year,
            @(inv.DateCreated.Month - 1),
            @inv.DateCreated.Day,
            @inv.DateCreated.Hour,
            @inv.DateCreated.Minute),
        y: @inv.Quantity
    }</text>
        if (invi < count)
        {
            <text>,</text>
        }
    }
],

 

R# complains about that final "if" block, claiming that the inclusion of the comma in the <text> results in an elided element, even though the if statement is clearly written to omit the trailing comma after the final element.

R#'s suggestion is to remove the comma from the <text> entirely, which breaks the graph.

Should not the heuristics be aware that there is no trailing comma after the final element, and not warn?

Thanks!

Jeff Woods

Bethlehem, PA

 

 

 

0

Please sign in to leave a comment.