Skip to content

Commit 38054f0

Browse files
fmeumShreeM01
authored andcommitted
Suggest alternatives for typoed rule attribute names
Closes bazelbuild#17847. PiperOrigin-RevId: 518664847 Change-Id: I99d09be093e785c7d1ad437d40866423638be118
1 parent f03abe0 commit 38054f0

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/main/java/com/google/devtools/build/lib/packages/RuleClass.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
import net.starlark.java.eval.Starlark;
8282
import net.starlark.java.eval.StarlarkCallable;
8383
import net.starlark.java.eval.StarlarkThread;
84+
import net.starlark.java.spelling.SpellChecker;
8485
import net.starlark.java.syntax.Location;
8586

8687
/**
@@ -2146,7 +2147,16 @@ private <T> BitSet populateDefinedRuleAttributeValues(
21462147
if (attrIndex == null) {
21472148
rule.reportError(
21482149
String.format(
2149-
"%s: no such attribute '%s' in '%s' rule", rule.getLabel(), attributeName, name),
2150+
"%s: no such attribute '%s' in '%s' rule%s",
2151+
rule.getLabel(),
2152+
attributeName,
2153+
name,
2154+
SpellChecker.didYouMean(
2155+
attributeName,
2156+
rule.getAttributes().stream()
2157+
.filter(Attribute::isDocumented)
2158+
.map(Attribute::getName)
2159+
.collect(ImmutableList.toImmutableList()))),
21502160
eventHandler);
21512161
continue;
21522162
}

0 commit comments

Comments
 (0)