Add CLI command typo detection (#34836)#10
Add CLI command typo detection (#34836)#10MitchLewis930 wants to merge 1 commit intopr_040_beforefrom
Conversation
* Add CLI command typo detection * Apply suggestions from code review Co-authored-by: Steven <steven@ceriously.com> * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Steven <steven@ceriously.com>
There was a problem hiding this comment.
Pull request overview
This PR adds typo detection for CLI commands to improve user experience by suggesting correct commands when users make typos. When an invalid command is entered, the system now calculates the edit distance to known commands and suggests the closest match if within a reasonable threshold.
Changes:
- Implemented Levenshtein distance algorithm for string similarity detection
- Added typo detection when invalid commands are provided to the CLI
- Added comprehensive test coverage for common command typos
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| test/integration/cli/test/index.test.js | Added test cases covering common typos for build, export, start, and dev commands |
| packages/next/lib/get-project-dir.ts | Integrated typo detection to suggest correct commands when invalid ones are entered |
| packages/next/lib/detect-typo.ts | Implemented edit distance calculation and typo detection logic |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,44 @@ | |||
| // the minimum number of operations required to convert string a to string b. | |||
| function minDistance(a: string, b: string, threshold: number): number { | |||
There was a problem hiding this comment.
The threshold parameter is passed to minDistance but never used in the calculation. This parameter should either be used for early termination optimization to avoid unnecessary computation, or removed if not needed.
| @@ -0,0 +1,44 @@ | |||
| // the minimum number of operations required to convert string a to string b. | |||
There was a problem hiding this comment.
This comment should be formatted as a proper JSDoc comment and should specify what algorithm is being implemented (Levenshtein distance). Consider: /** Calculates the Levenshtein distance (minimum number of operations required to convert string a to string b). */
| // the minimum number of operations required to convert string a to string b. | |
| /** | |
| * Calculates the Levenshtein distance (minimum number of single-character | |
| * operations required to convert string a to string b). | |
| * | |
| * @param a - The first string. | |
| * @param b - The second string. | |
| * @param threshold - A threshold value used by callers to limit acceptable distances. | |
| * @returns The Levenshtein distance between a and b. | |
| */ |
PR_040