Skip to content

please format does not canonicalise local build labels #3471

@hartblanc

Description

@hartblanc

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions