Skip to content

[MBT] Wrap Bazel target names in quotes when necessary. Add unit tests.#8450

Open
maksymilianrozanski wants to merge 1 commit into
scalameta:main-v2from
maksymilianrozanski:bazelQuery8445
Open

[MBT] Wrap Bazel target names in quotes when necessary. Add unit tests.#8450
maksymilianrozanski wants to merge 1 commit into
scalameta:main-v2from
maksymilianrozanski:bazelQuery8445

Conversation

@maksymilianrozanski
Copy link
Copy Markdown

@maksymilianrozanski maksymilianrozanski commented Jun 4, 2026

#8445
Updated Bazel target names to be wrapped in quotes when required.
Added unit tests.

https://bazel.build/query/language#lexical-syntax
https://bazel.build/concepts/labels#target-names

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved Bazel target label handling by properly quoting and escaping special characters, reserved keywords, and quotes in query strings.
  • Tests

    • Added comprehensive test coverage for Bazel query target label formatting across various edge cases.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 4, 2026

Review Change Stack

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b0709df8-548d-412b-9643-e509faa4d7bc

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The PR adds proper quoting and escaping for Bazel query target strings in the fullInformationQuery method to handle special characters and reserved keywords. Helper functions detect when targets need quoting and apply either single or double quotes based on their content, while logging warnings for malformed targets containing both quote types.

Changes

Bazel Query Target Quoting

Layer / File(s) Summary
Bazel target quoting rules and integration
metals/src/main/scala/scala/meta/internal/metals/mbt/importer/BazelQuery.scala
Defines reserved keywords (set, deps, etc.) and allowed unquoted characters, adds needsQuoting predicate to detect targets requiring escaping, implements quoteTarget to wrap targets with appropriate single or double quotes (or skip with warning if both quote types present), and integrates quoting into fullInformationQuery via flatMap to construct the deps(set(...)) query safely.
Quoting behavior test coverage
tests/unit/src/test/scala/tests/mbt/BazelQuerySuite.scala
FunSuite with comprehensive test cases validating quoting behavior across standard labels, URL-encoded patterns, external repos with +, special characters (=, %), leading hyphens, single/double quote handling, reserved keywords, empty inputs, and edge cases where targets contain both quote types (verified as skipped).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • zielinsky

Poem

🐰 A rabbit hops through query strings,
Where special chars once caused bad things!
Now quotes protect each label's soul,
Escaping makes the fragments whole.
Bazel's safe—let's build and test!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main changes: wrapping Bazel target names in quotes when necessary and adding unit tests to validate this behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@maksymilianrozanski
Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 4, 2026

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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.

1 participant