Skip to main content
CVAT follows strict coding standards to maintain code quality and consistency across the project. This guide covers the style guidelines for different programming languages used in CVAT.

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:
Format your Python code:

isort

Isort organizes imports with Black-compatible settings:
Sort imports:

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

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:
Auto-fix issues:

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

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:
Good commit message examples:
  • Fix annotation export for rotated bounding boxes
  • Add support for video chapters in frame navigation
  • Refactor task creation to improve performance
  • Update 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:
Always:
  • 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
Settings:

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
Ensure your code passes all checks before submitting a PR.

Next Steps