Skip to content
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

Cursor: Add API reuse and code pattern guidelines to development documentation #41629

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 60 additions & 1 deletion .cursor/rules/development-guidelines.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Before responding to any request, follow these steps:

- Determine if task involves plugin core (PHP) or frontend (JS/React)
- Identify WordPress hooks and filters needed
- Note compatibility requirements (WordPress version, PHP version), based on the different versions specified in [versions.sh](mdc:jetpack/jetpack/jetpack/jetpack/jetpack/.github/versions.sh)
- Note compatibility requirements (WordPress version, PHP version), based on the different versions specified in @versions.sh
lezama marked this conversation as resolved.
Show resolved Hide resolved
- Define core functionality and user experience goals
- Consider WordPress coding standards compliance

Expand All @@ -39,4 +39,63 @@ Before responding to any request, follow these steps:
- Ensure WordPress coding standards compliance
- Verify accessibility requirements

## API and Package Reuse

Before implementing new functionality or introducing new dependencies:

1. Package Assessment
- Survey existing packages within the monorepo for similar functionality
- Check for reusable components, utilities, or hooks in shared packages
- Review existing WordPress core and Jetpack APIs that might serve the need

2. Reuse Strategy
- Prioritize internal packages and APIs over external dependencies
- Consider extending existing functionality rather than duplicating
- Document usage of shared components and APIs for future reference
- Maintain consistency with existing patterns when reusing code

3. Integration Guidelines
- Use established patterns when integrating with existing packages
- Follow versioning guidelines when depending on internal packages
- Consider backwards compatibility when modifying shared code
- Contribute improvements back to shared packages when applicable

4. Performance Considerations
- Evaluate the impact of reusing packages on bundle size
- Consider code splitting and lazy loading for optimal performance
- Monitor dependencies for potential duplications across packages
- Balance code reuse with performance optimization goals

Always document dependencies and shared code usage to maintain a clear understanding of package relationships and promote efficient code reuse across the project.

## Code Patterns and Readability

When implementing new features or modifying existing code:

1. Pattern Consistency
- Survey similar features in the codebase for established patterns
- Follow existing naming conventions and code organization
- Maintain consistent file structure and component architecture
- Mirror successful implementation patterns from similar features

2. Pull Request Clarity
- Structure changes to follow logical, reviewable chunks
- Group related changes together in meaningful commits
- Follow existing patterns for commit messages and PR descriptions
- Include before/after examples for complex changes

3. Code Organization
- Match existing directory structures and file naming
- Follow established patterns for hooks, filters, and event handling
- Maintain consistent import ordering and file structure
- Use similar patterns for error handling and data validation

4. Documentation Alignment
- Follow existing documentation patterns in similar features
- Maintain consistent JSDoc/PHPDoc comment styles
- Include examples that mirror documentation in similar components
- Update relevant documentation following established formats

Remember that following familiar patterns makes code more predictable and easier to maintain for the entire team.

Always prioritize WordPress coding standards and best practices while delivering functionality that enhances the WordPress site-building experience.
Loading