feat(cli): add initial 'lingo fix' command with BOM fixer
This PR introduces the initial scaffolding and implementation for the new lingo fix command, as tracked in issue #1156. This command is designed to automatically find and fix common issues in lingo files.
This initial PR is intentionally scoped small and includes:
The core fix command scaffolding within the CLI.
A global --dry-run option, which allows users to see what changes would be made without modifying any files.
The first fixer implementation: a fixer to automatically remove UTF-8 BOM characters from files.
To Test:
- Pull down the branch and build the CLI.
- Create a test file that is saved with a UTF-8 BOM (many code editors like VS Code or Notepad++ have an option to save a file as "UTF-8 with BOM").
- Test the "dry run" mode: lingo fix ./path/to/your/file.json --dry-run
- Then to test the files changes and all i have run this command: cd packages/cli/demo/json and node ../../bin/cli.mjs fix --dry-run
Screenshot
What We Have Done in the Code (The Implementation):
- Added a New Command: You have registered a new top-level command called lingo fix in your command-line application (CLI).
- Built the "Scaffolding": You've created the basic code structure for this command. This means you've set up the argument parsing and the main function that will run one or more "fixers" on the user's files.
- Created a --dry-run Option: You have added a specific flag (or "option") called --dry-run. Your code will have if statements that check if this flag is present. If it is, the code will skip the part that saves changes to the disk.
- Wrote the First Fixer (BOM Fixer): You've written the first piece of active logic. This is a function that:
- Reads the bytes of a file.
- Checks if the first few bytes match the specific signature of a UTF-8 BOM (Byte Order Mark).
- If they do, it returns the rest of the file's content, effectively stripping the BOM from the beginning.
What Changes It Shall Do (The Behavior): This is what will happen when a user runs your new command:
- When a user runs lingo fix ... --dry-run:
- Your code will scan the specified files.
- It will find files that have a BOM.
- It will NOT change or save any files.
- It will only print a report to the console, saying something like, "BOM found in file.json. (dry-run)."
- When a user runs lingo fix ... (without --dry-run):
- Your code will scan the specified files.
- If a file has a BOM: Your code will read it, remove the BOM, and then overwrite the original file with the new, clean content. It will then report that the file was "fixed."
- If a file does NOT have a BOM: Your code will check it, find no issues, and do nothing to that file before moving on to the next one.
@maxprilutskiy can you have a look here please?
@maxprilutskiy Hey now i think this PR is upto date and ready to be merged as this resolve a good issue have a look at it please...Thanks...
@kartik0905 please resolve the merge conflicts
@sumitsaurabh927 I don't want to work on this issue anymore close the PR if you want...Thanks!