Giter Site home page Giter Site logo

Comments (8)

alecbz avatar alecbz commented on May 13, 2024

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 makes BUILD files shorter.

Although the motivation seemed to be one line as opposed to two.

from buildtools.

mwoehlke-kitware avatar mwoehlke-kitware commented on May 13, 2024

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.

pmbethe09 avatar pmbethe09 commented on May 13, 2024

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.

alecbz avatar alecbz commented on May 13, 2024

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.

psigen avatar psigen commented on May 13, 2024

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.

vladmos avatar vladmos commented on May 13, 2024

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.

psigen avatar psigen commented on May 13, 2024

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.

vladmos avatar vladmos commented on May 13, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.