Revert "Keep targets like "@foo//:foo" formatted as-is. (#1355)"
This reverts commit 870ee1bae25a0c8fc9a3f57339421f9594ca7d79.
diff --git a/build/rewrite.go b/build/rewrite.go
index 2f028e2..e500beb 100644
--- a/build/rewrite.go
+++ b/build/rewrite.go
@@ -217,7 +217,8 @@
// "//x" + ":y" (usually split across multiple lines) into "//x:y".
//
// Second, it removes redundant target qualifiers, turning labels like
-// "//third_party/m4:m4" into "//third_party/m4".
+// "//third_party/m4:m4" into "//third_party/m4" as well as ones like
+// "@foo//:foo" into "@foo".
func fixLabels(f *File, w *Rewriter) {
joinLabel := func(p *Expr) {
add, ok := (*p).(*BinaryExpr)
@@ -287,6 +288,8 @@
}
if m[4] != "" && m[4] == m[5] { // e.g. //foo:foo
str.Value = m[1]
+ } else if m[3] != "" && m[4] == "" && m[3] == m[5] { // e.g. @foo//:foo
+ str.Value = "@" + m[3]
}
}
diff --git a/build/testdata/019.build.golden b/build/testdata/019.build.golden
index fc11258..dcb103d 100644
--- a/build/testdata/019.build.golden
+++ b/build/testdata/019.build.golden
@@ -299,7 +299,7 @@
"//a|zzz",
"//a}zzz",
"//a~zzz",
- "@abc//:abc",
+ "@abc",
"@abc//:xyz",
"@abc//foo",
"@zzz",