[2150] Inaccurate unmatched closing tag

From the Nuget Package: Web Matrix Loop Helper the documentation cshtml files have the following block of code

   @foreach (var item in movies.Track()) {
        if (Loop.First) {
            @:<table>
        }
        @RenderPage("_Movie.cshtml", new { Category = item.Category, Movies = item.Top5 })
        if (Loop.Last) {
            @:</table>
        }
    }


Resharper states that
            @:</table>

is an error.

Perhaps the tag matching should skip tags that are open or closed inside of if statements?

3 comments

If skip inside code blocks - we can miss this case, for example
{code}
   @foreach (var item in movies.Track()) {
        if (Loop.First) {
            @:<table><tr></trr>
        }
        @RenderPage("_Movie.cshtml", new { Category = item.Category, Movies = item.Top5 })
        if (Loop.Last) {
            @:</table>
        }

    }
{code}

0

I think it'd be better to miss that than offer false positives. Resharper isn't a necromancer living inside of Visual Studio I think it's pretty reasonable to understand branching logic might not be able to be evaulated.

0

I think, we can make compromise - disable this analysis only in line markup - @:
In other cases, direct tags or wrapped by <text> - Razor requres valid tag structure.

0

Please sign in to leave a comment.