Skip to content

fix(format): point format_test failure at the multirun fixer#862

Open
ifutivic wants to merge 2 commits into
aspect-build:mainfrom
superbet-group:fix/format-test-fix-target
Open

fix(format): point format_test failure at the multirun fixer#862
ifutivic wants to merge 2 commits into
aspect-build:mainfrom
superbet-group:fix/format-test-fix-target

Conversation

@ifutivic
Copy link
Copy Markdown
Contributor

@ifutivic ifutivic commented May 11, 2026

A failing format_test prints:

Try running 'bazel run //tools/format:format_test_Go_with_gofmt' to fix this.

…but that's the test target itself, not a fixer. The FIX_TARGET env in _format_attr_factory is built from the test's own per-language target name (<format_test_name>_<Lang>_with_<tool>) instead of the companion format_multirun's fix command.

Add an optional fix_target parameter on format_test naming the companion format_multirun target. When set, FIX_TARGET is computed as <fix_target>_<Lang>_with_<tool> in that target's package.

Default behavior (parameter omitted) is unchanged.

Usage:

format_multirun(name = "format", go = "@aspect_rules_lint//format:gofumpt", ...)
format_test(name = "format_test", fix_target = "format", ...)

Changes are visible to end-users: yes

  • Searched for relevant documentation and updated as needed: yes
  • Breaking change: no
  • Suggested release notes appear below: yes

RELEASE NOTES: Properly format error message when formatting fails if the corresponding format target is specified

ifutivic added 2 commits May 11, 2026 12:06
… fixer

The FIX_TARGET env var consumed by format.sh was constructed from the
test's own per-language target name (e.g. `format_test_Go_with_gofmt`),
so a failing `format_test` told users to run the test itself rather than
the corresponding `format_multirun` fix command (e.g. `format_Go_with_gofmt`).

Add an optional `fix_target` parameter to `format_test` that names the
companion `format_multirun` target. When set, the per-language fix
target name is derived from it and used as `FIX_TARGET`. The parameter
is optional and defaults to the previous behavior, so existing callers
are unaffected.
Replaces the hand-rolled _parse_fix_target helper. native.package_relative_label
resolves the string relative to the calling BUILD file's package (handling
bare names, ':name', and '//pkg:name' uniformly), and .package/.name strip the
repo prefix so the constructed FIX_TARGET stays in the user's workspace.
@aspect-workflows
Copy link
Copy Markdown

aspect-workflows Bot commented May 11, 2026

Bazel 7 (Test)

6 test targets passed

Targets
//format/test:custom_args_test [k8-fastbuild] 480ms
//format/test:ls-files_test [k8-fastbuild]    785ms
//lint/rust:test_human [k8-fastbuild]         121ms
//lint/rust:test_patch [k8-fastbuild]         100ms
//lint/rust:test_sarif [k8-fastbuild]         171ms
//tools/sarif:sarif_test [k8-fastbuild]       166ms

Bazel 8 (Test)

All tests were cache hits

6 tests (100.0%) were fully cached saving 1s.


Bazel 9 (Test)

All tests were cache hits

6 tests (100.0%) were fully cached saving 2s.

Comment thread format/defs.bzl
attrs = _format_attr_factory(target_name, lang, toolname, tool_label, "test", disable_git_attribute_checks, custom_args)
fix_target_label = None
if fix_label:
fix_target_label = "//{}:{}_{}_with_{}".format(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have to reformat the label when one exists?

Why do we have a random _with_ in there if the fix_label already has a name?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix_label points to a format_multirun target that runs multiple formatters in parallel. Since we want to report which specific formatter failed, we construct the name as format_lang_with_tool.
We have two targets: format and format_test. When format_test fails for Go, for example, we want to tell the user to run format_Go_with_gofmt, matching what the existing format_test failure already reports except with a proper fixer target.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbedard Any updates on this? Happy to adjust or rework anything in the PR. My main goal is just making sure the final error message clearly points users toward the correct fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants