Improve error messaging for incorrect XML tag casing#1540
Improve error messaging for incorrect XML tag casing#1540
Conversation
Co-authored-by: TwitchBronBron <2544493+TwitchBronBron@users.noreply.github.com>
| // Check if this is a case mismatch for a known tag | ||
| const lowerCaseTag = name.image.toLowerCase(); | ||
| const matchingAllowedTag = allow.find(allowedTag => allowedTag.toLowerCase() === lowerCaseTag); | ||
|
|
||
| if (matchingAllowedTag && matchingAllowedTag !== name.image) { | ||
| // Case mismatch for a known tag | ||
| diagnostics.push({ | ||
| ...DiagnosticMessages.xmlTagCaseMismatch(name.image, matchingAllowedTag), | ||
| range: rangeFromTokens(name) | ||
| }); | ||
| } else { | ||
| // Truly unexpected tag | ||
| diagnostics.push({ | ||
| ...DiagnosticMessages.xmlUnexpectedTag(name.image), | ||
| range: rangeFromTokens(name) | ||
| }); | ||
| } | ||
| } |
There was a problem hiding this comment.
Can we move this into XmlFileValidator so that way it catches these casing issues even after parsing, (like when plugins change or inject AST).
Add a unit test where a plugin changes the casing of one of these elements and then it gets caught during validation.
There was a problem hiding this comment.
Moved the XML tag casing validation to XmlFileValidator as requested. The validation now catches casing issues even when plugins modify the AST after parsing, and includes the requested unit test demonstrating this behavior (commit 016d2db).
src/DiagnosticMessages.ts
Outdated
| xmlTagCaseMismatch: (tagName: string, expectedTagName: string) => ({ | ||
| message: `Tag '${tagName}' must be all lower case. Use '${expectedTagName}' instead.`, | ||
| code: 1143, | ||
| severity: DiagnosticSeverity.Error | ||
| }), |
There was a problem hiding this comment.
Move this to the bottom of the list so its code is in the correct order
There was a problem hiding this comment.
Moved xmlTagCaseMismatch diagnostic to the bottom of the list so its code (1143) is in the correct numerical order after code 1142.
- Move case validation logic from SGParser.ts to XmlFileValidator.ts for better plugin support - Update SGParser to create AST objects for case-mismatched tags (case-insensitive parsing) - Add comprehensive tests for XML tag casing validation in XmlFileValidator - Update existing SGParser tests to reflect new behavior - Add plugin test demonstrating validation catches AST modifications Co-authored-by: TwitchBronBron <2544493+TwitchBronBron@users.noreply.github.com>
…ages.ts Co-authored-by: TwitchBronBron <2544493+TwitchBronBron@users.noreply.github.com>
The
<children>XML tag (and other component-level tags) must be lowercase, but when users accidentally use incorrect casing like<Children>, BSC would show an unhelpful generic error message:"Unexpected tag 'Children'".This PR adds specific error messaging for case mismatches to help developers quickly identify and fix casing issues.
Changes
Before
After
Implementation Details
xmlTagCaseMismatch(code 1143) for case mismatch errorsSGParser.tsto detect when tag names match known allowed tags but with incorrect casingchildren,interface,script, and other component tagsBenefits
Fixes #1399.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.