Skip to content

Warn for empty outer tags when context switching from C# to markup - #84764

Merged
davidwengier merged 2 commits into
dotnet:mainfrom
davidwengier:restore-razor-rz1022
Aug 6, 2026
Merged

Warn for empty outer tags when context switching from C# to markup#84764
davidwengier merged 2 commits into
dotnet:mainfrom
davidwengier:restore-razor-rz1022

Conversation

@davidwengier

@davidwengier davidwengier commented Aug 5, 2026

Copy link
Copy Markdown
Member

Redo of dotnet/razor#12811 now that we have warning wave

Fixes dotnet/razor#12810

@<>...</> used as a markup template transition compiles silently but throws a runtime. Now it warns too. The diagnostic was pre-existing, but unused.

Microsoft Reviewers: Open in CodeFlow

davidwengier and others added 2 commits August 5, 2026 13:09
Emit RZ1022 for empty outer tags used to switch from C# to markup.
Gate it behind Razor warning level 11.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 1df2b838-1c9e-4e8d-b097-28ef6026c149
Cover level 10 suppression and level 11 reporting with separate integration tests.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 1df2b838-1c9e-4e8d-b097-28ef6026c149
@davidwengier
davidwengier requested a review from a team as a code owner August 5, 2026 03:12
Copilot AI review requested due to automatic review settings August 5, 2026 03:12
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Razor legacy HTML markup parser to emit an existing diagnostic (RZ1022) when the parser encounters an empty outer tag (<>) while parsing markup-in-code scenarios, and converts that diagnostic to a warning gated by Razor warning waves (warning level 11).

Changes:

  • Change RZ1022 (“Outer tag is missing a name…”) from an error descriptor to a warning descriptor with warningLevel: 11.
  • Add a targeted parser check to report RZ1022 for @{ <>... } / @<>...-style transitions when the outer tag name is empty.
  • Add/adjust parser baselines and integration tests to validate the diagnostic and warning-level gating behavior.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Razor/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorDiagnosticFactory.cs Reclassifies RZ1022 as a wave-gated warning (level 11).
src/Razor/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Legacy/HtmlMarkupParser.cs Emits RZ1022 when encountering an empty outer tag in MarkupInCodeBlock.
src/Razor/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/HtmlTagsTest/EmptyTag.diag.txt Adds expected RZ1022 warning baseline for EmptyTag.
src/Razor/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/HtmlErrorTest/EmptyOuterTagProducesWarningInTemplateExpression.stree.txt Adds parse tree baseline for template-expression repro.
src/Razor/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/HtmlErrorTest/EmptyOuterTagProducesWarningInTemplateExpression.diag.txt Adds expected RZ1022 warning baseline for template-expression repro.
src/Razor/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/HtmlErrorTest/EmptyOuterTagProducesWarningInTemplateExpression.cspans.txt Adds C# spans baseline for template-expression repro.
src/Razor/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/HtmlErrorTest/EmptyOuterTagProducesWarningInMarkupBlock.stree.txt Adds parse tree baseline for markup-block repro.
src/Razor/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/HtmlErrorTest/EmptyOuterTagProducesWarningInMarkupBlock.diag.txt Adds expected RZ1022 warning baseline for markup-block repro.
src/Razor/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/HtmlErrorTest/EmptyOuterTagProducesWarningInMarkupBlock.cspans.txt Adds C# spans baseline for markup-block repro.
src/Razor/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Legacy/HtmlErrorTest.cs Adds regression tests for the two repro shapes and tags them with a WorkItem link.
src/Razor/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/DefaultRazorProjectEngineIntegrationTest.cs Validates warning-wave suppression/reporting at Razor warning levels 10 vs 11.
src/Razor/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/HtmlTagsTest/EmptyTag.diag.txt Adds matching RZ1022 warning baseline for legacy test assets.

@davidwengier davidwengier changed the title Mark empty outer tags as errors when context switching from C# to markup Warn for empty outer tags when context switching from C# to markup Aug 5, 2026
@davidwengier
davidwengier merged commit 2bdb3a3 into dotnet:main Aug 6, 2026
27 checks passed
@davidwengier
davidwengier deleted the restore-razor-rz1022 branch August 6, 2026 23:08
JoeRobich pushed a commit that referenced this pull request Aug 11, 2026
Backs the `features/sonic` decl/impl split out of `main` to unblock
insertion. Reverts the merge (#84778) and the commits that stacked on
top of it and cannot stand without it.

## What reverts

- **#84778** `Merge/sonic into main` -- the whole feature body (reverted
with `-m 1`, keeping pre-sonic `main`).
- **#84818** fallback child-content discovery fix -- patches sonic's
fast/slow discovery, which no longer exists.
- **#84813** restore `GetCSharpDocument()`/`GeneratedCode` -- these were
re-added to shim sonic's API removal; reverting the merge restores the
originals, so the shim would double-define them.
- **#84795** always pass C# formatting options -- edits
`CSharpFormattingOptionsHelper.cs`, a file that only exists because of
sonic.

## What is kept

The other post-merge commits are independent of sonic and stay: arcade
bumps, SDL param removal, CS8802, #84758 (syntax-tree sharing), and the
two Razor features that merely shared files -- **#84760**
(unbound-attribute warnings) and **#84764** (empty-outer-tag warning).

Preserving #84760 needed one manual resolution in
`UnresolvedAttributeIntermediateNode.cs`: sonic added the
`CloneNode()`/`Clone()` overrides and #84760 later added one property
assignment inside `CloneNode`. The overrides are sonic infrastructure
and go with the revert; #84760's `IsDirectiveAttributeCandidate`
property and all its real usages are untouched.

## Validation

- `Razor.slnf` builds clean (compiler + all tooling projects, including
the ones #84795 touched).
- `Microsoft.NET.Sdk.Razor.SourceGenerators.UnitTests`: 215 passed.
- `Microsoft.AspNetCore.Razor.Language.UnitTests` (component / tag
helper / bind / unbound-attribute): 1593 passed -- confirms #84760's
kept feature still works.

## Note

Reverting the merge means re-landing `features/sonic` later will need
this revert itself reverted first -- expected for a back-out.

###### Microsoft Reviewers: [Open in
CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/dotnet/roslyn/pull/84831)
@jjonescz jjonescz added this to the 18.11 milestone Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

empty tags should be marked as errors when context switching from c# to markup

4 participants