Warn for empty outer tags when context switching from C# to markup - #84764
Merged
Conversation
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
|
Azure Pipelines: Successfully started running 2 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
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 withwarningLevel: 11. - Add a targeted parser check to report
RZ1022for@{ <>... }/@<>...-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. |
chsienki
approved these changes
Aug 6, 2026
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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