Skip to content

Conversation

@tupe12334
Copy link

Summary

  • Implements new ESLint rule enforce-tfunction-type to enforce usage of official TFunction type from i18next
  • Replaces custom translation function types with the official TFunction type for better type consistency

Features

  • Auto-detection: Identifies TypeScript type aliases, interfaces, and inline type annotations that match TFunction signatures
  • Auto-fix: Automatically replaces custom types with TFunction and manages i18next imports
  • Import management: Creates new i18next imports or extends existing ones as needed
  • Parameter flexibility: Supports multiple parameter names (key, translationKey, i18nKey)
  • Comprehensive testing: 23 test cases covering valid/invalid scenarios and edge cases

Implementation Details

  • Detects function signatures like (key: string) => string and similar patterns
  • Handles TypeScript type aliases, interface call signatures, and variable type annotations
  • Provides helpful error messages with auto-fix suggestions
  • Follows repository coding standards and testing patterns

Test Coverage

  • 23 total tests across 2 test files (default.js and edge-cases.js)
  • Fixture-based testing with TypeScript parser integration
  • Edge case coverage including complex signatures and import scenarios
  • Full test suite integration - all existing tests still pass

Files Changed

  • lib/rules/enforce-tfunction-type.js - Main rule implementation
  • tests/lib/rules/enforce-tfunction-type/ - Comprehensive test suite
  • tests/lib/fixtures/enforce-tfunction-type/ - Test fixtures
  • package.json - Updated test script to include new rule tests

Resolves #146

🤖 Generated with Claude Code

tupe12334 and others added 2 commits September 24, 2025 22:06
Add new ESLint rule to enforce usage of TFunction type from i18next
instead of custom translation function types.

Features:
- Detects type aliases, interfaces, and inline types matching TFunction signatures
- Auto-fixes by replacing with official TFunction type
- Manages i18next imports (creates new or extends existing)
- Supports multiple parameter names: key, translationKey, i18nKey
- Comprehensive test coverage with 23 test cases

Resolves edvardchen#146

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enforce TFunction type usage from i18next

1 participant