Comments (8)
Note that this rule is currently codified in the style guide:
Use a single blank line between two top-level definitions. Rationale: The structure of a
BUILD
file is not like a typical Python file. It has only top-level statements. Using a single-blank line makesBUILD
files shorter.
Although the motivation seemed to be one line as opposed to two.
from buildtools.
First off, that rationale is wrong; we have quite a few Bazel files full of utility functions, rule implementations, etc. that most certainly do not "[have] only top-level statements".
That said, I agree the intent seems to be 'one blank line, not two', rather than 'one blank line, not none'. Anyway, here's another example where adding a blank line is clunky, if not outright misguided:
# This is a comment that applies to multiple declarations.
FOO = "foo"
BAR = "bar"
With no blank line, it is clear that the comment applies to both declarations. Adding a blank line here is actively harmful to clarity.
from buildtools.
This change does seem reasonable and worth considering, but note that internally it will require a depot-wide change so will have to be rolled out cautiously.
from buildtools.
First off, that rationale is wrong; we have quite a few Bazel files full of utility functions, rule implementations, etc. that most certainly do not "[have] only top-level statements".
Bazel files (.bzl
) or BUILD
files?
from buildtools.
Is there any activity on fixing this? Or is there a way to disable it for a block of code (like clang-format: off
?)
I have a project where I have many groups of related constants in my WORKSPACE
(version numbers/hashes/urls for repositories), and this rule is making them extremely difficult to read.
I found this thread which suggests it's not possible:
#806 (comment)
I also looked through this list of warnings for anything I could disable but didn't immediately find anything relevant:
https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#how-to-disable-warnings
from buildtools.
There's a recent discussion on it in #890, however there's currently no activity.
It might be possible to disable formatter for a specific node with a comment, but in the example above one would need to comment every assignment statement:
UBUNTU_MAIN = "http://mirrors.kernel.org/ubuntu/pool/main/" # buildifier: disable-format
UBUNTU_UNIVERSE = "http://mirrors.kernel.org/ubuntu/pool/universe/" # buildifier: disable-format
NODEJS = "http://deb.nodesource.com/node_6.x/pool/main/" # buildifier: disable-format
Perhaps an easier approach would be to load all the necessary definitions from a .bzl file which is marked as "do not format" with a comment.
Regarding blank lines, they are not enforced anymore in .bzl
files (there are few exceptions, but in general users can decide when to separate statements with blank lines).
from buildtools.
Alright, I will try the workaround of moving all my blocks into separate files. I am not sure that will be too convenient either, as these were for repository imports that need to be interleaved with load
commands, so it will be dozens of 5 line files, but it might be easier than putting disable-format
on every line. 😞
Thank you for pointing out that this is specific to WORKSPACE
files. That is very useful to know.
from buildtools.
Note that the disabling comment is not yet implemented, that was just an idea of how it could work.
If you mean forced empty lines between statements, that's specific to BUILD
and WORKSPACE
files, for .bzl
files users have more control of how each statement should be formatted. You can move all your constants to a .bzl
file and group the statements as you want, e.g.:
UBUNTU_MAIN = "http://mirrors.kernel.org/ubuntu/pool/main/"
UBUNTU_UNIVERSE = "http://mirrors.kernel.org/ubuntu/pool/universe/"
NODEJS = "http://deb.nodesource.com/node_6.x/pool/main/"
from buildtools.
Related Issues (20)
- ERROR: --noenable_bzlmod :: Unrecognized option: --noenable_bzlmod HOT 1
- buildifier moves licenses() and distribs() from mainline to the package() declaration
- buildifier rule with check mode is deprecated but buildifier_test is not documented
- buildifier_test does not complain when passix fix as a mode
- new_load to= aliases broken HOT 1
- Virus Total Flagging latest Buildozer Darwin Amd64 as infected HOT 2
- [buildifier]: add lint warning for disallowed load
- [buildozer]: Support adding symbols instead of literal strings HOT 1
- Unable to go install tagged version since introduction of `v` prefix HOT 1
- Buildtools release artifacts are unsigned and have no checksum files
- buildozer doesn't accept "BUILD.bazel" HOT 1
- buildifier destroys `load()` statements targeting the same name HOT 2
- Buildozer: Handle multiple glob arguments in 'set' arguments HOT 1
- Release request HOT 5
- Feature Request - Provide a 'diff' mode for buildozer
- Buildifier doesn't recognise `MODULE.bazel`
- new_load local naming syntax with `=` no longer works
- constant-glob fails to lint when the first argument is named
- no such target '@@com_github_bazelbuild_buildtools//buildifier:runner.bat.template'
- Add s390x arch support HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from buildtools.