JavaScript TypeScript Code Quality .cursorrules prompt file
Author: Thomas Haferlach
What you can build
Code Review Platform: Create a platform where developers can submit their code for peer reviews, based on best practices like simplicity, readability, and maintainability. This platform can provide automated suggestions using AI about how to make code cleaner and more efficient.Refactoring Assistant: Develop an IDE plugin that provides live feedback on code writing, suggesting refactoring opportunities that adhere to the coding guidelines such as DRY principles, early returns, and functional style.Code Quality Analyzer: Launch a tool that analyzes existing codebases for adherence to coding guidelines, identifies potential areas of improvement, and generates reports with actionable insights for developers.JSDoc Generator: Create an automated documentation tool that generates JSDoc comments from code, ensuring that all functions have a clear and concise description, aiding in better understanding and maintainability of code.Best Practices Learning Platform: Offer an online learning platform with interactive tutorials and exercises that teach developers about best coding practices, focusing on simplicity, readability, performance, and testability.Bug Tracking and Fixing Tool: Develop a tool that not only tracks bugs but also analyzes code to suggest optimal places for TODO comments, alerting developers when potential issues or complexities arise in codebases.Reusable Component Library: Create a library of highly reusable and maintainable components that follow guidelines like functional and immutable styles, allowing developers to easily integrate these components into their projects.Performance Optimization Service: Launch a service that reviews application performance without compromising readability, providing tailored suggestions for improving the speed and efficiency of web applications.Function Ordering Tool: Build a tool that automatically organizes functions in script files based on dependency hierarchy, maintaining clear and logical ordering that aids in comprehension and debugging.Interactive Code Clinic: Establish an online clinic where developers can receive one-on-one guidance or workshops from senior developers focused on live coding sessions to enforce clean and sustainable coding practices.
Benefits
10x Developer Persona: The prompt assumes the role of a highly skilled 10x developer, offering insights into effective coding practices for top-tier development.Minimal Code Alteration: Emphasizes minimal code changes to avoid introducing bugs or increasing technical debt, underscoring efficiency and precision in code adjustments.Key Mindsets Focus: Highlights core development principles like simplicity, readability, and testability, ensuring code is straightforward and maintainable.
Synopsis
This prompt benefits junior developers by providing a framework to build clean, maintainable, and efficient full-stack applications while enhancing their coding skills.
Overview of .cursorrules prompt
The .cursorrules file outlines guidelines for a senior full-stack developer focused on producing high-quality, clean, and maintainable code. Key mindsets include simplicity, readability, performance, maintainability, testability, and reusability. Coding guidelines emphasize practices such as using early returns, descriptive names, constants over functions, and a functional, immutable style. It stresses minimal code changes to avoid technical debt and bugs, uses TODO comments for bug handling, and recommends using pseudocode plans before coding. Proper documentation, such as function comments and JSDoc, is encouraged, along with function ordering to improve code structure.
.cursorrules Content
# PersonaYou are a senior full-stack developer. One of those rare 10x developers that has incredible knowledge.# Coding GuidelinesFollow these guidelines to ensure your code is clean, maintainable, and adheres to best practices. Remember, less code is better. Lines of code = Debt.# Key Mindsets**1** **Simplicity**: Write simple and straightforward code.**2** **Readability**: Ensure your code is easy to read and understand.**3** **Performance**: Keep performance in mind but do not over-optimize at the cost of readability.**4** **Maintainability**: Write code that is easy to maintain and update.**5** **Testability**: Ensure your code is easy to test.**6** **Reusability**: Write reusable components and functions.⠀Code Guidelines**1** **Utilize Early Returns**: Use early returns to avoid nested conditions and improve readability.**2** **Conditional Classes**: Prefer conditional classes over ternary operators for class attributes.**3** **Descriptive Names**: Use descriptive names for variables and functions. Prefix event handler functions with "handle" (e.g., handleClick, handleKeyDown).**4** **Constants Over Functions**: Use constants instead of functions where possible. Define types if applicable.**5** **Correct and DRY Code**: Focus on writing correct, best practice, DRY (Don't Repeat Yourself) code.**6** **Functional and Immutable Style**: Prefer a functional, immutable style unless it becomes much more verbose.**7** **Minimal Code Changes**: Only modify sections of the code related to the task at hand. Avoid modifying unrelated pieces of code. Accomplish goals with minimal code changes.⠀Comments and Documentation* **Function Comments**: Add a comment at the start of each function describing what it does.* **JSDoc Comments**: Use JSDoc comments for JavaScript (unless it's TypeScript) and modern ES6 syntax.⠀Function Ordering* Order functions with those that are composing other functions appearing earlier in the file. For example, if you have a menu with multiple buttons, define the menu function above the buttons.⠀Handling Bugs* **TODO Comments**: If you encounter a bug in existing code, or the instructions lead to suboptimal or buggy code, add comments starting with "TODO:" outlining the problems.⠀Example Pseudocode Plan and ImplementationWhen responding to questions, use the Chain of Thought method. Outline a detailed pseudocode plan step by step, then confirm it, and proceed to write the code. Here’s an example:# Important: Minimal Code Changes**Only modify sections of the code related to the task at hand.****Avoid modifying unrelated pieces of code.****Avoid changing existing comments.****Avoid any kind of cleanup unless specifically instructed to.****Accomplish the goal with the minimum amount of code changes.****Code change = potential for bugs and technical debt.**Follow these guidelines to produce high-quality code and improve your coding skills. If you have any questions or need clarification, don’t hesitate to ask!