Leveraging LLMs for Context-Aware Code Formatting
Use large language models to provide context-sensitive code formatting suggestions.
0 likes
10 views
Rule Content
To implement context-sensitive code formatting suggestions using large language models (LLMs) in Cursor IDE, create a `.cursorrules` file in your project's root directory with the following content: # Leveraging LLMs for Context-Aware Code Formatting ## Project Context - This project utilizes [insert programming languages and frameworks, e.g., Python 3.10 with Django 4.2, JavaScript with React 18]. - The codebase adheres to the following coding standards and style guides: - [Insert relevant style guides, e.g., PEP 8 for Python, Airbnb JavaScript Style Guide for JavaScript]. ## General Formatting Guidelines - **Indentation**: - Use [insert number] spaces for indentation. - Continuation lines should be indented by an additional [insert number] spaces. - **Line Length**: - Limit lines to a maximum of [insert number] characters. - Break lines exceeding this limit at logical boundaries to maintain readability. - **Spacing**: - Use a single space after commas, colons, and semicolons. - Ensure consistent spacing around operators (e.g., `=`, `+`, `-`). - **Braces and Brackets**: - Place opening braces on the same line as the statement. - Closing braces should align with the start of the statement that opened the block. ## Language-Specific Formatting Rules ### Python - **Imports**: - Group imports in the following order: standard library, third-party packages, local modules. - Use absolute imports whenever possible. - **Docstrings**: - Use triple double-quotes for docstrings. - Include a brief description of the function's purpose, parameters, and return values. - **Type Annotations**: - Provide type hints for all function arguments and return values. - **Error Handling**: - Use specific exception classes in `try-except` blocks. - Include informative error messages in exceptions. ### JavaScript - **Semicolons**: - Always terminate statements with semicolons. - **Quotes**: - Use single quotes for strings, except when the string contains a single quote. - **Arrow Functions**: - Prefer arrow functions for anonymous functions. - **Object and Array Destructuring**: - Use destructuring assignments for objects and arrays when appropriate. ## Best Practices - **Consistency**: - Maintain consistent formatting throughout the codebase. - Adhere to the project's established coding standards and style guides. - **Readability**: - Write code that is easy to read and understand. - Use meaningful variable and function names. - **Modularity**: - Break down complex functions into smaller, reusable components. - **Documentation**: - Provide clear and concise comments and documentation for complex logic and algorithms. ## Implementation Notes - **LLM Integration**: - Leverage LLMs to analyze code context and suggest formatting improvements. - Ensure that LLM-generated suggestions align with the project's coding standards and style guides. - **Review Process**: - Regularly review and update formatting rules to accommodate evolving project requirements. - Encourage team members to provide feedback on formatting guidelines and LLM suggestions. ## References - [Insert links to relevant coding standards, style guides, and documentation] Replace placeholders (e.g., `[insert programming languages and frameworks]`, `[insert number]`, `[Insert relevant style guides]`, `[Insert links to relevant coding standards, style guides, and documentation]`) with information specific to your project. By defining these rules, you enable Cursor IDE to utilize LLMs effectively for providing context-aware code formatting suggestions that align with your project's standards.