Developer Guide
This guide helps developers understand ESLint Intl's architecture, setup a development environment, and contribute code.
Project Architecture
src/
├── extension.ts # Entry point: VS Code extension main
├── translator.ts # Translation core: OpenAI API calls
├── cache.ts # Cache system: dual-layer cache management
└── logger.ts # Logging: output channel utilitiesCore Modules
extension.ts - Extension Entry Point
- Activates extension
- Registers HoverProvider
- Manages commands
- Handles lifecycle
translator.ts - Translation Engine
- Calls OpenAI API
- Builds translation prompts
- Parses response JSON
- Manages request deduplication
cache.ts - Cache Management
- Memory cache (fast)
- Persistent cache (globalState)
- 7-day expiration
logger.ts - Logging Utilities
- Output channel management
- Structured logging
Development Environment Setup
System Requirements
- Node.js 16+
- npm 7+
- VS Code 1.85.0+
- Git
Installation Steps
bash
# 1. Clone repository
git clone https://github.com/RainSunMe/eslint-intl.git
cd eslint-intl
# 2. Install dependencies
npm install
# 3. Install VS Code CLI
npm install -g @vscode/vsce
# 4. Open project
code .Development Commands
bash
# Compile TypeScript
npm run compile
# Watch and compile on changes
npm run watch
# Check with ESLint
npm run lint
# Build VSIX file
vsce package
# Publish to Marketplace
vsce publishDebugging
Launch Debugger
Press F5 or click "Run and Debug" in sidebar
Opens a new VS Code window (Extension Development Host)
Debugging Tips
- Set Breakpoints: Click line number left margin
- View Variables: In "Variables" panel
- View Output: In main window open "ESLint Intl" output channel
- Reload: In Development Host press
Ctrl+R
Code Conventions
TypeScript
- Use
constnotlet - Explicit type annotations for complex types
- Use interfaces for object shapes
typescript
interface Config {
apiKey: string;
targetLanguage: string;
}Internationalization (i18n)
All user-facing strings must use vscode.l10n.t():
typescript
// ✅ Correct
log(vscode.l10n.t('Translating: "{0}"', message));
// ❌ Wrong
log("Translating: " + message);Logging
Use provided logging functions:
typescript
import { log, logError } from "./logger";
log("Translation completed");
logError("Failed to fetch: " + error.message);Error Handling
Promises should resolve to null instead of throwing:
typescript
// ✅ Good
async function translate() {
try {
return await api.call();
} catch (error) {
logError(error.message);
return null; // Graceful degradation
}
}Adding New Features
Add New Command
- Register in
package.json:
json
{
"contributes": {
"commands": [
{
"command": "eslintIntl.newCommand",
"title": "%command.newCommand%"
}
]
}
}- Implement in
extension.ts:
typescript
vscode.commands.registerCommand("eslintIntl.newCommand", async () => {
// Implementation
});- Add translation in
package.nls*.json
Add New Configuration
- In
package.json:
json
{
"contributes": {
"configuration": {
"properties": {
"eslintIntl.newOption": {
"type": "string",
"default": "value"
}
}
}
}
}Add descriptions in all
package.nls*.jsonAccess in code:
typescript
const config = vscode.workspace.getConfiguration("eslintIntl");
const value = config.get<string>("newOption");Building and Publishing
Local Testing
bash
npm run compile
vsce package
code --install-extension eslint-intl-*.vsixPublishing to Marketplace
bash
vsce login <publisher-name>
vsce publishCode Review Checklist
Before submitting PR:
- [ ] Code passes ESLint:
npm run lint - [ ] TypeScript compiles:
npm run compile - [ ] All strings i18n'd:
vscode.l10n.t() - [ ] License headers added
- [ ] README updated (if needed)
- [ ] Translation files updated
Resources
Getting Help
- 📖 Check existing code and comments
- 🐛 Submit an Issue
- 💬 Join the Discussion
- 📧 Contact maintainer
Thank you for contributing to ESLint Intl!