-
Notifications
You must be signed in to change notification settings - Fork 238
Mark empty outer tags as errors when context switching from C# to markup (RZ1022) #12811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
3
commits into
main
Choose a base branch
from
copilot/mark-empty-tags-as-errors
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+128
−0
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
9 changes: 9 additions & 0 deletions
9
...st/TestFiles/ParserTests/HtmlErrorTest/EmptyOuterTagProducesErrorInMarkupBlock.cspans.txt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| Markup span at (0:0,0 [0] ) - Parent: Markup block at (0:0,0 [11] ) | ||
| Transition span at (0:0,0 [1] ) - Parent: Statement block at (0:0,0 [11] ) | ||
| MetaCode span at (1:0,1 [1] ) - Parent: Statement block at (0:0,0 [11] ) | ||
| Markup span at (2:0,2 [2] ) - Parent: Tag block at (2:0,2 [2] ) | ||
| Markup span at (4:0,4 [3] ) - Parent: Markup block at (2:0,2 [8] ) | ||
| Markup span at (7:0,7 [3] ) - Parent: Tag block at (7:0,7 [3] ) | ||
| Code span at (10:0,10 [0] ) - Parent: Statement block at (0:0,0 [11] ) | ||
| MetaCode span at (10:0,10 [1] ) - Parent: Statement block at (0:0,0 [11] ) | ||
| Markup span at (11:0,11 [0] ) - Parent: Markup block at (0:0,0 [11] ) |
1 change: 1 addition & 0 deletions
1
...test/TestFiles/ParserTests/HtmlErrorTest/EmptyOuterTagProducesErrorInMarkupBlock.diag.txt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| (1,3): Error RZ1022: Outer tag is missing a name. The first character of a markup block must be an HTML tag with a valid name. |
32 changes: 32 additions & 0 deletions
32
...est/TestFiles/ParserTests/HtmlErrorTest/EmptyOuterTagProducesErrorInMarkupBlock.stree.txt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| RazorDocument - [0..11)::11 - [@{<>foo</>}] | ||
| MarkupBlock - [0..11)::11 | ||
| MarkupTextLiteral - [0..0)::0 - [] - Gen<Markup> | ||
| Marker;[]; | ||
| CSharpCodeBlock - [0..11)::11 | ||
| CSharpStatement - [0..11)::11 | ||
| CSharpTransition - [0..1)::1 - Gen<None> | ||
| Transition;[@]; | ||
| CSharpStatementBody - [1..11)::10 | ||
| RazorMetaCode - [1..2)::1 - Gen<None> | ||
| LeftBrace;[{]; | ||
| CSharpCodeBlock - [2..10)::8 | ||
| MarkupBlock - [2..10)::8 | ||
| MarkupElement - [2..10)::8 | ||
| MarkupStartTag - [2..4)::2 - [<>] - Gen<Markup> | ||
| OpenAngle;[<]; | ||
| Text;[<Missing>]; | ||
| CloseAngle;[>]; | ||
| MarkupTextLiteral - [4..7)::3 - [foo] - Gen<Markup> | ||
| Text;[foo]; | ||
| MarkupEndTag - [7..10)::3 - [</>] - Gen<Markup> | ||
| OpenAngle;[<]; | ||
| ForwardSlash;[/]; | ||
| Text;[<Missing>]; | ||
| CloseAngle;[>]; | ||
| CSharpStatementLiteral - [10..10)::0 - [] - Gen<Stmt> | ||
| Marker;[]; | ||
| RazorMetaCode - [10..11)::1 - Gen<None> | ||
| RightBrace;[}]; | ||
| MarkupTextLiteral - [11..11)::0 - [] - Gen<Markup> | ||
| Marker;[]; | ||
| EndOfFile;[]; |
11 changes: 11 additions & 0 deletions
11
...Files/ParserTests/HtmlErrorTest/EmptyOuterTagProducesErrorInTemplateExpression.cspans.txt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| Markup span at (0:0,0 [0] ) - Parent: Markup block at (0:0,0 [34] ) | ||
| Transition span at (0:0,0 [1] ) - Parent: Expression block at (0:0,0 [34] ) | ||
| Code span at (1:0,1 [16] ) - Parent: Expression block at (0:0,0 [34] ) | ||
| Transition span at (17:0,17 [1] ) - Parent: Markup block at (17:0,17 [16] ) | ||
| Markup span at (18:0,18 [2] ) - Parent: Tag block at (18:0,18 [2] ) | ||
| Markup span at (20:0,20 [5] ) - Parent: Markup block at (17:0,17 [16] ) | ||
| Transition span at (25:0,25 [1] ) - Parent: Expression block at (25:0,25 [5] ) | ||
| Code span at (26:0,26 [4] ) - Parent: Expression block at (25:0,25 [5] ) | ||
| Markup span at (30:0,30 [3] ) - Parent: Tag block at (30:0,30 [3] ) | ||
| Code span at (33:0,33 [1] ) - Parent: Expression block at (0:0,0 [34] ) | ||
| Markup span at (34:0,34 [0] ) - Parent: Markup block at (0:0,0 [34] ) |
1 change: 1 addition & 0 deletions
1
...stFiles/ParserTests/HtmlErrorTest/EmptyOuterTagProducesErrorInTemplateExpression.diag.txt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| (1,19): Error RZ1022: Outer tag is missing a name. The first character of a markup block must be an HTML tag with a valid name. |
49 changes: 49 additions & 0 deletions
49
...tFiles/ParserTests/HtmlErrorTest/EmptyOuterTagProducesErrorInTemplateExpression.stree.txt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| RazorDocument - [0..34)::34 - [@Html.Repeat(10, @<>Foo #@item</>)] | ||
| MarkupBlock - [0..34)::34 | ||
| MarkupTextLiteral - [0..0)::0 - [] - Gen<Markup> | ||
| Marker;[]; | ||
| CSharpCodeBlock - [0..34)::34 | ||
| CSharpImplicitExpression - [0..34)::34 | ||
| CSharpTransition - [0..1)::1 - Gen<None> | ||
| Transition;[@]; | ||
| CSharpImplicitExpressionBody - [1..34)::33 | ||
| CSharpCodeBlock - [1..34)::33 | ||
| CSharpExpressionLiteral - [1..17)::16 - [Html.Repeat(10, ] - Gen<Expr> | ||
| Identifier;[Html]; | ||
| Dot;[.]; | ||
| Identifier;[Repeat]; | ||
| LeftParenthesis;[(]; | ||
| NumericLiteral;[10]; | ||
| Comma;[,]; | ||
| Whitespace;[ ]; | ||
| CSharpTemplateBlock - [17..33)::16 | ||
| MarkupBlock - [17..33)::16 | ||
| MarkupTransition - [17..18)::1 - Gen<None> | ||
| Transition;[@]; | ||
| MarkupElement - [18..33)::15 | ||
| MarkupStartTag - [18..20)::2 - [<>] - Gen<Markup> | ||
| OpenAngle;[<]; | ||
| Text;[<Missing>]; | ||
| CloseAngle;[>]; | ||
| MarkupTextLiteral - [20..25)::5 - [Foo #] - Gen<Markup> | ||
| Text;[Foo]; | ||
| Whitespace;[ ]; | ||
| Text;[#]; | ||
| CSharpCodeBlock - [25..30)::5 | ||
| CSharpImplicitExpression - [25..30)::5 | ||
| CSharpTransition - [25..26)::1 - Gen<None> | ||
| Transition;[@]; | ||
| CSharpImplicitExpressionBody - [26..30)::4 | ||
| CSharpCodeBlock - [26..30)::4 | ||
| CSharpExpressionLiteral - [26..30)::4 - [item] - Gen<Expr> | ||
| Identifier;[item]; | ||
| MarkupEndTag - [30..33)::3 - [</>] - Gen<Markup> | ||
| OpenAngle;[<]; | ||
| ForwardSlash;[/]; | ||
| Text;[<Missing>]; | ||
| CloseAngle;[>]; | ||
| CSharpExpressionLiteral - [33..34)::1 - [)] - Gen<Expr> | ||
| RightParenthesis;[)]; | ||
| MarkupTextLiteral - [34..34)::0 - [] - Gen<Markup> | ||
| Marker;[]; | ||
| EndOfFile;[]; |
1 change: 1 addition & 0 deletions
1
...osoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/HtmlTagsTest/EmptyTag.diag.txt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| (1,3): Error RZ1022: Outer tag is missing a name. The first character of a markup block must be an HTML tag with a valid name. | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -664,6 +664,17 @@ private MarkupStartTagSyntax ParseStartTag( | |
| return ParseStartTextTag(openAngleToken, out tagMode, out isWellFormed); | ||
| } | ||
|
|
||
| if (mode == ParseMode.MarkupInCodeBlock && | ||
| _tagTracker.Count == 0 && | ||
| tagName.Length == 0 && | ||
| At(SyntaxKind.CloseAngle)) | ||
| { | ||
| // The outer tag of a markup block is missing a name. | ||
| Context.ErrorSink.OnError( | ||
| RazorDiagnosticFactory.CreateParsing_OuterTagMissingName( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked and this method has no callers, before this PR. The diagnostic is never used 🤷♂️ |
||
| new SourceSpan(tagStartLocation, contentLength: 1))); | ||
| } | ||
|
|
||
| var tagNameToken = At(SyntaxKind.Text) ? EatCurrentToken() : SyntaxFactory.MissingToken(SyntaxKind.Text); | ||
|
|
||
| var attributes = EmptySyntaxList; | ||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is introducing a new diagnostic into an existing test, that looks like this:
razor/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Legacy/HtmlTagsTest.cs
Lines 40 to 45 in c640a1c
That doesn't seem like an issue to me, but feel free to disagree.