Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[buildifier] doesn't properly oder load-statements #1282

Closed
mgred opened this issue Aug 1, 2024 · 2 comments
Closed

[buildifier] doesn't properly oder load-statements #1282

mgred opened this issue Aug 1, 2024 · 2 comments

Comments

@mgred
Copy link
Contributor

mgred commented Aug 1, 2024

Buildifier doesn't properly order load-statements if there is no newline between the fist statement and a comment string above.

Consider the following example:

foo.bzl:

# buildifier: disable=module-docstring
load(":baz.bzl", "baz")
load(":bar.bzl", "bar")

print(bar, baz, baz1, bar1)
cat foo.bzl | buildifier -mode=fix -lint=fix

The output is:

load(":bar.bzl", "bar")

# buildifier: disable=module-docstring
load(":baz.bzl", "baz")

print(bar, baz)

This problem can be fixed by inserting a newline between the comment and the following line.

I stumble upon this from time to time and just wanted to know, if this is worth getting fixed. If so, I would like to get my hands on this.

Thanks for any feedback or advice

@vladmos
Copy link
Member

vladmos commented Aug 1, 2024

Compare with the following:

# baz rule definitions
load(":baz.bzl", "baz")
load(":bar.bzl", "bar")

print(bar, baz, baz1, bar1)

Buildifier doesn't know what the comment describes, it assumes that a comment belongs to the next statement if there are no empty lines between them. Inserting an empty line is the correct workaround.

@mgred
Copy link
Contributor Author

mgred commented Aug 1, 2024

Ok, that makes sense. Thank you 🙏

@mgred mgred closed this as completed Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants