# Coding Style Rule

> **Enforced across all code written or modified.**

---

## When Applied

- Any code file is created or modified
- Code suggestions are made
- Refactoring is performed

---

## File Size Limits

| File Type | Maximum Lines |
|-----------|---------------|
| Python/TypeScript code | 800 lines |
| Markdown documentation | 600 lines |
| Test files | 800 lines |

**If exceeded:** Extract functions, create submodules, or split files.

---

## Python Standards

### Type Hints (Required)
```python
def process_data(
    data: pd.DataFrame,
    threshold: float = 0.8
) -> tuple[pd.DataFrame, list[str]]:
    ...
```

### Naming Conventions
```python
MAX_RETRY_COUNT = 3                    # Constants: UPPER_SNAKE_CASE
def calculate_total(items): ...        # Functions: snake_case
class DataProcessor: ...               # Classes: PascalCase
def _internal_helper(self): ...        # Private: leading underscore
```

### Imports
```python
# Standard library
import os
from pathlib import Path

# Third-party
import pandas as pd
from pydantic import BaseModel

# Local
from myproject.utils import helper
```

### Docstrings (Google-style)
```python
def process_file(path: Path, threshold: float = 0.8) -> ProcessedData:
    """Process file and return results.

    Args:
        path: Path to file to process
        threshold: Minimum quality threshold (0.0 to 1.0)

    Returns:
        ProcessedData with results and metadata

    Raises:
        FileNotFoundError: If file doesn't exist
    """
```

---

## TypeScript Standards

### Strict Mode
Always enabled. No `any` without justification.

### Naming Conventions
```typescript
const MAX_RETRY_COUNT = 3;             // Constants: UPPER_SNAKE_CASE
function calculateTotal(items): ...    // Functions: camelCase
class DataProcessor { ... }            // Classes: PascalCase
interface UserProps { ... }            // Interfaces: PascalCase
type UserId = string;                  // Types: PascalCase
```

### Imports
```typescript
// External packages
import React from 'react';
import { useState } from 'react';

// Internal absolute
import { Button } from '@/components/ui';

// Internal relative
import { helper } from './utils';
```

---

## React Standards

### Component Size
- Maximum 150 lines per component
- Extract logic to custom hooks
- Extract UI to sub-components

### File Naming
```
components/
├── Button/
│   ├── Button.tsx        # Component
│   ├── Button.test.tsx   # Tests
│   ├── Button.styles.ts  # Styles (if separate)
│   └── index.ts          # Exports
```

---

## Enforcement

Violations trigger:
1. Warning in code review
2. Lint error (if configured)
3. Pre-commit hook failure
