please icon indicating copy to clipboard operation
please copied to clipboard

`please format` does not canonicalise local build labels

Open HartBlanc opened this issue 3 weeks ago • 2 comments

The please format command helpfully canonicalises and deduplicates build labels. For example the following BUILD file:

go_library(
    name = "name",
    srcs = [
        "src.go",
    ],
    deps = [
        "//path/to/my/package:package",
        "//path/to/my/package:package",
        "//path/to/my/package",
        "//path/to/my/package",
    ],
)

is formatted as:

go_library(
    name = "name",
    srcs = [
        "src.go",
    ],
    deps = ["//path/to/my/package"],
)

However, the same is not true for local build labels.

For example the following BUILD file:

# path/to/my/package/BUILD
go_library(
    name = "name",
    srcs = [
        "src.go",
    ],
    deps = [
        "//path/to/my/package:package",
        "//path/to/my/package:package",
        "//path/to/my/package",
        "//path/to/my/package",
        ":package",
        ":package",
    ],
)

is formatted as:

go_library(
    name = "name",
    srcs = [
        "src.go",
    ],
    deps = [
        ":package",
        "//path/to/my/package",
    ],
)

I think it would be preferable if it was formatted as:

go_library(
    name = "name",
    srcs = [
        "src.go",
    ],
    deps = [
        ":package",
    ],
)

This would ensure that the target is not duplicated and would ensure that there is a single canonical label. If there is consensus that this is preferable, I'd be happy to raise a PR - thanks.

HartBlanc avatar Dec 09 '25 17:12 HartBlanc

Yes, I agree that what you suggest would be preferable, and we'd be delighted to receive a PR from you!

toastwaffle avatar Dec 09 '25 20:12 toastwaffle

I've added https://github.com/please-build/buildtools/pull/10 which should solve this

HartBlanc avatar Dec 10 '25 17:12 HartBlanc