Skip to content

docs: add component-enum-union-migration.md cursor rule#945

Merged
georgewrmarshall merged 1 commit into
mainfrom
docs/component-enum-union-migration-cursor-rule
Feb 27, 2026
Merged

docs: add component-enum-union-migration.md cursor rule#945
georgewrmarshall merged 1 commit into
mainfrom
docs/component-enum-union-migration-cursor-rule

Conversation

@georgewrmarshall

@georgewrmarshall georgewrmarshall commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

Description

Adds component-enum-union-migration.md cursor rule providing workflow for refactoring existing monorepo components to ADR-0003 (const objects) and ADR-0004 (centralized types) patterns. This rule is specifically for internal cleanup of components with duplicate const object definitions across React and React Native packages.

When to use this workflow:

  • Component already exists in both React and React Native packages
  • Const objects are duplicated across platform packages
  • Types are defined separately in each platform (no shared source)
  • Component API needs to be unified/modernized

Key workflow documented:

  1. Identify components with duplicate const objects across platforms
  2. Create shared types in @metamask/design-system-shared package
  3. Update React package to import (not re-export) shared types
  4. Update React Native package to import (not re-export) shared types
  5. Remove old duplicates from platform type indices
  6. Update component index.ts to export directly from shared
  7. Verify build/test/lint

Critical mistakes documented:

  • Re-exporting const objects from .types.ts files (causes test coverage loss)
  • Using interface instead of type for shared props (ESLint error)
  • Separate type exports causing "Duplicate identifier" TypeScript errors
  • Wrong import ordering (platform imports before shared imports)
  • Including platform-specific props in shared types (violates ADR-0004)

Why this matters:
The BadgeCount migration (PR #942) revealed that duplicate const object exports in .types.ts files create uncovered code paths, failing Jest coverage thresholds at 81.81% instead of 100%. This rule documents the exact two-file pattern needed to prevent this issue.

Relationship to other rules:

  • Depends on: component-architecture.md (foundational ADR patterns)
  • Different from: component-creation.md (new components) and component-migration.md (extension/mobile migration)
  • Use case: Internal monorepo cleanup only

References:

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/DSYS-344

Manual testing steps

  1. Review the cursor rule file: .cursor/rules/component-enum-union-migration.md
  2. Verify it references BadgeCount PR refactor: migrate BadgeCount to union and shared types #942 and PR refactor: migrate BadgeStatus to design-system-shared and union types #912
  3. Check workflow steps match the BadgeCount migration pattern
  4. Confirm anti-patterns section shows duplicate export mistake
  5. Verify it clarifies this is NOT for new components
  6. Check golden path examples reference BadgeStatus implementation
  7. Confirm verification checklist covers both platforms
  8. Verify CLAUDE.md includes reference to this new rule

Screenshots/Recordings

N/A - Documentation only

Pre-merge author checklist

  • I've followed MetaMask Contributor Docs
  • I've completed the PR template to the best of my ability
  • I've included tests if applicable (N/A - documentation)
  • I've documented my code using JSDoc format if applicable (N/A - markdown)
  • I've applied the right labels on the PR (see labeling guidelines). Not required for external contributors.

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Low Risk
Documentation-only change that adds internal guidance; no runtime or build logic is modified.

Overview
Adds a new Cursor rule, .cursor/rules/component-enum-union-migration.md, documenting a standard workflow for migrating existing cross-platform components from duplicated enums/consts to shared string-union types per ADR-0003/ADR-0004 (including export patterns, import ordering, and common pitfalls like .types.ts re-exports impacting coverage).

Updates CLAUDE.md to reference this new rule in the AI-agent documentation index.

Written by Cursor Bugbot for commit e257d78. This will update automatically on new commits. Configure here.

@github-actions

Copy link
Copy Markdown
Contributor

📖 Storybook Preview

@github-actions

Copy link
Copy Markdown
Contributor

📖 Storybook Preview

@georgewrmarshall georgewrmarshall marked this pull request as ready for review February 26, 2026 22:18
@georgewrmarshall georgewrmarshall requested a review from a team as a code owner February 26, 2026 22:18
@georgewrmarshall georgewrmarshall self-assigned this Feb 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📖 Storybook Preview

georgewrmarshall

This comment was marked as resolved.


- [ ] Build succeeds: `yarn build`
- [ ] Tests pass: `yarn test`
- [ ] Coverage meets thresholds: `yarn test --coverage` (100% all metrics)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage threshold check added to catch duplicate const object exports early. This workflow involves moving const objects from platform packages to shared package - duplicate exports create uncovered code paths that fail Jest 100% coverage thresholds.

- `size` prop → `Size` story
- `isDisabled` prop → `IsDisabled` story
- `isLoading` prop → `IsLoading` story
- `status` prop → `Status` story

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Story naming convention expanded with concrete examples to clarify PascalCase transformation pattern for AI agents following these rules.

Comment thread CLAUDE.md

- @.cursor/rules/styling.md
- @.cursor/rules/component-documentation.md
- @.cursor/rules/component-enum-union-migration.md

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added component-enum-union-migration.md to CLAUDE.md for AI agent integration. This rule documents the internal monorepo cleanup workflow for migrating existing components to ADR-0003/0004 patterns.

Comment thread CLAUDE.md

# Component Creation
yarn create-component:react --name ComponentName --description "Brief description"
yarn create-component:react-native --name ComponentName --description "Brief description"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added React Native component creation command for cross-platform parity. Both platforms should be scaffolded together to ensure consistency.

Comment thread docs/ai-agents.md
- `cross-platform.md` - Cross platform consistency and shared types
- `component-documentation.md` - Storybook and README standards
- `figma-integration.md` - Code Connect

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated Current Rule Files section to reflect all implemented cursor rules with clear descriptions. This provides accurate documentation state for AI agents and human contributors.

brianacnguyen
brianacnguyen previously approved these changes Feb 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📖 Storybook Preview

@georgewrmarshall georgewrmarshall force-pushed the docs/component-enum-union-migration-cursor-rule branch from 690c364 to e257d78 Compare February 27, 2026 20:59
@georgewrmarshall georgewrmarshall enabled auto-merge (squash) February 27, 2026 20:59
@github-actions

Copy link
Copy Markdown
Contributor

📖 Storybook Preview

@georgewrmarshall georgewrmarshall merged commit afc280a into main Feb 27, 2026
43 checks passed
@georgewrmarshall georgewrmarshall deleted the docs/component-enum-union-migration-cursor-rule branch February 27, 2026 21:33
georgewrmarshall added a commit that referenced this pull request Mar 3, 2026
## **Description**

Adds `component-enum-union-migration.md` cursor rule providing workflow
for refactoring existing monorepo components to ADR-0003 (const objects)
and ADR-0004 (centralized types) patterns. This rule is specifically for
internal cleanup of components with duplicate const object definitions
across React and React Native packages.

**When to use this workflow:**
- Component already exists in both React and React Native packages
- Const objects are duplicated across platform packages
- Types are defined separately in each platform (no shared source)
- Component API needs to be unified/modernized

**Key workflow documented:**
1. Identify components with duplicate const objects across platforms
2. Create shared types in `@metamask/design-system-shared` package
3. Update React package to import (not re-export) shared types
4. Update React Native package to import (not re-export) shared types
5. Remove old duplicates from platform type indices
6. Update component index.ts to export directly from shared
7. Verify build/test/lint

**Critical mistakes documented:**
- Re-exporting const objects from `.types.ts` files (causes test
coverage loss)
- Using `interface` instead of `type` for shared props (ESLint error)
- Separate type exports causing "Duplicate identifier" TypeScript errors
- Wrong import ordering (platform imports before shared imports)
- Including platform-specific props in shared types (violates ADR-0004)

**Why this matters:**
The BadgeCount migration (PR #942) revealed that duplicate const object
exports in `.types.ts` files create uncovered code paths, failing Jest
coverage thresholds at 81.81% instead of 100%. This rule documents the
exact two-file pattern needed to prevent this issue.

**Relationship to other rules:**
- Depends on: `component-architecture.md` (foundational ADR patterns)
- Different from: `component-creation.md` (new components) and
`component-migration.md` (extension/mobile migration)
- Use case: Internal monorepo cleanup only

**References:**
- Golden path: BadgeStatus component (SOURCE OF TRUTH for shared types)
- Complete example: PR #912 (full migration with all file changes)
- Validation: BadgeCount PR #942 (demonstrated coverage issue and fix)

## **Related issues**

Fixes: https://consensyssoftware.atlassian.net/browse/DSYS-344

## **Manual testing steps**

1. Review the cursor rule file:
`.cursor/rules/component-enum-union-migration.md`
2. Verify it references BadgeCount PR #942 and PR #912
3. Check workflow steps match the BadgeCount migration pattern
4. Confirm anti-patterns section shows duplicate export mistake
5. Verify it clarifies this is NOT for new components
6. Check golden path examples reference BadgeStatus implementation
7. Confirm verification checklist covers both platforms
8. Verify CLAUDE.md includes reference to this new rule

## **Screenshots/Recordings**

N/A - Documentation only

## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs)
- [x] I've completed the PR template to the best of my ability
- [x] I've included tests if applicable (N/A - documentation)
- [x] I've documented my code using [JSDoc](https://jsdoc.app/) format
if applicable (N/A - markdown)
- [ ] I've applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Documentation-only changes: adds an internal workflow guide and links
it from `CLAUDE.md`, with no runtime or build impact.
> 
> **Overview**
> Adds a new Cursor rule,
`.cursor/rules/component-enum-union-migration.md`, documenting a
step-by-step workflow to migrate existing cross-platform components from
duplicated enums/consts to **shared const-object + string-union types**
per ADR-0003/ADR-0004, including common pitfalls (notably avoiding const
re-exports from `.types.ts` to prevent coverage drops).
> 
> Updates `CLAUDE.md` to reference this new rule in the AI-agent
documentation list.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
690c364. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
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.

2 participants