CROP
ProjectsParts Services

Pre-Commit Hooks - Cyrillic Check

Status: ✅ Active Last Updated: 2025-11-11

Pre-Commit Hooks - Cyrillic Check

Status: ✅ Active Last Updated: 2025-11-11


Overview

Pre-commit hook that prevents committing code with Cyrillic characters (Russian/Ukrainian text). Ensures all code, comments, logs, and documentation use English only.


How It Works

Architecture

Git Commit Attempt

.husky/pre-commit hook (automatic)

1. Run scripts/check-no-cyrillic.ts
   ├─ Scan all staged files
   ├─ Find Cyrillic characters (Russian/Ukrainian)
   └─ Exit 1 if found → BLOCK COMMIT ❌

2. Run lint-staged per service
   ├─ services/payment → biome check
   ├─ services/search → biome check
   └─ ... (other services)

3. If all checks pass → ALLOW COMMIT ✅

Monorepo Strategy

One Git = One pre-commit hook

  • Hook located in: .husky/pre-commit
  • Checks ALL services: payment, search, catalog, user, media, analytics, health-analytics
  • Script located in: scripts/check-no-cyrillic.ts

What Is Checked

✅ Files Checked

  • All .ts, .tsx, .js, .jsx files (code)
  • All .json files (configuration)
  • All .md files (documentation)
  • All other text files

❌ Files Excluded

  • Lock files (package-lock.json, bun.lockb, yarn.lock)
  • Binary files (.png, .jpg, .svg, .woff, etc.)
  • Environment files (.env, .env.*)
  • Git internals (.git/)
  • Dependencies (node_modules/)
  • Build artifacts (dist/, build/)

Setup

Already Set Up ✅

The hook is already configured for the entire monorepo. Nothing to do!

Manual Setup (if needed)

# 1. Go to monorepo root
cd /path/to/CROP-parts-services

# 2. Install dependencies (if not done)
bun install

# 3. Make scripts executable
chmod +x scripts/check-no-cyrillic.ts
chmod +x .husky/pre-commit

# 4. Test the hook
echo "// Test comment in Russian" > test.ts
git add test.ts
git commit -m "test"
# Should fail with: ❌ Found Cyrillic characters

# 5. Clean up
rm test.ts
git reset HEAD test.ts

Usage

Automatic (Pre-Commit)

Hook runs automatically on every commit:

git add .
git commit -m "Add feature"
# Hook runs automatically:
# 🔍 Pre-commit checks...
# ✅ No Cyrillic characters found
# Running lint-staged for payment...
# ✅ Pre-commit checks passed!

Manual Check

Run check manually without committing:

# From monorepo root
bun scripts/check-no-cyrillic.ts

# From any service
cd services/payment
bun ../../scripts/check-no-cyrillic.ts

Examples

❌ Commit Blocked

$ git commit -m "Add payment feature"

🔍 Pre-commit checks...

🔍 Checking for Cyrillic characters (Russian/Ukrainian)...

   Checking 3 staged file(s)...

 Found Cyrillic characters in staged files:

   📄 services/payment/src/routes/customers.ts
      Line 45: console.log('User created'); // (was in Russian)
      Line 67: // TODO: add validation check // (was in Russian)

   📄 services/payment/docs/README.md
      Line 12: ## Service Description // (was in Russian)

📝 Policy: All code, comments, logs, and documentation must be in English.
   Please remove Cyrillic characters and commit again.

   Total violations: 3 across 2 file(s)

Fix: Replace Cyrillic text with English:

// Before (Russian: "User created")
console.log('User created in Russian');

// After
console.log('User created');

✅ Commit Allowed

$ git commit -m "Add payment feature"

🔍 Pre-commit checks...

🔍 Checking for Cyrillic characters (Russian/Ukrainian)...

   Checking 3 staged file(s)...

 No Cyrillic characters found
   Checked 3 file(s)

Running lint-staged for payment...
 Pre-commit checks passed!

[main abc1234] Add payment feature
 3 files changed, 150 insertions(+)

Per-Service Configuration

Each service can have its own lint-staged rules that run AFTER Cyrillic check:

services/payment/package.json

{
  "lint-staged": {
    "*.{ts,tsx,js,jsx,json,md}": [
      "biome check --write --no-errors-on-unmatched"
    ]
  }
}

services/search/package.json

{
  "lint-staged": {
    "*.ts": [
      "biome check --write",
      "prettier --write"
    ],
    "*.json": [
      "prettier --write"
    ]
  }
}

Troubleshooting

Hook Not Running

Problem: Commit succeeds even with Cyrillic text.

Solution:

# 1. Check if .husky/pre-commit exists
ls -la .husky/pre-commit

# 2. Check if executable
chmod +x .husky/pre-commit

# 3. Verify git hooks path
git config core.hooksPath
# Should be empty or ".husky"

# 4. Reinstall husky (if needed)
rm -rf .husky
bun install

Script Not Found

Problem: bun: command not found: scripts/check-no-cyrillic.ts

Solution:

# 1. Check script exists
ls -la scripts/check-no-cyrillic.ts

# 2. Make executable
chmod +x scripts/check-no-cyrillic.ts

# 3. Run from monorepo root
cd /Users/vova/Code/CROP/microservices
bun scripts/check-no-cyrillic.ts

False Positives

Problem: Script reports Cyrillic in binary/lock files.

Solution: Edit scripts/check-no-cyrillic.ts and add pattern to EXCLUDE_PATTERNS:

const EXCLUDE_PATTERNS = [
  // ... existing patterns
  'path/to/exclude/**',
  '*.specific-extension',
];

⚠️ Only for emergencies!

# Skip pre-commit hooks (NOT RECOMMENDED)
git commit --no-verify -m "Emergency fix"

# Better: Fix the issue and commit properly

Policy

✅ Required

All code, comments, logs, and documentation MUST be in English:

  • ✅ Code: const user = createUser();
  • ✅ Comments: // Create new user
  • ✅ Logs: console.log('User created');
  • ✅ Docs: ## User Management
  • ✅ Error messages: throw new Error('User not found');

❌ Not Allowed

  • ❌ Russian: // Create user (when written in Russian)
  • ❌ Ukrainian: // Create user (when written in Ukrainian)
  • ❌ Mixing: // Create user (mixing English and Cyrillic - not allowed!)

Exceptions

None. Use English everywhere. If you need multilingual support:

  • User-facing text: Use i18n/translation files
  • Documentation for Russian users: Create separate docs in docs/ru/ (not committed to code branches)

Benefits

  1. Code Consistency - All developers use same language
  2. International Collaboration - Non-Russian speakers can understand code
  3. Best Practices - Following industry standards (English for code)
  4. Code Reviews - Easier for everyone to review
  5. Documentation - Consistent documentation language

Technical Details

Cyrillic Detection

Uses Unicode range \u0400-\u04FF to detect:

  • Russian alphabet (uppercase and lowercase)
  • Ukrainian alphabet (including special characters)
  • Belarusian alphabet (including special characters)

Performance

  • Checks only staged files (not entire repo)
  • Skips binary files
  • Fast regex matching
  • Typical runtime: <1 second for 10-20 files

Files

FilePurpose
.husky/pre-commitMain pre-commit hook (runs on every commit)
scripts/check-no-cyrillic.tsCyrillic detection script
services/*/package.jsonPer-service lint-staged config


Support

Questions? Ask in team chat or create an issue.

Found a bug? Report in this document or fix via PR.


Document Version: 1.0.0 Maintained By: Development Team

On this page