fix module file detection (#1407)
The naming scheme for module files is [prefix.]MODULE.bazel:
https://bazel.build/rules/lib/globals/module#include
diff --git a/buildifier/utils/utils.go b/buildifier/utils/utils.go
index 458738e..ded4036 100644
--- a/buildifier/utils/utils.go
+++ b/buildifier/utils/utils.go
@@ -37,7 +37,8 @@
switch ext {
case ".bazel", ".oss":
// BUILD.bazel or BUILD.foo.bazel should be treated as Starlark files, same for WORSKSPACE and MODULE
- return strings.HasPrefix(name, "BUILD.") || strings.HasPrefix(name, "WORKSPACE.") || strings.HasPrefix(name, "MODULE.")
+ // MODULE files flip the order: [prefix.]MODULE.bazel
+ return strings.HasPrefix(name, "BUILD.") || strings.HasPrefix(name, "WORKSPACE.") || strings.HasSuffix(name, "MODULE.bazel")
}
return name == "BUILD" || name == "WORKSPACE"
diff --git a/buildifier/utils/utils_test.go b/buildifier/utils/utils_test.go
index 2968a2e..8e855b3 100644
--- a/buildifier/utils/utils_test.go
+++ b/buildifier/utils/utils_test.go
@@ -129,6 +129,18 @@
filename: "foo.workspace",
ok: false,
},
+ {
+ filename: "MODULE.bazel",
+ ok: true,
+ },
+ {
+ filename: "my.MODULE.bazel",
+ ok: true,
+ },
+ {
+ filename: "MODULE.bazel.other",
+ ok: false,
+ },
}
for _, tc := range tests {