Is there currently a solution to lint/autoformat B...
# general
c
Is there currently a solution to lint/autoformat BUILD files? My project has gotten into a space where we mix 2 and 4 spaces as indents and would love to fix to be 2 spaces, but if there is a tool that only does 4 I can be flexible.
h
There is not, outside of manually invoking Black on BUILD files. But I agree we should support it and others have asked for it too There are some challenges that will need to be figured out where targets fall apart. There isn't any target referring to BUILD files themselves, and without that, naively something like
::
(glob for all targets) wouldn't operate on BUILD files. But that's something we need to figure out and it speaks to a shortcoming of the current Pants concept of targets Would you want to open an issue to trick this? I couldn't find one
So it's fairly trivial to create a
build_files
target with default
sources = ("**/BUILD",)
, where we anticipate only having a single target in your whole repo to capture your BUILD files. That's a bit awkward, but it works and hooks up Black/isort seamlessly Some rough edges though that need to be figured out: 1. In order to get the formatters to work, we mark
BuildFilesSources
as subclassing
PythonSources
- this causes linters like Flake8 and Bandit to also think they can operate on BUILD files, even though they cannot 2. Right now, file arguments and
--changed-since
resolve a BUILD file to all of the targets defined within it. So, if you were to do
./pants fmt path/to/BUILD
, it will fmt not only the BUILD file, but also the targets defined there - that is suprising