rules_scala
rules_scala copied to clipboard
Running scala fmt for multiple targets with query and run fails
trafficstars
I am trying to run scalafmt on all targets using combined bazel run and query:
bazel run $(bazel query 'kind("generated file", //...:*)' | grep format-test)
But this fails with weird error:
<some path to file>.scala
diff: //<target>:tests.format-test/<path to file>.scala: No such file or directory
When running the same target manually (bazel run //<target>:tests.format-test) it is working as expected.
To get around it, I solved it with a small shell script:
#!/bin/bash
set -e
TASK=${1:-format-test}
for TARGET in $(bazel query 'kind("scala_library", //...:*)' )
do
bazel run $TARGET.$TASK
done
for TARGET in $(bazel query 'kind("scala_library", //...:*)' )
do
bazel run $TARGET.$TASK
done
But I would like to do this directly with Bazel...
scalafmt is supported by https://github.com/aspect-build/rules_lint - I encourage you to come try it out! I'm happy to provides some support for any problems with it. (big picture - format and lint are complex topics and better to have one DX for them rather than each language ruleset inventing different "way to hold it")