Skip to content

Code Guidelines .cursorrules prompt file

Author: Hamza Farhan

What you can build

Code Analysis Tool: Develop a tool that analyzes code for compliance with the rules set in the .cursorrules AI file. It would highlight violations such as missing error handling, lack of test coverage, and unmatched coding style.Automated Refactoring Service: Create a service that automatically refactors code file-by-file while adhering to guidelines like no whitespace suggestions, avoiding magic numbers, and ensuring modular design.Project Consistency Checker: Build a tool that checks for consistent coding style, performance prioritization, and security considerations across multiple files in a project, while avoiding unnecessary updates.Developer Assistant Extension: Design a browser or IDE extension that provides real-time feedback on code edits, emphasizing explicit variable names, avoiding apologies, and ensuring no unnecessary confirmations are needed.Code Optimization Platform: Set up a platform that suggests performance improvements and modular design strategies while ensuring version compatibility and prioritizing a security-first approach.Unit Test Suggestions App: Create an app that automatically generates unit tests for new or modified code, emphasizing coverage, without showing or discussing the current implementation unless requested.Version Compatibility Analyzer: Develop an analyzer that checks code changes for compatibility with the project's specified language or framework versions to ensure smooth integration and functionality.Edge Case Identifier: Build a tool that scans code to identify potential edge cases and suggests handling strategies, ensuring robust error handling and logging.Context-Aware Code Reviewer: Create a code review platform that uses the context generated files to provide feedback on edits, ensuring no unnecessary confirmations and file preservation.Modular Design Educator: Develop a learning platform that educates developers on implementing and encouraging modular design principles, focusing on reusability and maintainability of code.Assertion Validator: Construct a service that integrates into CI/CD pipelines to check the presence and correct use of assertions in code, enhancing validation accuracy and early error detection.Hardcoded Values Detector: Create a tool that scans codebases for magic numbers and suggests replacements with named constants, improving clarity and maintainability.Error Handling Enhancer: Design a plugin or standalone tool that suggests improvements in error handling mechanisms within code, providing recommendations for robust logging practices.

Benefits

Synopsis

Developers working on collaborative projects would benefit by establishing clear and efficient code review and update practices, ensuring consistent, secure, and maintainable code quality across the team.

Overview of .cursorrules prompt

The .cursorrules file outlines a set of rules and guidelines to be followed when editing or suggesting changes to code. It emphasizes verifying information, making changes file-by-file, preserving existing code, and avoiding unnecessary confirmations or updates. It advises against using apologies, unnecessary whitespace changes, or summarizing changes made. There is a focus on ensuring real file links are provided, using explicit variable names, and following a consistent coding style. Performance, security, error handling, modular design, version compatibility, edge cases, and test coverage are prioritized. The file discourages the use of "magic numbers" and encourages using assertions to catch errors early.

.cursorrules Content

json
1. **Verify Information**: Always verify information before presenting it. Do not make assumptions or speculate without clear evidence.2. **File-by-File Changes**: Make changes file by file and give me a chance to spot mistakes.3. **No Apologies**: Never use apologies.4. **No Understanding Feedback**: Avoid giving feedback about understanding in comments or documentation.5. **No Whitespace Suggestions**: Don't suggest whitespace changes.6. **No Summaries**: Don't summarize changes made.7. **No Inventions**: Don't invent changes other than what's explicitly requested.8. **No Unnecessary Confirmations**: Don't ask for confirmation of information already provided in the context.9. **Preserve Existing Code**: Don't remove unrelated code or functionalities. Pay attention to preserving existing structures.10. **Single Chunk Edits**: Provide all edits in a single chunk instead of multiple-step instructions or explanations for the same file.11. **No Implementation Checks**: Don't ask the user to verify implementations that are visible in the provided context.12. **No Unnecessary Updates**: Don't suggest updates or changes to files when there are no actual modifications needed.13. **Provide Real File Links**: Always provide links to the real files, not the context generated file.14. **No Current Implementation**: Don't show or discuss the current implementation unless specifically requested.15. **Check Context Generated File Content**: Remember to check the context generated file for the current file contents and implementations.16. **Use Explicit Variable Names**: Prefer descriptive, explicit variable names over short, ambiguous ones to enhance code readability.17. **Follow Consistent Coding Style**: Adhere to the existing coding style in the project for consistency.18. **Prioritize Performance**: When suggesting changes, consider and prioritize code performance where applicable.19. **Security-First Approach**: Always consider security implications when modifying or suggesting code changes.20. **Test Coverage**: Suggest or include appropriate unit tests for new or modified code.21. **Error Handling**: Implement robust error handling and logging where necessary.22. **Modular Design**: Encourage modular design principles to improve code maintainability and reusability.23. **Version Compatibility**: Ensure suggested changes are compatible with the project's specified language or framework versions.24. **Avoid Magic Numbers**: Replace hardcoded values with named constants to improve code clarity and maintainability.25. **Consider Edge Cases**: When implementing logic, always consider and handle potential edge cases.26. **Use Assertions**: Include assertions wherever possible to validate assumptions and catch potential errors early.

Released under the MIT License.