Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 18, 2025

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

<component name="Test" extends="Group">
    <Children>  <!-- Shows: "Unexpected tag 'Children'" -->
        <Label id="test" />
    </Children>
</component>

After

<component name="Test" extends="Group">
    <Children>  <!-- Shows: "Tag 'Children' must be all lower case. Use 'children' instead." -->
        <Label id="test" />
    </Children>
</component>

Implementation Details

  • Added new diagnostic message xmlTagCaseMismatch (code 1143) for case mismatch errors
  • Enhanced XML validation logic in SGParser.ts to detect when tag names match known allowed tags but with incorrect casing
  • Preserved existing behavior for truly unexpected/unknown tags (still shows generic "Unexpected tag" message)
  • Comprehensive test coverage for children, interface, script, and other component tags

Benefits

  • Clearer error messages help developers fix issues faster
  • Maintains backward compatibility - no breaking changes
  • Surgical implementation - minimal code changes with maximum impact
  • Covers all component-level tags that require lowercase (children, interface, script, customization)

Fixes #1399.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: TwitchBronBron <2544493+TwitchBronBron@users.noreply.github.com>
Copilot AI changed the title [WIP] Better messaging for incorrect casing for <children> Improve error messaging for incorrect XML tag casing Jul 18, 2025
Copilot AI requested a review from TwitchBronBron July 18, 2025 18:22
Comment on lines 260 to 277
// 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)
});
}
}
Copy link
Member

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.

Copy link
Contributor Author

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).

Comment on lines 357 to 361
xmlTagCaseMismatch: (tagName: string, expectedTagName: string) => ({
message: `Tag '${tagName}' must be all lower case. Use '${expectedTagName}' instead.`,
code: 1143,
severity: DiagnosticSeverity.Error
}),
Copy link
Member

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

Copy link
Contributor Author

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>
TwitchBronBron and others added 2 commits July 18, 2025 16:10
…ages.ts

Co-authored-by: TwitchBronBron <2544493+TwitchBronBron@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better messaging for incorrect casing for <children>

2 participants