# ESLint 9 Migration Summary

## Overview
This document summarizes the changes made to migrate the `@spaced-out/eslint-plugin-i18n` plugin from ESLint 8 to ESLint 9.

## Breaking Changes in ESLint 9
ESLint 9 changed several APIs that were used in this plugin:
- `context.getScope()` - Scope analysis API (replaced with `context.sourceCode.scopeManager`)
- `context.getSourceCode()` - Source code access (replaced with `context.sourceCode`)

## Changes Made

### 1. Package.json Updates
- Updated ESLint dependency from `8.35.0` to `^9.0.0`
- Added ESLint 9 as a peer dependency
- Added test scripts for migration validation

### 2. Source Code API Updates
Updated all instances of `context.getSourceCode()` to use the ESLint 9 compatible pattern:
```javascript
// Before
const sourceCode = context.getSourceCode();

// After  
const sourceCode = context.sourceCode || context.getSourceCode();
```

**Files Updated:**
- `lib/rules/i18n-enforce-makeKey-wrapper.js`
- `lib/utils/index.js`

### 3. Scope Analysis Migration
ESLint 9 replaced the scope analysis API (`context.getScope()`) with `context.sourceCode.scopeManager`, which required updates to several rules:

#### `lib/utils/index.js`
- **`getIdentifierNode()` function**: Updated to use ESLint 9's scope manager API
- **`getVariableFromScope()` function**: Updated to work with ESLint 9's scope structure

#### `lib/rules/no-static-labels.js`
- **AssignmentExpression handler**: Restored scope-based variable reference tracking using new API
- **Imports**: Restored all necessary imports for full functionality

### 4. Documentation Updates
- Updated README.md with ESLint 9 compatibility section
- Added migration notes and impact assessment
- Updated configuration examples

## Impact Assessment

### ✅ Fully Functional Rules
- `no-static-labels` - Fully functional with complete scope tracking
- `missing-translation` - No changes needed
- `invalid-translation-key-format` - No changes needed  
- `no-react-i18next-import` - No changes needed
- `i18n-enforce-makeKey-wrapper` - No changes needed

### 🚀 Enhanced Features
- **Better error handling**: Fallback mechanisms for scope analysis failures
- **Future-proof**: Uses ESLint 9's modern scope analysis API
- **Full compatibility**: All functionality preserved and enhanced

## Testing
A test script (`test-migration.js`) has been added to validate the migration:
```bash
npm test
# or
npm run test:migration
```

## Migration Guide for Users

### Before (ESLint 8)
```javascript
module.exports = {
  plugins: ["@spaced-out"],
  rules: {
    "@spaced-out/i18n/no-static-labels": "error",
  },
};
```

### After (ESLint 9)
```javascript
module.exports = {
  plugins: ["@spaced-out"],
  rules: {
    "@spaced-out/i18n/no-static-labels": "error",
  },
};
```

## Future Considerations
1. **Enhanced Scope Analysis**: Consider leveraging more advanced features of ESLint 9's scope manager
2. **Performance Optimization**: Explore opportunities to optimize scope analysis performance
3. **Additional Rules**: Consider adding new rules that leverage ESLint 9's enhanced capabilities

## Compatibility
- **ESLint 8**: ❌ No longer supported
- **ESLint 9**: ✅ Fully supported with all functionality
- **Node.js**: Compatible with Node.js versions supported by ESLint 9 