From 745ca288770253225d5d96069038a5d735eda69b Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Wed, 22 Mar 2023 13:53:54 -0700 Subject: [PATCH] Suggest alternatives for typoed rule attribute names Closes #17847. PiperOrigin-RevId: 518664847 Change-Id: I99d09be093e785c7d1ad437d40866423638be118 --- .../devtools/build/lib/packages/RuleClass.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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..9ff3ab675615d7 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; /** @@ -2080,7 +2081,16 @@ private BitSet populateDefinedRuleAttributeValues( if (attrIndex == null) { rule.reportError( String.format( - "%s: no such attribute '%s' in '%s' rule", rule.getLabel(), attributeName, name), + "%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; }