From 9c5c8911fa7de8022941640f21b8a5658993a667 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Wed, 22 Mar 2023 15:42:13 +0100 Subject: [PATCH] Suggest alternatives for typoed rule attribute names --- .../google/devtools/build/lib/packages/RuleClass.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java index 721033d4e238f4..f4e5d134787507 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java +++ b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java @@ -78,6 +78,7 @@ import net.starlark.java.eval.Starlark; import net.starlark.java.eval.StarlarkCallable; import net.starlark.java.eval.StarlarkThread; +import net.starlark.java.spelling.SpellChecker; import net.starlark.java.syntax.Location; /** @@ -2079,8 +2080,12 @@ private BitSet populateDefinedRuleAttributeValues( Integer attrIndex = getAttributeIndex(attributeName); if (attrIndex == null) { rule.reportError( - String.format( - "%s: no such attribute '%s' in '%s' rule", rule.getLabel(), attributeName, name), + String.format("%s: no such attribute '%s' in '%s' rule%s", rule.getLabel(), + attributeName, name, SpellChecker.didYouMean(attributeName, + rule.getAttributes().stream() + .filter(Attribute::isDocumented) + .map(Attribute::getName) + .collect(ImmutableList.toImmutableList()))), eventHandler); continue; }