Skip to main content

Code Quality Guidelines

Viben project code quality standards


Overview

This guide defines the code quality standards for the Viben project, applicable to both TypeScript and Python code.


TypeScript Quality Requirements

Linting & Formatting

ToolPurposeCommand
ESLintCode lintingpnpm lint
PrettierCode formattingpnpm format
TypeScriptType checkingpnpm typecheck

Pre-commit Checks

# Run all checks
pnpm lint
pnpm typecheck
pnpm build

Type Safety

All public functions must have type annotations:

// Correct
function createAgent(config: AgentConfig): Promise<Agent> {
// ...
}

// Incorrect - missing types
function createAgent(config) {
// ...
}

Use unknown instead of any:

// Correct
function handleData(data: unknown): void {
if (typeof data === 'string') {
// ...
}
}

// Incorrect
function handleData(data: any): void {
// ...
}

Python Quality Requirements

Linting & Formatting

ToolPurposeCommand
ruffLintingruff check .
ruffFormattingruff format .
mypyType checkingmypy browse_mcp/

Pre-commit Checks

cd backend/browse-mcp
ruff check browse_mcp/
ruff format --check browse_mcp/

Type Hints

All public functions must have type hints:

from typing import List, Optional

# Correct
def search(query: str, max_results: int = 10) -> List[Paper]:
pass

# Incorrect - missing types
def search(query, max_results=10):
pass

Docstring

Use Google-style docstrings:

def search(query: str, max_results: int = 10) -> List[Paper]:
"""Search for papers.

Args:
query: Search query string.
max_results: Maximum number of results to return.

Returns:
List of Paper objects matching the query.

Raises:
ValueError: If query is empty.
"""
pass

Code Metrics

MetricLimit
Function length< 50 lines
File length< 500 lines
Cyclomatic complexity< 10
Nesting depth< 4 levels

Forbidden Patterns

TypeScript

PatternReasonAlternative
any typeType unsafeUse unknown or specific types
console.logUnstructuredUse logger
Hardcoded pathsNot portableUse config or path module
eval() / new Function()Security riskNever use

Python

PatternReasonAlternative
except: (bare)Catches all exceptionsexcept Exception:
print()Unstructuredlogger.info()
Hardcoded pathsNot portableUse pathlib or config
eval() / exec()Security riskNever use

Naming Conventions

File Names

TypeTypeScriptPython
Componentkebab-case.tsx-
Utilitykebab-case.tssnake_case.py
Typestypes.tstypes.py
Tests*.test.tstest_*.py

Variables and Functions

TypeTypeScriptPython
VariablecamelCasesnake_case
FunctioncamelCasesnake_case
ConstantUPPER_SNAKE_CASEUPPER_SNAKE_CASE
ClassPascalCasePascalCase

API Parameters

Important: All Gateway API query parameters use snake_case:

// Correct
workspace_path, include_global, session_id

// Incorrect
workspacePath, includeGlobal, sessionId

Testing Requirements

Test File Location

# TypeScript
packages/core/src/
├── agent/
│ ├── agent.ts
│ └── agent.test.ts

# Python
backend/browse-mcp/
├── browse_mcp/
│ └── sources/
│ └── arxiv.py
└── tests/
└── test_arxiv.py

Test Naming

// TypeScript
describe('AgentService', () => {
it('should create agent with valid config', () => {
// ...
});

it('should throw error for invalid config', () => {
// ...
});
});
# Python
def test_search_returns_papers():
"""Test that search returns list of papers."""
pass

def test_search_empty_query_raises():
"""Test that empty query raises ValueError."""
pass

Code Review Checklist

Pre-commit Self-check

  • Code passes lint checks
  • Code passes type checks
  • New features have test coverage
  • Public APIs have documentation
  • No hardcoded sensitive information
  • Errors are properly handled
  • No console.log or print

Review Focus

  • Type safety
  • Error handling completeness
  • Security vulnerabilities
  • Performance issues
  • Code readability