You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: incorrect printout how to fix formatting issues #138
The issue arises due to the way format_multirun and format_test macros are implemented by aspect-build.
format_multirun produces a target named [name].check, which does not modify files but instead exits with a non-zero status if any sources require formatting.
To get the correct suggestion output, run the check command of the format.fix target:
bazel run //tools/format:format.fix_YAML_with_yamlfmt.check
Output
...
Formatted YAML in 0m0.028s
FAILED: A formatter tool exited with code 123
Try running 'bazel run //tools/format:format.fix_YAML_with_yamlfmt' to fix this.
Proposed Improvement: Renaming Targets
We can improve usability by renaming the targets as follows:
@AlexanderLanin@nicu1989 I've took a look and I don't see how renaming targets will lead to a better command suggestion.
Tried this:
diff --git a/BUILD b/BUILD
index b423cbc..f405edd 100644
--- a/BUILD
+++ b/BUILD
@@ -15,12 +15,12 @@ load("//tools/cr_checker:cr_checker.bzl", "copyright_checker")
test_suite(
name = "format.check",
- tests = ["//tools/format:format.check"],
+ tests = ["//tools/format:format_test"],
)
alias(
name = "format.fix",
- actual = "//tools/format:format.fix",
+ actual = "//tools/format:format",
)
copyright_checker(
diff --git a/MODULE.bazel b/MODULE.bazel
index 57d4007..61f4210 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -78,4 +78,4 @@ bazel_dep(name = "buildifier_prebuilt", version = "7.3.1")
# Generic linting and formatting rules
#
###############################################################################
-bazel_dep(name = "aspect_rules_lint", version = "1.0.3")
+bazel_dep(name = "aspect_rules_lint", version = "1.1.0")
diff --git a/tools/format/BUILD b/tools/format/BUILD
index 3bf7c6d..510ddf7 100644
--- a/tools/format/BUILD
+++ b/tools/format/BUILD
@@ -14,7 +14,7 @@
load("@aspect_rules_lint//format:defs.bzl", "format_multirun", "format_test")
format_multirun(
- name = "format.fix",
+ name = "format",
python = "@aspect_rules_lint//format:ruff",
starlark = "@buildifier_prebuilt//:buildifier",
visibility = [
@@ -24,7 +24,7 @@ format_multirun(
)
format_test(
- name = "format.check",
+ name = "format_test",
no_sandbox = True,
python = "@aspect_rules_lint//format:ruff",
starlark = "@buildifier_prebuilt//:buildifier",
bazel test //:format.check --test_output=all
...
Formatted Python in 0m0.022s
FAILED: A formatter tool exited with code 123
Try running 'bazel run //tools/format:format_test_Python_with_ruff ' to fix this.
The problem lies in the implementation in rules_lint.
True, that's my conclusion also. There is not much what we can do about it. But by changing the target names we can address somewhat the usecase presented in the ticket(having the same outputed suggestion as the command):
Current:
run: bazel run //tools/format:format.check_YAML_with_yamlfmt
outputed suggestion: bazel run //tools/format:format.check_YAML_with_yamlfmt <- exactly the same as the run command, does not fix the formatting issue
Modified target names:
run: bazel run //tools/format:format_YAML_with_yamlfmt.check
outputed suggestion: bazel run //tools/format:format_YAML_with_yamlfmt <- no check in the suggestion, and it actually does what is supposed to do.
Activity
[-]Bug: yaml formatting command[/-][+]Bug: incorrect printout how to fix formatting issues[/+]MaximilianSoerenPollak commentedon Jan 10, 2025
Should the fix command not just be
bazel run //:format.fix?nicu1989 commentedon Feb 3, 2025
Issue Analysis
The issue arises due to the way
format_multirunandformat_testmacros are implemented by aspect-build.format_multirunproduces a target named[name].check, which does not modify files but instead exits with a non-zero status if any sources require formatting.format_testis intended to be used withbazel testto verify that files are formatted.Getingt the correct suggestion output
The following command lists all current targets:
bazel query '//tools/format:*'Output
To get the correct suggestion output, run the check command of the
format.fixtarget:Output
Proposed Improvement: Renaming Targets
We can improve usability by renaming the targets as follows:
tools\format\BUILD:
After Renaming, the targets would be:
Now, the following commands will be used:
bazel run //tools/format:format_YAML_with_yamlfmt.checkbazel run //tools/format:format_YAML_with_yamlfmtbazel run //tools/format:format.checkbazel test //tools/format:format_testbazel run //tools/format:formatNote
AlexanderLanin commentedon Feb 5, 2025
@nradakovic can you provide feedback here?
ltekieli commentedon Feb 7, 2025
@AlexanderLanin @nicu1989 I've took a look and I don't see how renaming targets will lead to a better command suggestion.
Tried this:
The problem lies in the implementation in rules_lint. The suggestion just uses the same command as run for check: https://github.com/aspect-build/rules_lint/blob/3bf498bc3b92ac96818165a8ee989ba7ad06cdcd/format/private/format.sh#L47
nicu1989 commentedon Feb 12, 2025
True, that's my conclusion also. There is not much what we can do about it. But by changing the target names we can address somewhat the usecase presented in the ticket(having the same outputed suggestion as the command):
Current:
bazel run //tools/format:format.check_YAML_with_yamlfmtbazel run //tools/format:format.check_YAML_with_yamlfmt<- exactly the same as the run command, does not fix the formatting issueModified target names:
bazel run //tools/format:format_YAML_with_yamlfmt.checkbazel run //tools/format:format_YAML_with_yamlfmt<- no check in the suggestion, and it actually does what is supposed to do.MaximilianSoerenPollak commentedon Feb 12, 2025
I think easiest would be to just have a note somewhere that one can fix any of the 'formatting' issues via the
bazel run //:format.fix?AlexanderLanin commentedon Feb 13, 2025
It's in README. This ticket was created because CI checks print incorrect output.
AlexanderLanin commentedon Feb 13, 2025
@nicu1989 how about we merge this one here AND create an issue upstream?
nicu1989 commentedon Feb 14, 2025
I have created an issue to aspect-build/rules_lint: aspect-build/rules_lint#482