lingo.dev icon indicating copy to clipboard operation
lingo.dev copied to clipboard

Add `fix` CLI command to automatically repair common source file issues

Open maxprilutskiy opened this issue 5 months ago • 12 comments

Description

Add a new CLI command lingo.dev fix that automatically repairs common issues in source files before processing. This would improve developer experience by automatically handling fixable problems rather than failing with errors.

Problem

Currently, when source files have certain issues, the CLI fails and developers must manually fix them. Common issues include:

  • JSON objects using numeric keys (e.g., {"0": "value", "1": "another"})
  • Malformed JSON with trailing commas, missing quotes, or incorrect escaping
  • Invalid YAML indentation or syntax
  • Mixed quote styles in JSON
  • BOM (Byte Order Mark) characters
  • Invalid Unicode sequences

Proposed Solution

Implement a lingo.dev fix command that:

Features

  1. Auto-detect file format (JSON, YAML, etc.)
  2. Fix common issues:
    • Convert numeric keys to string keys in JSON
    • Remove trailing commas in JSON
    • Fix quote inconsistencies
    • Correct YAML indentation
    • Remove BOM characters
    • Escape special characters properly
  3. Respect existing Prettier config if present (for formatting decisions like indentation, quotes, etc.)
  4. Preserve file structure and comments where possible
  5. Dry-run mode (--dry-run) to preview changes

Usage Examples

# Fix all files in current directory
lingo.dev fix

# Fix specific file
lingo.dev fix ./locales/en.json

# Preview changes without applying
lingo.dev fix --dry-run

# Fix specific issue types
lingo.dev fix --fix-numeric-keys --fix-trailing-commas

Output

Show clear before/after diffs and summary of fixes applied:

Fixed 3 issues in locales/en.json:
  ✓ Converted 2 numeric keys to strings
  ✓ Removed 1 trailing comma
  ✓ Fixed 0 quote inconsistencies

Implementation Notes

  • Should integrate with existing CLI structure
  • Reuse parsing logic where possible
  • Check for and respect .prettierrc, prettier.config.js, etc. when formatting
  • Add comprehensive tests for each fix type
  • Consider making some fixes opt-in if they could be destructive

Related Issues

  • Could help prevent errors in CI/CD pipelines
  • Improves onboarding experience for new users
  • Reduces support burden for common file format issues

maxprilutskiy avatar Sep 06 '25 05:09 maxprilutskiy

Claude encountered an error —— View job


Analyzing issue and implementing fix command

  • [x] Component identification and contributor analysis
  • [x] Codebase exploration
  • [x] Issue intelligence gathering
  • [x] Apply appropriate labels
  • [x] Post greeting and technical analysis
  • [x] Explore existing CLI structure
  • [ ] Implement fix command functionality
  • [ ] Add comprehensive tests
  • [ ] Run linting and tests
  • [ ] Commit and push changes
  • [ ] Create PR link

Progress

Based on the codebase, this CLI feature would integrate with the existing command structure in packages/cli/src/cli/index.ts:25. The CLI uses interactive-commander and already has utilities for file processing through loaders. Key dependencies like jsonrepair, prettier, and yaml are already available.

cc @mathio for CLI functionality

github-actions[bot] avatar Sep 06 '25 05:09 github-actions[bot]

Hey @maxprilutskiy! Good to see you back. If you want to discuss this in real-time, we're always on Discord.

github-actions[bot] avatar Sep 06 '25 05:09 github-actions[bot]

Based on the codebase, this would likely affect packages/cli/src/cli/index.ts around line 25 where commands are registered. You'll want to look at similar commands like cleanup.ts in packages/cli/src/cli/cmd/ for the implementation pattern.

github-actions[bot] avatar Sep 06 '25 05:09 github-actions[bot]

The cleanest approach would be to create a new fix.ts command that leverages existing loader infrastructure and file detection utilities. This would involve modifying packages/cli/src/cli/index.ts to register the command and packages/cli/src/cli/cmd/fix.ts for the implementation.

github-actions[bot] avatar Sep 06 '25 05:09 github-actions[bot]

Hey @maxprilutskiy and @vrcprl, I'll pick this one.

Nithishvb avatar Sep 29 '25 16:09 Nithishvb

go for it @Nithishvb !

maxprilutskiy avatar Oct 01 '25 19:10 maxprilutskiy

@maxprilutskiy @vrcprl @Nithishvb

If Its Open i would like to give it a try.

Swayanshu004 avatar Oct 29 '25 14:10 Swayanshu004

Hi @maxprilutskiy and the Lingo.dev team,

As a new contributor, I'd love to work on this good first issue. I've read the CONTRIBUTING.md and would like to request this be assigned to me.

The issue description is very comprehensive. To align with the "surgical PR" guideline, I'd like to propose tackling this in phases.

For my first PR, I can start by implementing the basic lingo.dev fix command structure and the logic for one of the fixes: "Remove BOM (Byte Order Mark) characters".

My plan would be to:

Add the new lingo.dev fix command to the CLI.

Implement the logic to read files, detect and remove the BOM character (\uFEFF).

Add specific unit tests for this BOM fix.

This would be the first small piece of the full command. Please let me know if this approach sounds good!

Thanks!

rishhh09 avatar Oct 29 '25 15:10 rishhh09

Hey, just joined the Discord. I'd like to take a shot at building this. Can you confirm what the first 1-2 'common issues' you'd like this to fix are?

kartik0905 avatar Oct 29 '25 15:10 kartik0905

@maxprilutskiy I have pulled a PR for this issue kindly review it and merge it if possible and correct Thanks....

kartik0905 avatar Oct 29 '25 16:10 kartik0905

Hi everyone! I see there's a lot of great discussion here. Is anyone still actively working on implementing this?

If not, I would really like to try it out for the new contributor event. Please let me know if it's available!

Madhusudan-Maity avatar Oct 29 '25 17:10 Madhusudan-Maity

Hey @Nithishvb are you still working on it? Please reply by tomorrow, otherwise I'll have to assign to someone else who has shown interest.

Thank you.

sumitsaurabh927 avatar Nov 03 '25 22:11 sumitsaurabh927