Skip to content

Commit a16e1af

Browse files
committed
Only add the "Did you mean" message if the levenshtein distance is less than 3
1 parent 1ceabc1 commit a16e1af

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,9 @@ const publicApiProxy = new Proxy(publicApi, {
633633
process.exit(1); // eslint-disable-line
634634
}
635635
};
636-
} else if (typeof target[prop] === 'undefined') {
636+
}
637+
638+
if (typeof target[prop] === 'undefined') {
637639
// Find the property with the closest Levenshtein distance
638640
let similarProperty;
639641
let minDistance = Number.MAX_VALUE;
@@ -645,7 +647,12 @@ const publicApiProxy = new Proxy(publicApi, {
645647
}
646648
}
647649

648-
const error = new Error(`${chalk.red(`Encore.${prop}`)} is not a recognized property or method, did you mean ${chalk.green(`Encore.${similarProperty}`)}?`);
650+
let errorMessage = `${chalk.red(`Encore.${prop}`)} is not a recognized property or method.`;
651+
if (minDistance < 3) {
652+
errorMessage += ` Did you mean ${chalk.green(`Encore.${similarProperty}`)}?`;
653+
}
654+
655+
const error = new Error(errorMessage);
649656
console.log(new PrettyError().render(error));
650657
process.exit(1); // eslint-disable-line
651658
}

0 commit comments

Comments
 (0)