General Principles
- Write readable code: Code is read more often than written
- Be consistent: Follow existing patterns in the codebase
- Document your code: Add comments for complex logic
- Keep it simple: Avoid unnecessary complexity
- Test your changes: Ensure code works as expected
Python Code Style
CVAT’s Python code follows PEP 8 with some modifications enforced by Black and isort.Formatters and Linters
Black
Black is used for automatic code formatting with these settings:isort
Isort organizes imports with Black-compatible settings:pylint
Pylint is used for static code analysis. Run it to check for issues:Python Style Guidelines
- Line length: Maximum 100 characters
- Indentation: 4 spaces (no tabs)
- Imports: Group imports (standard library, third-party, local) and sort alphabetically
- Naming conventions:
- Classes:
PascalCase - Functions and variables:
snake_case - Constants:
UPPER_SNAKE_CASE - Private members:
_leading_underscore
- Classes:
Example
JavaScript/TypeScript Code Style
The frontend uses ESLint and Prettier for code quality and formatting.ESLint Configuration
CVAT uses a strict ESLint configuration based on Airbnb style guide:Prettier Configuration
Prettier enforces consistent formatting:Running Linters
Check code style:TypeScript/JavaScript Style Guidelines
- Line length: Maximum 120 characters
- Indentation: 4 spaces
- Quotes: Single quotes for strings, JSX props use single quotes
- Semicolons: Always required
- Naming conventions:
- Interfaces/Types:
PascalCase - Functions/Variables:
camelCase - Constants:
UPPER_SNAKE_CASE - React components:
PascalCase - Private members:
_leadingUnderscore
- Interfaces/Types:
TypeScript Example
File Organization
Python Files
TypeScript/JavaScript Files
Comments and Documentation
Python Docstrings
Use Google-style docstrings:TypeScript/JSDoc Comments
Git Commit Messages
Write clear, descriptive commit messages:Fix annotation export for rotated bounding boxesAdd support for video chapters in frame navigationRefactor task creation to improve performanceUpdate dependencies to fix security vulnerabilities
Pre-commit Hooks
CVAT uses linters in CI/CD. Before committing, run:Code Review Guidelines
When reviewing code:- Check for adherence to style guidelines
- Verify tests are included and passing
- Look for potential bugs or edge cases
- Ensure code is readable and maintainable
- Provide constructive feedback
- Approve when requirements are met
Security Considerations
ESLint includes security plugins:- Sanitize user input
- Avoid
eval()and similar dangerous functions - Use parameterized queries for database access
- Validate and escape data before rendering
Editor Configuration
VS Code
Recommended extensions:- Python (Microsoft)
- Pylance
- ESLint
- Prettier
- EditorConfig
PyCharm/WebStorm
Configure:- Black as the Python formatter
- ESLint for JavaScript/TypeScript
- Prettier for auto-formatting
- Line length to 100 (Python) or 120 (JS/TS)
Continuous Integration
CVAT’s CI runs these checks on every pull request:- Linters: ESLint, Pylint, Black, isort
- Type checking: TypeScript compiler, mypy
- Security: CodeQL analysis
- Tests: Unit, integration, and E2E tests
Next Steps
- Learn about testing your changes
- Understand the system architecture
- Read the pull request guide