-
Notifications
You must be signed in to change notification settings - Fork 53
Improve error messaging for incorrect XML tag casing #1540
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
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this to the bottom of the list so its code is in the correct order
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.
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.