Refactor consumer suggestion
MODIFY
packages/@romejs/consume/Consumer.ts
packages/@romejs/consume/Consumer.ts
@@ -13,7 +13,6 @@ import {
DiagnosticPointer,
getDiagnosticsFromError,
DiagnosticCategory,
- PartialDiagnosticAdviceItem,
} from '@romejs/diagnostics';
import {suggestClosest} from '@romejs/suggest';
import {UnknownObject} from '@romejs/typescript-helpers';
@@ -530,27 +529,25 @@ export default class Consumer {
return;
}
+ const knownProperties = Array.from(this.usedNames.keys());
+
for (const [key, value] of this.asMap(false, false)) {
if (!this.usedNames.has(key)) {
- const advice: Array<PartialDiagnosticAdviceItem> = [];
- const suggestion = suggestClosest(
- key,
- Array.from(this.usedNames.keys()),
- );
-
- if (suggestion) {
- advice.push({
- type: 'log',
- category: 'info',
- message: `Did you mean <emphasis>${suggestion}</emphasis>?`,
- });
- }
+ const suggestion = suggestClosest(key, knownProperties);
value.unexpected(`Unknown <emphasis>${key}</emphasis> ${type}`, {
target: 'key',
at: 'suffix',
atParent: true,
- advice,
+ advice: suggestion
+ ? [
+ {
+ type: 'log',
+ category: 'info',
+ message: `Did you mean <emphasis>${suggestion}</emphasis>?`,
+ },
+ ]
+ : undefined,
});
}

Refactor consumer suggestion