Skip to content

Commit 82ab633

Browse files
authored
fix module file detection (#1407)
The naming scheme for module files is [prefix.]MODULE.bazel: https://bazel.build/rules/lib/globals/module#include
1 parent 30d1c54 commit 82ab633

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

buildifier/utils/utils.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ func isStarlarkFile(name string) bool {
3737
switch ext {
3838
case ".bazel", ".oss":
3939
// BUILD.bazel or BUILD.foo.bazel should be treated as Starlark files, same for WORSKSPACE and MODULE
40-
return strings.HasPrefix(name, "BUILD.") || strings.HasPrefix(name, "WORKSPACE.") || strings.HasPrefix(name, "MODULE.")
40+
// MODULE files flip the order: [prefix.]MODULE.bazel
41+
return strings.HasPrefix(name, "BUILD.") || strings.HasPrefix(name, "WORKSPACE.") || strings.HasSuffix(name, "MODULE.bazel")
4142
}
4243

4344
return name == "BUILD" || name == "WORKSPACE"

buildifier/utils/utils_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,18 @@ func TestIsStarlarkFile(t *testing.T) {
129129
filename: "foo.workspace",
130130
ok: false,
131131
},
132+
{
133+
filename: "MODULE.bazel",
134+
ok: true,
135+
},
136+
{
137+
filename: "my.MODULE.bazel",
138+
ok: true,
139+
},
140+
{
141+
filename: "MODULE.bazel.other",
142+
ok: false,
143+
},
132144
}
133145

134146
for _, tc := range tests {

0 commit comments

Comments
 (0)