-
Notifications
You must be signed in to change notification settings - Fork 419
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
Add option to sort lists by default #833
base: main
Are you sure you want to change the base?
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@@ -450,7 +456,7 @@ func sortStringList(x Expr, context string) { | |||
return | |||
} | |||
|
|||
forceSort := keepSorted(list) || keepSorted(list.List[0]) | |||
forceSort := forceKeepSorted(list) || forceKeepSorted(list.List[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this bit of logic requires users to explicitly comment "keep sorted" on lists with comments
@googlebot I signed it! |
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
what problem does this solve that some combination of: ? |
my understanding is that the code block
is handled by some subset of the following lines: https://github.com/bazelbuild/buildtools/blob/master/build/rewrite.go#L411-L434 |
I'm not familiar with what jsontables is, and google doesn't seem to be returning relevant results. What is that? |
It's correct, this is currently not supported. However, I feel like this is a very niche need and it doesn't match the style recommendations in Bazel. I would encourage you to build your own program (using Buildifier as a library) to perform this transformation; you'll just need to write a few lines of Go. I don't think this feature should belong to Buildifier. |
Based on https://docs.bazel.build/versions/master/skylark/build-style.html, it's true that we should |
We work in a repo that does not care about dependency order, and we keep our lists in variables. A simple example of a typical file in our repo looks like:
We'd like to keep lists sorted by default, and if we ever have a case of wanting to preserve order, we can choose to use the "do not sort" comment.
This PR adds an option to sort by lists by default, and it respects the existing "do not sort" comment.