Every time you choose to apply a rule(s), explicitly state the rule(s) in the output. You can abbreviate the rule description to a single word or phrase.
[Brief description ]
- [more description]
- [more description]
- [more description]
- Python
- [libary or framework name]
- [libary or framework name]
- [libary or framework name]
- PEP 8
- Tool: Pyright
- Tool: Pylint
- Spaces: 4
- Tabs: Not allowed
- Maximum: 79 characters
- Required: Yes
- Style: Google
- Variables: snake_case
- Functions: snake_case
- Classes: PascalCase
- Constants: UPPER_SNAKE_CASE
- Type Hints: Required
- Strictness: High
- Order: PEP 8 compliant
- Unused Imports:
- Remove all unused imports
- Run regular checks to identify and remove unused imports
- Use tools like
pylint
to detect unused imports - Keep imports minimal and only include what is actually used in the code
- Import Style:
- Use absolute imports over relative imports
- Group imports according to PEP 8:
- Standard library imports
- Third-party imports
- Local application imports
- Separate import groups with a blank line
- Comments: Required
- Nested Blocks:
- Limit: 3 levels
- Suggestion: Refactor when exceeding the limit
- Function Size:
- Maximum Lines: 50
- Suggestion: Split into smaller functions when exceeding the limit
- Class Size:
- Maximum Lines: 300
- Suggestion: Split into smaller classes when exceeding the limit
- Level: High
- Critical Errors: Enabled
- Warnings: Enabled
- Info Messages: Disabled
- Tool: pytest
- Test the functionliaty; not the implementation
- Write tests that cover end-to-end functionality covering multipule units
- For apis, test the API calls with expected input and output
- For UI's, test the interface with expected behaviours
- Mock external dependencies like databases, file systems, API's
Commit Message Prefixes:
- "fix:" for bug fixes
- "feat:" for new features
- "perf:" for performance improvements
- "docs:" for documentation changes
- "style:" for formatting changes
- "refactor:" for code refactoring
- "test:" for adding missing tests
- "chore:" for maintenance tasks
Rules:
- Use lowercase for commit messages
- Keep the summary line concise
- Include description for non-obvious changes
- Reference issue numbers when applicable
A starter .cursorrules for python projects