[ESLint] Add button-group-no-invalid-children rule - #9849
Draft
mgadewoll wants to merge 4 commits into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new @elastic/eui ESLint rule to statically validate EuiButtonGroup’s new Children API usage, helping consumers avoid composing unsupported child elements and wrapper patterns.
Changes:
- Implement
button-group-no-invalid-childrenrule, validating allowed direct children and supported wrappers (including special handling forEuiPopover’sbuttonprop). - Add JSX child-collection utilities to expand/resolve common composition patterns (fragments, conditionals, arrays, identifiers, local arrow components, and
.map()callbacks). - Add comprehensive unit tests and document the new rule in the plugin README; register the rule in the plugin’s exported config.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/eslint-plugin/src/utils/is_fragment.ts | New helper to identify <Fragment> / <React.Fragment> opening elements. |
| packages/eslint-plugin/src/utils/flat_map.ts | New flatMap shim used by rule utilities. |
| packages/eslint-plugin/src/utils/collect_jsx_children.ts | New utility to expand JSX children into concrete JSXElements for validation. |
| packages/eslint-plugin/src/rules/button_group_no_invalid_children.ts | New ESLint rule implementation for EuiButtonGroup Children API validation. |
| packages/eslint-plugin/src/rules/button_group_no_invalid_children.test.ts | Unit tests covering valid/invalid child patterns and wrapper handling. |
| packages/eslint-plugin/src/index.ts | Registers the new rule and enables it in recommended. |
| packages/eslint-plugin/README.md | Adds end-user documentation and examples for the new rule. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
💚 Build Succeeded
History
cc @mgadewoll |
💚 Build Succeeded
cc @mgadewoll |
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.
Summary
Important
This PR should be merged after #9845 which adds the new Children API on
EuiButtonGroup.button-group-no-invalid-childrento prevent passing unexpectedchildrentoEuiButtonGroupwhen used with the new Children API (added in [EuiButtonGroup] Implement redesign #1 - Add EuiButtonGroupContext & Children API support #9845).EuiButtonGroupchildren to only allowEuiButton,EuiButtonEmptyandEuiButtonIcon+ wrappersEuiPopover,EuiToolTipandEuiCopy.Examples
✅ valid
❌ invalid
Additional information
The EuiButtonGroup redesign adds a Children API (PR) as an alternative to the existing options-array API. With this API, consumers compose button components directly as JSX children rather than passing a configuration array. Because JSX children are freeform, the rule provides a lint-time guardrail that catches invalid compositions without requiring a runtime throw.
What the rule validates
The rule validates direct children for
variant="default": EuiButton, EuiButtonEmpty, EuiButtonIcon. (later iterations will support morevariantvalues). Additionally it validates allowed the following allowed wrapper components:EuiPopover,EuiToolTipandEuiCopy.API Changes
⚪ No API changes
Screenshots
Impact Assessment
Note: Most PRs should be tested in Kibana to help gauge their Impact before merging.
Impact level: 🟢 None
Release Readiness
QA instructions for reviewer
yarn workspace @elastic/eslint-plugin-eui buildon rootyarn workspace @elastic/eui build:workspaceson rootyarn workspace @elastic/eui linton rootChecklist before marking Ready for Review
breaking changelabel (if applicable)Reviewer checklist