Coder Social home page Coder Social logo

bazel-super-formatter's People

Contributors

agluszak avatar alexeagle avatar dbanetto avatar ewhauser avatar f0rmiga avatar gregmagolan avatar jhchabran avatar johanbrorson avatar lavatoaster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

bazel-super-formatter's Issues

[FR]: bzlmod support?

What is the current behavior?

No bzlmod support, so it has to be installed outside of MODULE.bazel

Describe the feature

This repo got forked from bazel-contrib/rules-template before MODULE.bazel support was added, and so it lacks from such features, does it make sense to add it? Would you mind if I contribute it?

Accept list of files to format as positional command-line args

Some tools like pre-commit expect formatter tools to be called like formatter file.fmt.

This is nice because that tool has already determined which files are modified by the user in a given context, so we won't have to wait to "re-format the world".

Black execution fails (missing 'typing_extensions')

Trying to run v0.2.2 with

python_register_toolchains(
    name = "python3",
    python_version = "3.10",
)

fails with

Traceback (most recent call last):
  File "/home/ph03/.cache/bazel/_bazel_ph03/2db8cbce6fe365e36a9715d20aab49e9/execroot/dsai/bazel-out/k8-opt/bin/external/aspect_rules_format_pypi_black/rules_python_wheel_entry_point_black.runfiles/aspect_rules_format_pypi_black/rules_python_wheel_entry_point_black.py", line 3, in <module>
    from black import patched_main
  File "/home/ph03/.cache/bazel/_bazel_ph03/2db8cbce6fe365e36a9715d20aab49e9/execroot/dsai/bazel-out/k8-opt/bin/external/aspect_rules_format_pypi_black/rules_python_wheel_entry_point_black.runfiles/aspect_rules_format_pypi_black/site-packages/black/__init__.py", line 42, in <module>
    from black.nodes import STARS, syms, is_simple_decorator_expression
  File "/home/ph03/.cache/bazel/_bazel_ph03/2db8cbce6fe365e36a9715d20aab49e9/execroot/dsai/bazel-out/k8-opt/bin/external/aspect_rules_format_pypi_black/rules_python_wheel_entry_point_black.runfiles/aspect_rules_format_pypi_black/site-packages/black/nodes.py", line 24, in <module>
    from typing_extensions import TypeGuard
ModuleNotFoundError: No module named 'typing_extensions'
FAILED: A formatter tool exited with code 123
Try running 'bazel run @aspect_rules_format//format' to fix this.

while running with

python_register_toolchains(
    name = "python3",
    python_version = "3.10",
)

already fails at the configuration step with

INFO: Invocation ID: c11114e4-935a-4a07-b80a-3b9cddb4bf13
ERROR: /home/ph03/.cache/bazel/_bazel_ph03/2db8cbce6fe365e36a9715d20aab49e9/external/aspect_rules_format_pypi_black/BUILD.bazel:22:11: no such package '@aspect_rules_format_pypi_typing_extensions//': The repository '@aspect_rules_format_pypi_typing_extensions' could not be resolved: Repository '@aspect_rules_format_pypi_typing_extensions' is not defined and referenced by '@aspect_rules_format_pypi_black//:pkg'
ERROR: Analysis of target '@aspect_rules_format//format:format' failed; build aborted: 

which looks like an inconsistency to me. Note that I have a python toolchain registered before, i.e.,

python_register_toolchains(
    name = "python39",
    # Available versions are listed in @rules_python//python:versions.bzl
    python_version = "3.9",
)

but that one is not picked up by bazel-super-formatter as it's expecting the python toolchain to be called python3 not python39 (could that be the source of the issue?)

Formatter fails if you don't define a Python toolchain even if Python formatting is disabled

With build --@aspect_rules_format//format:python_enabled=false set in .bazelrc, I'm getting this error message:

ERROR: Failed to load Starlark extension '@python3//:defs.bzl'.
Cycle in the workspace file detected. This indicates that a repository is used prior to being defined.
The following chain of repository dependencies lead to the missing definition.
 - @python3
This could either mean you have to add the '@python3' repository with a statement like `http_archive` in your WORKSPACE file (note that transitive dependencies are not added automatically
), or move an existing definition earlier in your WORKSPACE file.
INFO: Reading rc options for 'run' from /Users/ewhauser/working/cadencerpm/monorepo/.bazelrc:
  Inherited 'build' options: --sandbox_default_allow_network=false --incompatible_allow_tags_propagation --modify_execution_info=PackageTar=+no-remote --nolegacy_external_runfiles --works
pace_status_command tools/workspace_status.sh --build_metadata=REPO_URL=https://github.com/cadencerpm/monorepo --noexperimental_convenience_symlinks --noremote_upload_local_results --expe
rimental_remote_merkle_tree_cache=true --experimental_remote_merkle_tree_cache_size=1000 --remote_local_fallback --incompatible_remote_results_ignore_disk --noexperimental_check_output_fi
les --experimental_reuse_sandbox_directories --incompatible_remote_results_ignore_disk --aspects //bazel/api_linter:defs.bzl%api_linter_aspect --output_groups=+api_linter --@aspect_rules_
format//format:python_enabled=false
ERROR: @aspect_rules_format//format:python_enabled :: Error loading option @aspect_rules_format//format:python_enabled: cycles detected during target parsing

Based on the notes in releases, it seems like adding the Python toolchain is optional if you aren't using black.

Add more languages

  • Go
  • C/C++/C# - clang-format, see bazelbuild/rules_cc#125
  • Rust
  • SQL
  • Objective-C
  • Ruby
  • PHP
  • Visual Basic
  • Groovy
  • Scala
  • Kotlin - @maven//:com_facebook_ktfmt_jar_with_dependencies
  • Haskell
  • Dart
  • Perl
  • Protobuf
  • Jsonnet
  • Terraform

[Bug]: Recommended pre-commit config can silently ignore files

What happened?

I set up the super-formatter in our .pre-commit-config.yaml [1] in VideoAmp/central, a repo with a lot of files (>3500). I observe that when I run pre-commit run --all-files bazel-super-formatter, which is supposed to run the pre-commit on all files in the repo, many files are missed. By contrast, everything works as expected when I run bazel run @aspect_rules_format//format (for example, docs/go/README.md currently needs formatting at HEAD).
My theory is that pre-commit's batching mechanism isn't working properly with the super formatter.

[1] used this config block (same as from this repo's README):

- id: bazel-super-formatter
  name: run bazel super formatter
  language: system
  entry: bazel run @aspect_rules_format//format
  files: .*
  stages: [commit]

Version

Development (host) and target OS/architectures:

Output of bazel --version: 6.0.0 (bazelisk)

Language(s) and/or frameworks involved:
markdown, shell, js

How to reproduce

The "what happened" description lays it out pretty well. For Alex: there are currently 6 files in the repo (which you can access) that need formatting at HEAD, and I'll leave those there for you to see.

Any other information?

No response

Fund our work

  • Sponsor our open source work by donating a bug bounty

Suggested configuration flags cause unwanted log spew

The custom configuration flags in the README to disable formatters cause warning log spew as build is inherrited by verbs that don't support custom flags, eg:

bazel output_base

WARNING: info command does not support starlark options. Ignoring options: [--@aspect_rules_format//format:java_enabled=false]

[Bug]: wrong binaries are being downloaded in Linux/aarch64

What happened?

For a monorepo managed by Bazel and with bazel super formatter as a pre-commit plugin, we are getting wrong binaries for its dependencies. Specifically when the pre-commit hooks for bazel super formatter are applied, wrong binaries for buf and buildifier are being downloaded.

As a consequence, the formatting process ends in a broken state.

It is expected the formatting process to work correctly if the aarch64 binaries for those tools are downloaded to the system.

NOTE: for example when the bazel super formatter pre-commit hook runs, the buildifier binary is being downloaded to ~/.cache/pre-commit/buildifier/linux-amd64-5.1.0/buildifier/buildifier. Notice the linux-amd64-5.1.0 directory in the download path.

Version

Development (host) and target OS/architectures:

aarch64 GNU/Linux

Output of bazel --version:

bazel 6.0.0

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file:

1.0.0 (Bazel Super Formatteer 1.0.0 version)

Language(s) and/or frameworks involved:

Protocol Buffers and Bazel Build files, but the consequence is that the whole formatting process fails.

How to reproduce

Working in a Linux environment that runs in a aarch64 architecture if you try to apply the formatter in a repository with modified Protocol Buffers or Bazel BUILD files (BUILD or BUILD.bazel), the formatting process will fail since Bazel Super Formatter downloads buf and buildifier amd64 binaries for a aarch64 architecture.

Any other information?

No response

[Bug]: prettier sh format broken with rules_js > 1.24.0

What happened?

Format fails with the error:

[2023-04-19T23:58:05Z] Running Prettier...
[2023-04-19T23:58:05Z] [error] Cannot find module 'mvdan-sh'

Version

Development (host) and target OS/architectures:

Output of bazel --version: 6.1.2

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file: 2.0.0 using WORKSPACE

Language(s) and/or frameworks involved:
prettier / sh

How to reproduce

No response

Any other information?

No response

Add formatting rule to be used from BUILD.bazel files

I'm quite new to Bazel so please point out anything that doesn't make sense or isn't actually possible ๐Ÿ˜„

What?
Would it be possible to add a formatting rule that can then be used from BUILD.bazel files?

e.g.

# greeting/BUILD.bazel
format(
    name = "format_greeting_lib",
    srcs = glob("*.ts"),
)

# BUILD.bazel
format(
    name = "format_hello_lib",
    srcs = glob("*.ts"),
    deps = ["//greeting:format_greeting_lib"],
)

And then it could be run like this:

bazel run //src/format_hello_lib

As the //greeting:format_greeting_lib target is a dependency, it would also be formatted but could potentially be cached

Why?
As I understand it, currently bazel-super-formatter either formats all files in a workspace (with some exceptions based on .gitignore or other global-to-the-workspace config) or it needs to be told on the command line which files to format.

Formatting all files in a workspace could get quite heavy and seems a shame not to take advantage of Bazel's build cache in this situation.

[Bug]: broken with latest rules_python versions

What happened?

rules_python has changed the naming scheme for its toolchain repos and hence the load of interpreter from @python3//:defs.bzl fails with the latest versions of rules_python.

Version

Development (host) and target OS/architectures:

Output of bazel --version: 6.3.2

Language(s) and/or frameworks involved: python

How to reproduce

No response

Any other information?

No response

How do you imagine this project integrates with editors?

What is the current behavior?

No response

Describe the feature

I'm currently investigating how our team should use Bazel to lint/format files and came across this amazing work! I'm curious how you are imagining formatters built with Bazel to be configured with an editor like VSCode so you get behaviour like "format on save" and inline suggestions.

Fund our work

[Bug]: Prettifier / Node.js crashing

What happened?

Running latest version formatting checks with bazel run @aspect_rules_format//format -- --mode check fail in prettifier with

Checking formatting...
All matched files use Prettier code style!
FATAL ERROR: v8::FromJust Maybe value is Nothing.
 1: 0xb09c10 node::Abort() [/home/developer/.cache/bazel/_bazel_developer/6fc7dd3d681346fb996e4b7beb1cd826/execroot/tair-project-template/bazel-out/k8-opt/bin/external/aspect_rules_format/format/format.runfiles/tair-project-template/../node_linux_amd64/bin/nodejs/bin/node]
 2: 0xa1c193 node::FatalError(char const*, char const*) [/home/developer/.cache/bazel/_bazel_developer/6fc7dd3d681346fb996e4b7beb1cd826/execroot/tair-project-template/bazel-out/k8-opt/bin/external/aspect_rules_format/format/format.runfiles/tair-project-template/../node_linux_amd64/bin/nodejs/bin/node]
 3: 0xcf8afa v8::Utils::ReportApiFailure(char const*, char const*) [/home/developer/.cache/bazel/_bazel_developer/6fc7dd3d681346fb996e4b7beb1cd826/execroot/tair-project-template/bazel-out/k8-opt/bin/external/aspect_rules_format/format/format.runfiles/tair-project-template/../node_linux_amd64/bin/nodejs/bin/node]
 4: 0xb0da7d node::fs::FileHandle::CloseReq::Resolve() [/home/developer/.cache/bazel/_bazel_developer/6fc7dd3d681346fb996e4b7beb1cd826/execroot/tair-project-template/bazel-out/k8-opt/bin/external/aspect_rules_format/format/format.runfiles/tair-project-template/../node_linux_amd64/bin/nodejs/bin/node]
 5: 0xb0dbd9  [/home/developer/.cache/bazel/_bazel_developer/6fc7dd3d681346fb996e4b7beb1cd826/execroot/tair-project-template/bazel-out/k8-opt/bin/external/aspect_rules_format/format/format.runfiles/tair-project-template/../node_linux_amd64/bin/nodejs/bin/node]
 6: 0x156015d  [/home/developer/.cache/bazel/_bazel_developer/6fc7dd3d681346fb996e4b7beb1cd826/execroot/tair-project-template/bazel-out/k8-opt/bin/external/aspect_rules_format/format/format.runfiles/tair-project-template/../node_linux_amd64/bin/nodejs/bin/node]
 7: 0x1564936  [/home/developer/.cache/bazel/_bazel_developer/6fc7dd3d681346fb996e4b7beb1cd826/execroot/tair-project-template/bazel-out/k8-opt/bin/external/aspect_rules_format/format/format.runfiles/tair-project-template/../node_linux_amd64/bin/nodejs/bin/node]
 8: 0x1577064  [/home/developer/.cache/bazel/_bazel_developer/6fc7dd3d681346fb996e4b7beb1cd826/execroot/tair-project-template/bazel-out/k8-opt/bin/external/aspect_rules_format/format/format.runfiles/tair-project-template/../node_linux_amd64/bin/nodejs/bin/node]
 9: 0x1565288 uv_run [/home/developer/.cache/bazel/_bazel_developer/6fc7dd3d681346fb996e4b7beb1cd826/execroot/tair-project-template/bazel-out/k8-opt/bin/external/aspect_rules_format/format/format.runfiles/tair-project-template/../node_linux_amd64/bin/nodejs/bin/node]
10: 0xa43dd5 node::SpinEventLoop(node::Environment*) [/home/developer/.cache/bazel/_bazel_developer/6fc7dd3d681346fb996e4b7beb1cd826/execroot/tair-project-template/bazel-out/k8-opt/bin/external/aspect_rules_format/format/format.runfiles/tair-project-template/../node_linux_amd64/bin/nodejs/bin/node]
11: 0xbd3792 node::worker::Worker::Run() [/home/developer/.cache/bazel/_bazel_developer/6fc7dd3d681346fb996e4b7beb1cd826/execroot/tair-project-template/bazel-out/k8-opt/bin/external/aspect_rules_format/format/format.runfiles/tair-project-template/../node_linux_amd64/bin/nodejs/bin/node]
12: 0xbd3f28  [/home/developer/.cache/bazel/_bazel_developer/6fc7dd3d681346fb996e4b7beb1cd826/execroot/tair-project-template/bazel-out/k8-opt/bin/external/aspect_rules_format/format/format.runfiles/tair-project-template/../node_linux_amd64/bin/nodejs/bin/node]
13: 0x7ff0340d5b43  [/lib/x86_64-linux-gnu/libc.so.6]
14: 0x7ff034167a00  [/lib/x86_64-linux-gnu/libc.so.6]
/home/developer/.cache/bazel/_bazel_developer/6fc7dd3d681346fb996e4b7beb1cd826/execroot/tair-project-template/bazel-out/k8-opt/bin/external/aspect_rules_format/format/prettier.sh: line 441:  3394 Aborted                 (core dumped) "$JS_BINARY__NODE_WRAPPER" ${NODE_OPTIONS[@]+"${NODE_OPTIONS[@]}"} -- "$entry_point" ${ARGS[@]+"${ARGS[@]}"} 0<&0
FAILED: A formatter tool exited with code 123

I can see YAML formatting was disabled in https://github.com/aspect-build/bazel-super-formatter/releases/tag/v0.3.1 - are there perhaps some other extension failing with similar issues (e.g., markdown?).

Is there an easy way to use the latest node / prettier versions maybe?

Version

Development (host) and target OS/architectures: Linux

Output of bazel --version:

bazel 5.3.1

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file:

0.3.1

How to reproduce

No response

Any other information?

No response

Fund our work

  • Sponsor our open source work by donating a bug bounty

Does not support file paths with spaces

The tool does not seem to handle the case where the file path has spaces in. There are errors like the following:

michaelboyd bazel-experiment $ bazel run @aspect_rules_format//format
INFO: Analyzed target @aspect_rules_format//format:format (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target @aspect_rules_format//format:format up-to-date:
  bazel-bin/external/aspect_rules_format/format/format
INFO: Elapsed time: 0.257s, Critical Path: 0.01s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Build completed successfully, 1 total action
Running Buildifier...
Running Prettier...
...
[error] No files matching the pattern were found: "path/first".
[error] No files matching the pattern were found: "word.json".

Unfortunately, even trying to cover the problematic files with .prettierignore does not seem to work.
I have looked into this and the problem seems to be in format.sh.

[FR]: Linting

What is the current behavior?

The tool only does formatting.

Describe the feature

I wonder why not introduce linting as well? Or is there an existing tool which does "super-linting" and integrates with Bazel?

Fund our work

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.