0

I have a C# Razor page that ReSharper (via TeamCity Professional 2019.1.3, so likely 2019.1.1) is flagging as having Potential Code Quality Issues > Not closed tag.

Since I'm only using the version of ReSharper that comes with TeamCity I need to manually add the code to ignore this error.

According to the ReSharper documentation for Potential Code Quality issues the ID is Html.TagNotClosed, which means that I should be able to use the following comment above the code that's triggering this error: ReSharper disable once Html.TagNotClosed

However, if I try either of the following code snippets ReSharper does not ignore this error.

@if (currentRecord % 3 == 1)
{
    // ReSharper disable once Html.TagNotClosed
    <text><div class="row top-spacing-none bottom-spacing-small" data-equalizer="" data-equalizer-mq="medium-up"></text>
}

// alternative

@if (currentRecord % 3 == 1)
{
    <!-- ReSharper disable once Html.TagNotClosed -->
    <text><div class="row top-spacing-none bottom-spacing-small" data-equalizer="" data-equalizer-mq="medium-up"></text>
}

I've confirmed that this is the line it's throwing an error on, and this is the code I want to try, due to the issue covered by Razor doesn't understand unclosed html tags.

What's the proper way to have ReSharper ignore a 'Not closed tag' error in a Razor CSHTML file?

James Skemp
  • 8,018
  • 9
  • 64
  • 107

1 Answers1

1

Currently it's impossible to disable this particular highlighting with "disable once". At least because it happens twice. You can do one of the following:

1. Use disable/restore instead:

// ReSharper disable Html.TagNotClosed
<text><div class="row top-spacing-none bottom-spacing-small" data-equalizer="" data-equalizer-mq="medium-up"></text>
// ReSharper restore Html.TagNotClosed

2. Use @:, ReSharper skips "tag not closed" analysis in it

@: <div class="row top-spacing-none bottom-spacing-small" data-equalizer="" data-equalizer-mq="medium-up">
Dmitry Osinovskiy
  • 9,999
  • 1
  • 47
  • 38
  • First option worked great. I a) didn't even think about those comments for some reason and b) guess I would have expected the error count to drop from 2 on this line to one if I disabled it once. Thanks for the easy solution! – James Skemp Nov 15 '19 at 19:14
  • 1
    Yep, b) is a bug, would be fixed soon – Dmitry Osinovskiy Nov 15 '19 at 23:02